/src/bag/api/bag_interleavedlegacylayerdescriptor.cpp
Line | Count | Source |
1 | | |
2 | | #include "bag_exceptions.h" |
3 | | #include "bag_interleavedlegacylayer.h" |
4 | | #include "bag_interleavedlegacylayerdescriptor.h" |
5 | | #include "bag_private.h" |
6 | | |
7 | | |
8 | | namespace BAG { |
9 | | |
10 | | //! The constructor. |
11 | | /*! |
12 | | \param id |
13 | | The unique layer id. |
14 | | \param layerType |
15 | | The type of layer to be read. |
16 | | \param groupType |
17 | | The type of group to be read. |
18 | | NODE or ELEVATION. |
19 | | */ |
20 | | InterleavedLegacyLayerDescriptor::InterleavedLegacyLayerDescriptor( |
21 | | uint32_t id, |
22 | | LayerType layerType, |
23 | | GroupType groupType, |
24 | | uint32_t rows, uint32_t cols) |
25 | 0 | : LayerDescriptor(id, Layer::getInternalPath(layerType), |
26 | 0 | kLayerTypeMapString.at(layerType), layerType, rows, cols, 0, 0) |
27 | 0 | , m_groupType(groupType) |
28 | 0 | , m_elementSize(Layer::getElementSize(Layer::getDataType(layerType))) |
29 | 0 | { |
30 | 0 | this->setInternalPath(groupType == NODE ? |
31 | 0 | NODE_GROUP_PATH : ELEVATION_SOLUTION_GROUP_PATH); |
32 | |
|
33 | 0 | InterleavedLegacyLayerDescriptor::validateTypes(layerType, groupType); |
34 | 0 | } |
35 | | |
36 | | //! The constructor. |
37 | | /*! |
38 | | \param dataset |
39 | | The BAG Dataset this layer belongs to. |
40 | | \param layerType |
41 | | The type of layer to be read. |
42 | | \param groupType |
43 | | The type of group to be read. |
44 | | NODE or ELEVATION. |
45 | | */ |
46 | | InterleavedLegacyLayerDescriptor::InterleavedLegacyLayerDescriptor( |
47 | | const Dataset& dataset, |
48 | | LayerType layerType, |
49 | | GroupType groupType, |
50 | | uint32_t rows, uint32_t cols) |
51 | 0 | : LayerDescriptor(dataset, layerType, |
52 | 0 | rows, cols, |
53 | 0 | groupType == NODE |
54 | 0 | ? NODE_GROUP_PATH |
55 | 0 | : groupType == ELEVATION |
56 | 0 | ? ELEVATION_SOLUTION_GROUP_PATH |
57 | 0 | : "") |
58 | 0 | , m_groupType(groupType) |
59 | 0 | , m_elementSize(Layer::getElementSize(Layer::getDataType(layerType))) |
60 | 0 | { |
61 | 0 | InterleavedLegacyLayerDescriptor::validateTypes(layerType, groupType); |
62 | 0 | } |
63 | | |
64 | | //! Create an interleaved layer descriptor. |
65 | | /*! |
66 | | \param dataset |
67 | | The BAG Dataset this layer belongs to. |
68 | | \param layerType |
69 | | The type of layer to be read. |
70 | | \param groupType |
71 | | The type of group to be read. |
72 | | NODE or ELEVATION. |
73 | | |
74 | | \return |
75 | | The newly created interleaved layer descriptor. |
76 | | */ |
77 | | std::shared_ptr<InterleavedLegacyLayerDescriptor> InterleavedLegacyLayerDescriptor::create( |
78 | | const Dataset& dataset, |
79 | | LayerType layerType, |
80 | | GroupType groupType) |
81 | 0 | { |
82 | 0 | uint32_t rows, cols; |
83 | 0 | std::tie(rows, cols) = dataset.getDescriptor().getDims(); |
84 | 0 | return std::shared_ptr<InterleavedLegacyLayerDescriptor>( |
85 | 0 | new InterleavedLegacyLayerDescriptor{dataset.getNextId(), layerType, |
86 | 0 | groupType, rows, cols}); |
87 | 0 | } |
88 | | |
89 | | //! Open an interleaved layer descriptor. |
90 | | /*! |
91 | | \param dataset |
92 | | The BAG Dataset this layer belongs to. |
93 | | \param layerType |
94 | | The type of layer to be read. |
95 | | \param groupType |
96 | | The type of group to be read. |
97 | | NODE or ELEVATION. |
98 | | |
99 | | \return |
100 | | The newly opened interleaved layer descriptor. |
101 | | */ |
102 | | std::shared_ptr<InterleavedLegacyLayerDescriptor> InterleavedLegacyLayerDescriptor::open( |
103 | | const Dataset& dataset, |
104 | | LayerType layerType, |
105 | | GroupType groupType) |
106 | 0 | { |
107 | 0 | uint32_t rows, cols; |
108 | 0 | std::tie<uint32_t, uint32_t>(rows, cols) = dataset.getDescriptor().getDims(); |
109 | 0 | return std::shared_ptr<InterleavedLegacyLayerDescriptor>( |
110 | 0 | new InterleavedLegacyLayerDescriptor{dataset, layerType, groupType, rows, cols}); |
111 | 0 | } |
112 | | |
113 | | |
114 | | //! \copydoc LayerDescriptor::getDataType |
115 | | DataType InterleavedLegacyLayerDescriptor::getDataTypeProxy() const noexcept |
116 | 0 | { |
117 | 0 | return Layer::getDataType(this->getLayerType()); |
118 | 0 | } |
119 | | |
120 | | //! \copydoc LayerDescriptor::getElementSize |
121 | | uint8_t InterleavedLegacyLayerDescriptor::getElementSizeProxy() const noexcept |
122 | 0 | { |
123 | 0 | return m_elementSize; |
124 | 0 | } |
125 | | |
126 | | //! Return the group type of this layer. |
127 | | /*! |
128 | | \return |
129 | | The group type of this layer. |
130 | | */ |
131 | | GroupType InterleavedLegacyLayerDescriptor::getGroupType() const noexcept |
132 | 0 | { |
133 | 0 | return m_groupType; |
134 | 0 | } |
135 | | |
136 | | //! Verify the proper group and layer combination is given. |
137 | | /*! |
138 | | Validate the specified layer type is allowed for the group type. If the |
139 | | layer type is not valid for the specified group, an exception of type |
140 | | UnsupportedInterleavedLayer is thrown. |
141 | | |
142 | | \param layerType |
143 | | The type of layer to be read. |
144 | | \param groupType |
145 | | The type of group to be read. |
146 | | NODE or ELEVATION. |
147 | | */ |
148 | | void InterleavedLegacyLayerDescriptor::validateTypes( |
149 | | LayerType layerType, |
150 | | GroupType groupType) |
151 | 0 | { |
152 | 0 | if (groupType == ELEVATION) |
153 | 0 | { |
154 | 0 | if (layerType != Shoal_Elevation && layerType != Std_Dev && |
155 | 0 | layerType != Num_Soundings) |
156 | 0 | throw UnsupportedInterleavedLayer{}; |
157 | 0 | } |
158 | 0 | else if (groupType == NODE) |
159 | 0 | { |
160 | 0 | if (layerType != Hypothesis_Strength && layerType != Num_Hypotheses) |
161 | 0 | throw UnsupportedInterleavedLayer{}; |
162 | 0 | } |
163 | 0 | else |
164 | 0 | throw UnsupportedInterleavedLayer{}; |
165 | 0 | } |
166 | | |
167 | | } // namespace BAG |
168 | | |