cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
file_format.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
7namespace toolbox::io
8{
9
31{
32public:
34 default; // 虚析构函数对基类很重要 / Virtual destructor is important for
35 // base classes
36 // Rule of Five/Zero: 如果定义了虚析构函数,需要考虑其他特殊成员函数 / If a
37 // virtual destructor is defined, consider the others
38 // 由于这个类没有需要特殊管理的资源,使用默认实现即可 / Since this class has no
39 // resources needing special management, default is fine
44
45protected:
47 default; // 只允许派生类构造 / Allow construction only by derived classes
48};
49
83{
84public:
85 virtual ~base_file_format_t() = default;
86 // 这个类可能是无状态的或通过RAII管理资源(如派生类中的unique_ptr) / This class
87 // is likely stateless or manages resources via RAII
88 // 默认的拷贝/移动操作可能没问题,但删除它们更安全 / Default copy/move
89 // operations are probably fine, but deleting them is safer
91 delete; // 通常格式处理器不需要拷贝 / Typically format handlers are not
92 // copied
95 default; // 移动可能是可以的 / Moving might be okay
97
104 [[nodiscard]] virtual auto can_read(const std::string& path) const
105 -> bool = 0;
106
111 [[nodiscard]] virtual auto get_supported_extensions() const
112 -> std::vector<std::string> = 0;
113
120 virtual auto read(const std::string& path,
121 std::unique_ptr<base_file_data_t>& data) -> bool = 0;
122
130 [[nodiscard]] virtual auto write(
131 const std::string& path,
132 const std::unique_ptr<base_file_data_t>& data,
133 bool binary) const -> bool = 0;
134
135protected:
137};
138
139} // namespace toolbox::io
文件数据的基类 / Base class for data loaded from files
Definition file_format.hpp:31
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 file_format.hpp:83
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 file_format.hpp:8