COGS
Computer Graphics Structures library
DataBlock.h
1 #ifndef COGS_DATA_BLOCK_H
2 #define COGS_DATA_BLOCK_H
3 #include <fstream>
4 #include <memory>
5 #include <limits>
6 
7 namespace cogs
8 {
10  namespace io
11  {
13  using DataBlockIndex = size_t;
14 
15  const static DataBlockIndex INVALID_DATABLOCK_INDEX {std::numeric_limits<size_t>::max()};
16 
22  using DataBlockType = std::string;
23 
25  class DataBlock
26  {
27  public:
28 
29  const DataBlockIndex INDEX;
30 
31  explicit DataBlock(DataBlockIndex index) : INDEX(index) {};
32 
34  [[nodiscard]] virtual DataBlockType GetType() const = 0;
35 
37  [[nodiscard]] virtual uint8_t GetExportVersion() const = 0;
38 
40  [[nodiscard]] virtual bool IsImportVersionSupported(uint8_t version) const = 0;
41 
43  virtual bool Import(std::istream &in_s, uint8_t version) = 0;
44 
46  virtual bool Export(std::ostream &out_s) = 0;
47  };
48 
51  {
52  public:
54  virtual std::unique_ptr<DataBlock> Create(DataBlockIndex index) const = 0;
55  };
56 
57  }
58 }
59 #endif /* !COGS_DATA_BLOCK_H */
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8
virtual uint8_t GetExportVersion() const =0
Version of export function.
size_t DataBlockIndex
Defines position index of the data block in a file.
Definition: DataBlock.h:13
virtual bool IsImportVersionSupported(uint8_t version) const =0
Checks if specified version is supported by import function.
virtual bool Export(std::ostream &out_s)=0
Executes export to specified stream.
virtual bool Import(std::istream &in_s, uint8_t version)=0
Executes import form specified stream.
Definition of required interface for derived data blocks.
Definition: DataBlock.h:25
virtual DataBlockType GetType() const =0
Returns unique identifier of class. Usually class name.
Factory for data block type.
Definition: DataBlock.h:50
std::string DataBlockType
Identifies data block instances. Each class derived from cogs::io::DataBlockType should have unique t...
Definition: DataBlock.h:22