23 #ifndef COM_DAFER45_TBTK_ANNOTATED_ARRAY
24 #define COM_DAFER45_TBTK_ANNOTATED_ARRAY
40 template<
typename DataType,
typename AxesType>
52 const std::vector<std::vector<AxesType>> &axes
62 const std::string &serialization,
69 const std::vector<std::vector<AxesType>>&
getAxes()
const;
75 std::vector<std::vector<AxesType>> axes;
78 template<
typename DataType,
typename AxesType>
82 template<
typename DataType,
typename AxesType>
85 const std::vector<std::vector<AxesType>> &axes
87 Array<DataType>(array),
90 const std::vector<unsigned int> &ranges = array.
getRanges();
92 ranges.size() == axes.size(),
93 "AnnotatedArray::AnnotatedArray()",
94 "Incompatible dimensions. 'array' has '" << ranges.size()
95 <<
"' dimensions, while 'axes' have '" << axes.size() <<
"'"
99 for(
unsigned int n = 0; n < ranges.size(); n++){
101 ranges[n] == axes[n].size(),
102 "AnnotatedArray::AnnotatedArray()",
103 "Incompatible sizes. Dimension '" << n <<
" of 'array'"
104 <<
" has size '" << ranges[n] <<
"', but axis '" << n
105 <<
"' has size '" << axes[n].size() <<
"'.",
111 template<
typename DataType,
typename AxesType>
113 const std::string &serialization,
129 "AnnotatedArray::AnnotatedArray()",
130 "Unable to parse string as AnnotatedArray '" << serialization
136 case Serializable::Mode::JSON:
140 = nlohmann::json::parse(serialization);
141 nlohmann::json jsonAxes = j.at(
"axes");
143 nlohmann::json::iterator axisIterator
145 axisIterator != jsonAxes.end();
149 = atoi(axisIterator.key().c_str());
150 for(
unsigned int n = axes.size(); n <= axisId; n++)
151 axes.push_back(std::vector<AxesType>());
153 nlohmann::json::iterator iterator
154 = axisIterator->begin();
155 iterator != axisIterator->end();
158 axes.back().push_back(
166 catch(nlohmann::json::exception &e){
168 "AnnotatedArray::AnnotatedArray()",
169 "Unable to parse string as AnnotatedArray '"
170 << serialization <<
"'.",
179 "AnnotatedArray::AnnotatedArray()",
180 "Unable to parse string as AnnotatedArray '"
181 << serialization <<
"'.",
187 template<
typename DataType,
typename AxesType>
195 template<
typename DataType,
typename AxesType>
200 case Serializable::Mode::JSON:
203 j[
"id"] =
"AnnotatedArray";
204 j[
"array"] = nlohmann::json::parse(
207 j[
"axes"] = nlohmann::json();
208 for(
unsigned int n = 0; n < axes.size(); n++){
209 std::string index = std::to_string(n);
210 j[
"axes"][index] = nlohmann::json();
211 for(
unsigned int c = 0; c < axes[n].size(); c++){
212 j[
"axes"][index].push_back(
225 "AnnotatedArray::serialize()",
226 "Only Serializable::Mode::JSON is supported yet.",