KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
DataSet.h
Go to the documentation of this file.
1
50#ifndef KIDS_DataSet_H
51#define KIDS_DataSet_H
52
53#include <fstream>
54#include <map>
55#include <memory>
56#include <tuple>
57#include <type_traits>
58#include <vector>
59
60#include "kids/Exception.h"
61#include "kids/Node.h"
62#include "kids/Shape.h"
63#include "kids/Tensor.h"
64#include "kids/Types.h"
65#include "kids/Variable.h"
66#include "kids/concat.h"
67
68namespace PROJECT_NS {
69
74class DataSet final : public Node {
75 private:
76 DataSet& operator=(const DataSet&) = delete;
77
78 public:
79 using DataType = std::map<std::string, std::shared_ptr<Node>>;
80 std::shared_ptr<DataType> _data;
81
85 DataSet();
86
93
100
107
115 kids_int* def_int(const std::string& key, Shape S = 1, const std::string& info = "");
116
125 kids_int* def_int(const std::string& key, kids_int* arr_in, Shape S = 1, const std::string& info = "");
126
134 kids_int* def_int(const std::string& key, const std::string& key_in, const std::string& info = "");
135
143 DataSet& _def_int(const std::string& key, Shape S = 1, const std::string& info = "");
144
152 kids_real* def_real(const std::string& key, Shape S = 1, const std::string& info = "");
153
162 kids_real* def_real(const std::string& key, kids_real* arr_in, Shape S = 1, const std::string& info = "");
163
171 kids_real* def_real(const std::string& key, const std::string& key_in, const std::string& info = "");
172
180 DataSet& _def_real(const std::string& key, Shape S = 1, const std::string& info = "");
181
189 kids_complex* def_complex(const std::string& key, Shape S = 1, const std::string& info = "");
190
199 kids_complex* def_complex(const std::string& key, kids_complex* arr_in, Shape S = 1, const std::string& info = "");
200
208 kids_complex* def_complex(const std::string& key, const std::string& key_in, const std::string& info = "");
209
217 DataSet& _def_complex(const std::string& key, Shape S = 1, const std::string& info = "");
218
226 DataSet& _def(const std::string& key, const std::string& key_in, const std::string& info = "");
227
233 DataSet& _undef(const std::string& key);
234
240 std::tuple<kids_dtype, void*, Shape*> obtain(const std::string& key);
241
247 Node* node(const std::string& key);
248
254 DataSet* at(const std::string& key);
255
261 virtual std::string help(const std::string& name);
262
267 virtual std::string repr();
268
273 virtual void dump(std::ostream& os);
274
279 virtual void load(std::istream& is);
280
281 private:
290 template <typename T>
291 T* def(const std::string& key, Shape S = 1, const std::string& info = "");
292
294 public:
295 std::vector<std::string> terms;
296 DataSetKeyParser(const std::string& key, const std::string& delimiter = ".") {
297 size_t start = 0, end;
298 while ((end = key.find(delimiter, start)) != std::string::npos) {
299 terms.emplace_back(key, start, end - start);
300 start = end + delimiter.length();
301 }
302 terms.emplace_back(key, start);
303 }
304 };
305};
306
307}; // namespace PROJECT_NS
308
309#endif // KIDS_DataSet_H
310
provide Exception structs
Declaration of the Node class used for DataSet.
Declaration of the Shape class.
A class inherited from Node, representing tensors.
definition of types in the project and some utiles for types
this file provide Variable class
DataSetKeyParser(const std::string &key, const std::string &delimiter=".")
Definition DataSet.h:296
std::vector< std::string > terms
Definition DataSet.h:295
DataSet class is a tree-structured container for storage of Tensor and other DataSet.
Definition DataSet.h:74
DataSet & _def_complex(const std::string &key, Shape S=1, const std::string &info="")
Define a complex variable with a specified key, shape, and info and update the dataset.
Definition DataSet.cpp:116
std::map< std::string, std::shared_ptr< Node > > DataType
Definition DataSet.h:79
DataSet & _def_real(const std::string &key, Shape S=1, const std::string &info="")
Define a real variable with a specified key, shape, and info and update the dataset.
Definition DataSet.cpp:95
virtual void dump(std::ostream &os)
Dump the DataSet to an output stream.
Definition DataSet.cpp:265
DataSet * at(const std::string &key)
Access the DataSet corresponding to a variable with a specified key.
Definition DataSet.cpp:203
virtual std::string repr()
Get a string representation of the DataSet.
Definition DataSet.cpp:240
DataSet & _undef(const std::string &key)
Undefine a variable with a specified key.
Definition DataSet.cpp:140
virtual void load(std::istream &is)
Load the DataSet from an input stream.
Definition DataSet.cpp:267
Node * node(const std::string &key)
Get the node corresponding to a variable with a specified key.
Definition DataSet.cpp:185
DataSet()
Constructor for DataSet.
Definition DataSet.cpp:22
DataSet & operator=(const DataSet &)=delete
kids_complex * def_complex(const std::string &key, Shape S=1, const std::string &info="")
Define a complex variable with a specified key, shape, and info.
Definition DataSet.cpp:100
std::tuple< kids_dtype, void *, Shape * > obtain(const std::string &key)
Obtain information about a variable with a specified key.
Definition DataSet.cpp:160
virtual std::string help(const std::string &name)
Get help information for a variable with a specified name.
Definition DataSet.cpp:213
DataSet & _def(const std::string &key, const std::string &key_in, const std::string &info="")
Define a variable with a specified key and reference key, and info.
Definition DataSet.cpp:122
kids_int * def_int(const std::string &key, Shape S=1, const std::string &info="")
Define an integer variable with a specified key, shape, and info.
Definition DataSet.cpp:58
kids_int * def(VARIABLE< kids_int > &var)
Define a variable of type kids_int.
Definition DataSet.cpp:53
std::shared_ptr< DataType > _data
Definition DataSet.h:80
kids_real * def_real(const std::string &key, Shape S=1, const std::string &info="")
Define a real variable with a specified key, shape, and info.
Definition DataSet.cpp:79
DataSet & _def_int(const std::string &key, Shape S=1, const std::string &info="")
Define an integer variable with a specified key, shape, and info and update the dataset.
Definition DataSet.cpp:74
Node class is an abstract interface.
Definition Node.h:39
Shape class provide information about of a Tensor's shape.
Definition Shape.h:50
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
double kids_real
Alias for real number type.
Definition Types.h:59
std::complex< double > kids_complex
Alias for complex number type.
Definition Types.h:60
int kids_int
Alias for integer type.
Definition Types.h:57