/src/bag/api/bag_dataset.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef BAG_DATASET_H |
2 | | #define BAG_DATASET_H |
3 | | |
4 | | #include "bag_compounddatatype.h" |
5 | | #include "bag_georefmetadatalayerdescriptor.h" |
6 | | #include "bag_config.h" |
7 | | #include "bag_descriptor.h" |
8 | | #include "bag_exceptions.h" |
9 | | #include "bag_fordec.h" |
10 | | #include "bag_layer.h" |
11 | | #include "bag_metadata.h" |
12 | | #include "bag_trackinglist.h" |
13 | | #include "bag_types.h" |
14 | | #include "bag_vrtrackinglist.h" |
15 | | |
16 | | #include <functional> |
17 | | #include <memory> |
18 | | #include <numeric> |
19 | | #include <string> |
20 | | #include <unordered_map> |
21 | | #include <vector> |
22 | | |
23 | | |
24 | | namespace H5 { |
25 | | |
26 | | class H5File; |
27 | | |
28 | | } //namespace H5 |
29 | | |
30 | | namespace BAG { |
31 | | |
32 | | #ifdef _MSC_VER |
33 | | #pragma warning(push) |
34 | | #pragma warning(disable: 4251) // std classes do not have DLL-interface when exporting |
35 | | #pragma warning(disable: 4275) // non-DLL-interface class used as base class |
36 | | #endif |
37 | | |
38 | | //! The interface for the BAG. |
39 | | /*! |
40 | | This is the BAG Dataset. It is responsible for creating or reading a BAG. |
41 | | It contains the layers and metadata. It has a descriptor for general |
42 | | details. |
43 | | |
44 | | It is the only way layers can be created. It is meant to be the interface |
45 | | to the BAG, and answer questions about said BAG. |
46 | | */ |
47 | | class BAG_API Dataset final |
48 | | : public std::enable_shared_from_this<Dataset> |
49 | | |
50 | | { |
51 | | public: |
52 | | static std::shared_ptr<Dataset> open(const std::string &fileName, |
53 | | OpenMode openMode); |
54 | | |
55 | | static std::shared_ptr<Dataset> create(const std::string &fileName, |
56 | | Metadata&& metadata, uint64_t chunkSize = 100, |
57 | | int compressionLevel = 5); |
58 | | |
59 | | void close(); |
60 | | |
61 | | Dataset(const Dataset&) = delete; |
62 | | Dataset(Dataset&&) = delete; |
63 | | |
64 | | Dataset& operator=(const Dataset&) = delete; |
65 | | Dataset& operator=(Dataset&&) = delete; |
66 | | |
67 | 0 | bool operator==(const Dataset &rhs) const noexcept { |
68 | 0 | return m_pH5file == rhs.m_pH5file && |
69 | 0 | m_layers == rhs.m_layers && |
70 | 0 | m_pMetadata == rhs.m_pMetadata && |
71 | 0 | m_pTrackingList == rhs.m_pTrackingList && |
72 | 0 | m_descriptor == rhs.m_descriptor && |
73 | 0 | m_pVRTrackingList == rhs.m_pVRTrackingList; |
74 | 0 | } |
75 | | |
76 | 0 | bool operator!=(const Dataset &rhs) const noexcept { |
77 | 0 | return !(rhs == *this); |
78 | 0 | } |
79 | | |
80 | | Layer& getLayer(uint32_t id) &; |
81 | | const Layer& getLayer(uint32_t id) const &; |
82 | | std::shared_ptr<Layer> getLayer(LayerType type, const std::string& name) &; |
83 | | std::shared_ptr<const Layer> getLayer(LayerType type, const std::string& name) const &; |
84 | | std::vector<std::shared_ptr<const Layer>> getLayers() const &; |
85 | | |
86 | | std::vector<LayerType> getLayerTypes() const; |
87 | | |
88 | | Layer& createSimpleLayer(LayerType type, uint64_t chunkSize, |
89 | | int compressionLevel) &; |
90 | | GeorefMetadataLayer& createGeorefMetadataLayer(DataType keyType, GeorefMetadataProfile profile, |
91 | | const std::string& name, const RecordDefinition& definition, |
92 | | uint64_t chunkSize, int compressionLevel) &; |
93 | | GeorefMetadataLayer& createGeorefMetadataLayer(GeorefMetadataProfile profile, |
94 | | const std::string& name, |
95 | | uint64_t chunkSize, int compressionLevel, |
96 | | DataType keyType = DT_UINT16) &; |
97 | | SurfaceCorrections& createSurfaceCorrections( |
98 | | BAG_SURFACE_CORRECTION_TOPOGRAPHY type, uint8_t numCorrectors, |
99 | | uint64_t chunkSize, int compressionLevel) &; |
100 | | void createVR(uint64_t chunkSize, int compressionLevel, bool makeNode); |
101 | | |
102 | | const Metadata& getMetadata() const & noexcept; |
103 | | |
104 | | TrackingList& getTrackingList() & noexcept; |
105 | | const TrackingList& getTrackingList() const & noexcept; |
106 | | |
107 | | std::shared_ptr<GeorefMetadataLayer> getGeorefMetadataLayer(const std::string& name) & noexcept; |
108 | | std::shared_ptr<const GeorefMetadataLayer> getGeorefMetadataLayer(const std::string& name) const & noexcept; |
109 | | std::vector<std::shared_ptr<GeorefMetadataLayer>> getGeorefMetadataLayers() & noexcept; |
110 | | |
111 | | std::shared_ptr<SurfaceCorrections> getSurfaceCorrections() & noexcept; |
112 | | std::shared_ptr<const SurfaceCorrections> getSurfaceCorrections() const & noexcept; |
113 | | |
114 | | std::shared_ptr<SimpleLayer> getSimpleLayer(LayerType type) & noexcept; |
115 | | std::shared_ptr <const SimpleLayer> getSimpleLayer(LayerType type) const & noexcept; |
116 | | |
117 | | std::shared_ptr<VRMetadata> getVRMetadata() & noexcept; |
118 | | std::shared_ptr<const VRMetadata> getVRMetadata() const & noexcept; |
119 | | |
120 | | std::shared_ptr<VRNode> getVRNode() & noexcept; |
121 | | std::shared_ptr<const VRNode> getVRNode() const & noexcept; |
122 | | |
123 | | std::shared_ptr<VRRefinements> getVRRefinements() & noexcept; |
124 | | std::shared_ptr<const VRRefinements> getVRRefinements() const & noexcept; |
125 | | |
126 | | std::shared_ptr<VRTrackingList> getVRTrackingList() & noexcept; |
127 | | std::shared_ptr<const VRTrackingList> getVRTrackingList() const & noexcept; |
128 | | |
129 | | Descriptor& getDescriptor() & noexcept; |
130 | | const Descriptor& getDescriptor() const & noexcept; |
131 | | |
132 | | std::tuple<double, double> gridToGeo(uint32_t row, uint32_t column) const noexcept; |
133 | | std::tuple<uint32_t, uint32_t> geoToGrid(double x, double y) const noexcept; |
134 | | |
135 | | private: |
136 | 306 | Dataset() = default; |
137 | | uint32_t getNextId() const noexcept; |
138 | | |
139 | | void readDataset(const std::string& fileName, OpenMode openMode); |
140 | | void createDataset(const std::string& fileName, Metadata&& metadata, |
141 | | uint64_t chunkSize, int compressionLevel); |
142 | | |
143 | | std::tuple<bool, float, float> getMinMax(LayerType type, |
144 | | const std::string& path = {}) const; |
145 | | |
146 | | ::H5::H5File& getH5file() const & noexcept; |
147 | | |
148 | | Layer& addLayer(std::shared_ptr<Layer> layer) &; |
149 | | |
150 | | //! Custom deleter to not require knowledge of ::H5::H5File destructor here. |
151 | | struct BAG_API DeleteH5File final { |
152 | | void operator()(::H5::H5File* ptr) noexcept; |
153 | | }; |
154 | | |
155 | | //! The HDF5 file that the BAG is stored in. |
156 | | std::unique_ptr<::H5::H5File, DeleteH5File> m_pH5file; |
157 | | //! The mandatory and optional layers found in the BAG, including ones |
158 | | //! created after opening. |
159 | | std::vector<std::shared_ptr<Layer>> m_layers; |
160 | | //! The metadata. |
161 | | std::unique_ptr<Metadata> m_pMetadata; |
162 | | //! The tracking list. |
163 | | std::unique_ptr<TrackingList> m_pTrackingList; |
164 | | //! The descriptor. |
165 | | Descriptor m_descriptor; |
166 | | //! The optional VR tracking list. |
167 | | std::shared_ptr<VRTrackingList> m_pVRTrackingList; |
168 | | |
169 | | friend GeorefMetadataLayer; |
170 | | friend GeorefMetadataLayerDescriptor; |
171 | | friend InterleavedLegacyLayer; |
172 | | friend InterleavedLegacyLayerDescriptor; |
173 | | friend LayerDescriptor; |
174 | | friend Metadata; |
175 | | friend SimpleLayer; |
176 | | friend TrackingList; |
177 | | friend SimpleLayerDescriptor; |
178 | | friend SurfaceCorrections; |
179 | | friend SurfaceCorrectionsDescriptor; |
180 | | friend ValueTable; |
181 | | friend VRMetadata; |
182 | | friend VRMetadataDescriptor; |
183 | | friend VRNode; |
184 | | friend VRNodeDescriptor; |
185 | | friend VRRefinements; |
186 | | friend VRRefinementsDescriptor; |
187 | | friend VRTrackingList; |
188 | | }; |
189 | | |
190 | | #ifdef _MSC_VER |
191 | | #pragma warning(pop) |
192 | | #endif |
193 | | |
194 | | } //namespace BAG |
195 | | |
196 | | #endif //BAG_DATASET_H |
197 | | |