cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
dataset.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <optional>
5
6#include <cpp-toolbox/cpp-toolbox_export.hpp>
7
8namespace toolbox::io
9{
10
31template<typename Derived, typename DataType>
32class CPP_TOOLBOX_EXPORT dataset_t
33{
34public:
38 using data_type = DataType;
39
49 std::size_t size() const
50 {
51 return static_cast<const Derived*>(this)->size_impl();
52 }
53
63 std::optional<DataType> operator[](std::size_t index) const
64 {
65 return static_cast<const Derived*>(this)->at_impl(index);
66 }
67
77 std::optional<DataType> at(std::size_t index) const
78 {
79 return static_cast<const Derived*>(this)->at_impl(index);
80 }
81
91 std::optional<DataType> get_item(std::size_t index) const
92 {
93 return static_cast<const Derived*>(this)->at_impl(index);
94 }
95
110 std::optional<DataType> get_next()
111 {
112 return static_cast<const Derived*>(this)->at_impl(m_current_index++);
113 }
114
125 std::optional<DataType> peek_next() const
126 {
127 return static_cast<const Derived*>(this)->at_impl(m_current_index);
128 }
129
137 void reset_iterator() { m_current_index = 0; }
138
147 std::size_t current_index() const { return m_current_index; }
148
149protected:
153 dataset_t() = default;
157 ~dataset_t() = default;
158
159public:
163 dataset_t(const dataset_t&) = delete;
167 dataset_t& operator=(const dataset_t&) = delete;
171 dataset_t(dataset_t&&) = delete;
176
177private:
181 std::size_t m_current_index = 0;
182};
183
184} // namespace toolbox::io
数据集基类/Abstract base class for datasets
Definition dataset.hpp:33
dataset_t()=default
构造函数/Constructor
DataType data_type
数据类型别名/Type alias for data type
Definition dataset.hpp:38
void reset_iterator()
重置内部迭代器索引/Reset the internal iterator index
Definition dataset.hpp:137
dataset_t(const dataset_t &)=delete
禁用拷贝构造/Copy constructor is disabled
std::optional< DataType > get_item(std::size_t index) const
获取指定索引的数据/Get data at the specified index
Definition dataset.hpp:91
std::optional< DataType > at(std::size_t index) const
通过下标访问数据/Access data by index
Definition dataset.hpp:77
std::optional< DataType > operator[](std::size_t index) const
通过下标访问数据/Access data by index
Definition dataset.hpp:63
~dataset_t()=default
析构函数/Destructor
dataset_t & operator=(dataset_t &&)=delete
禁用移动赋值/Move assignment is disabled
std::optional< DataType > get_next()
获取下一个元素并推进内部索引/Get the next element and advance the internal index
Definition dataset.hpp:110
std::optional< DataType > peek_next() const
查看下一个元素但不推进索引/Peek the next element without advancing the index
Definition dataset.hpp:125
dataset_t & operator=(const dataset_t &)=delete
禁用拷贝赋值/Copy assignment is disabled
dataset_t(dataset_t &&)=delete
禁用移动构造/Move constructor is disabled
std::size_t size() const
获取数据集大小/Get the size of the dataset
Definition dataset.hpp:49
std::size_t current_index() const
获取当前迭代器索引/Get the current iterator index
Definition dataset.hpp:147
< 用于列出目录下的文件/For listing files in a directory
Definition dataloader.hpp:15