COGS
Computer Graphics Structures library
DataBlockManager.h
1 #ifndef COGS_DATA_BLOCK_MANAGER_H
2 #define COGS_DATA_BLOCK_MANAGER_H
3 #include <memory>
4 #include <unordered_map>
5 
6 #include <Utils/Ulog.h>
7 #include <COGS/API.h>
8 #include <COGS/io/DataBlock.h>
9 
10 
11 
12 namespace cogs
13 {
14  namespace io
15  {
24  class COGS_API DataBlockManager
25  {
26  public:
35 
38  ~DataBlockManager() = default;
39  DataBlockManager(const DataBlockManager &) = delete;
40  DataBlockManager &operator=(const DataBlockManager &) = delete;
42  DataBlockManager &operator=(DataBlockManager &&) & = delete;
43 
45  [[nodiscard]] bool HasFactoryFor(const DataBlockType &datablock_type);
46 
48  [[nodiscard]] std::unique_ptr<DataBlock> Create(const DataBlockType &datablock_type, DataBlockIndex index);
49 
56  template <typename T>
57  void AddFactoryFor(const DataBlockType &datablock_type);
58 
59  private:
60  std::unordered_map<DataBlockType, std::unique_ptr<DataBlockFactory>> factories_;
61  };
62 
63  template <typename T>
65  {
66  if (HasFactoryFor(datablock_type))
67  {
68  ulog::Fail("Cannot create DataBlockFactory for type '"
69  + datablock_type + "'. Another factory for that type already exists.", "cogs::io::DataBlockManager::AddFactoryFor");
70  }
71  else
72  {
73  factories_[datablock_type] = std::make_unique<T>();
74  }
75  }
76 
77  }
78 }
79 
80 
81 #endif /* !COGS_DATA_BLOCK_MANAGER_H */
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8
static const DataBlockType MESH_DTB_TYPE
Identifier of predefined mesh data block class.
Definition: DataBlockManager.h:32
size_t DataBlockIndex
Defines position index of the data block in a file.
Definition: DataBlock.h:13
static const DataBlockType POINTCLOUD_DTB_TYPE
Identifier of predefined point cloud data block class.
Definition: DataBlockManager.h:28
Container class for specific data block factory objects.
Definition: DataBlockManager.h:24
static const DataBlockType SCAN_DTB_TYPE
Identifier of predefined scan data block class.
Definition: DataBlockManager.h:30
static const DataBlockType TRIANGULATION_DTB_TYPE
Identifier of predefined triangulation data block class.
Definition: DataBlockManager.h:34
void AddFactoryFor(const DataBlockType &datablock_type)
Registers new factory type T for the defined datablock_type.
Definition: DataBlockManager.h:64
std::string DataBlockType
Identifies data block instances. Each class derived from cogs::io::DataBlockType should have unique t...
Definition: DataBlock.h:22