23 #ifndef COM_DAFER45_TBTK_C_ARRAY
24 #define COM_DAFER45_TBTK_C_ARRAY
29 #include "TBTK/json.hpp"
43 template<
typename DataType>
107 const DataType&
operator[](
unsigned int n)
const;
119 const DataType*
getData()
const;
142 template<
typename DataType>
147 template<
typename DataType>
150 data =
new DataType[size];
153 template<
typename DataType>
156 if(carray.data ==
nullptr){
160 data =
new DataType[size];
161 for(
unsigned int n = 0; n < size; n++)
162 data[n] = carray.data[n];
166 template<
typename DataType>
169 if(carray.data ==
nullptr){
174 carray.data =
nullptr;
178 template<
typename DataType>
180 const std::string &serialization,
190 "Unable to parse string as CArray '" << serialization <<
"'.",
195 case Serializable::Mode::JSON:
199 = nlohmann::json::parse(serialization);
200 size = j.at(
"size").get<
unsigned int>();
201 nlohmann::json d = j.at(
"data");
202 std::vector<DataType> tempData;
204 nlohmann::json::iterator iterator = d.begin();
209 Serializable::deserialize<DataType>(
216 size == tempData.size(),
218 "Unable to deserialize CArray. The number of"
219 <<
"data elements does not agree with the size"
220 <<
" '" << serialization <<
"'.",
223 data =
new DataType[size];
224 for(
unsigned int n = 0; n < size; n++)
225 data[n] = tempData[n];
227 catch(nlohmann::json::exception &e){
230 "Unable to parse string as CArray '"
231 << serialization <<
"'.",
241 "Only Serializable::Mode::JSON is supported yet.",
247 template<
typename DataType>
253 template<
typename DataType>
260 if(rhs.data ==
nullptr){
264 data =
new DataType[size];
265 for(
unsigned int n = 0; n < size; n++)
266 data[n] = rhs.data[n];
273 template<
typename DataType>
280 if(rhs.data ==
nullptr){
292 template<
typename DataType>
297 template<
typename DataType>
302 template<
typename DataType>
307 template<
typename DataType>
312 template<
typename DataType>
317 template<
typename DataType>
320 case Serializable::Mode::JSON:
325 j[
"data"] = nlohmann::json();
326 for(
unsigned int n = 0; n < size; n++){
336 "CArray::serialize()",
337 "Only Serializable::Mode::JSON is supported yet.",