cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory> // For std::unique_ptr
4#include <string> // For std::string
5#include <vector> // For std::vector
6
8
9namespace toolbox::io
10{
11
33{
34public:
36 default; // 虚析构函数对基类很重要 / Virtual destructor is important for
37 // base classes
38 // Rule of Five/Zero: 如果定义了虚析构函数,需要考虑其他特殊成员函数 / If a
39 // virtual destructor is defined, consider the others
40 // 由于这个类没有需要特殊管理的资源,使用默认实现即可 / Since this class has no
41 // resources needing special management, default is fine
46
47protected:
49 default; // 只允许派生类构造 / Allow construction only by derived classes
50};
51
85{
86public:
87 virtual ~base_file_format_t() = default;
88 // 这个类可能是无状态的或通过RAII管理资源(如派生类中的unique_ptr) / This class
89 // is likely stateless or manages resources via RAII
90 // 默认的拷贝/移动操作可能没问题,但删除它们更安全 / Default copy/move
91 // operations are probably fine, but deleting them is safer
93 delete; // 通常格式处理器不需要拷贝 / Typically format handlers are not
94 // copied
97 default; // 移动可能是可以的 / Moving might be okay
99
106 [[nodiscard]] virtual auto can_read(const std::string& path) const
107 -> bool = 0;
108
113 [[nodiscard]] virtual auto get_supported_extensions() const
114 -> std::vector<std::string> = 0;
115
122 virtual auto read(const std::string& path,
123 std::unique_ptr<base_file_data_t>& data) -> bool = 0;
124
132 [[nodiscard]] virtual auto write(
133 const std::string& path,
134 const std::unique_ptr<base_file_data_t>& data,
135 bool binary) const -> bool = 0;
136
137protected:
139};
140
141} // namespace toolbox::io
文件数据的基类 / Base class for data loaded from files
Definition base.hpp:33
base_file_data_t & operator=(base_file_data_t &&)=default
base_file_data_t & operator=(const base_file_data_t &)=default
base_file_data_t(base_file_data_t &&)=default
base_file_data_t(const base_file_data_t &)=default
virtual ~base_file_data_t()=default
文件格式读写器的基类 / Base class for file format readers/writers
Definition base.hpp:85
base_file_format_t & operator=(base_file_format_t &&)=default
base_file_format_t(base_file_format_t &&)=default
virtual auto write(const std::string &path, const std::unique_ptr< base_file_data_t > &data, bool binary) const -> bool=0
将数据写入文件 / Write data to file
base_file_format_t & operator=(const base_file_format_t &)=delete
virtual ~base_file_format_t()=default
virtual auto get_supported_extensions() const -> std::vector< std::string >=0
获取支持的文件扩展名列表 / Get list of supported file extensions
virtual auto can_read(const std::string &path) const -> bool=0
检查是否可以读取指定路径的文件 / Check if file at given path can be read
base_file_format_t(const base_file_format_t &)=delete
virtual auto read(const std::string &path, std::unique_ptr< base_file_data_t > &data) -> bool=0
读取文件内容到数据对象 / Read file contents into data object
< 用于列出目录下的文件/For listing files in a directory
Definition dataloader.hpp:15