30 std::shared_ptr<DataType> d_ptr =
_data;
33 for (
size_t i = 0; i < kh.
terms.size() - 1; ++i) {
38 d_ptr = currentNode->
_data;
41 std::shared_ptr<Node>& leaf_node = (*d_ptr)[kh.
terms.back()];
42 if (!leaf_node) leaf_node = std::shared_ptr<Tensor<T>>(
new Tensor<T>(S, info));
44 if (leaf_node->type() != as_enum<T>()) {
45 throw std::runtime_error(
"doubly conflicted definition!");
47 auto leaf_node_ts =
static_cast<Tensor<T>*
>(leaf_node.get());
48 if (S.size() != leaf_node_ts->size()) {
49 throw std::runtime_error(
"doubly conflicted definition!");
51 return leaf_node_ts->data();
59 return def<kids_int>(key, S, info);
63 for (
int i = 0; i < S.size(); ++i) arr[i] = arr_in[i];
67 auto inode =
node(key_in);
69 throw std::runtime_error(std::string{key_in} +
" : failed copying dataset");
72 return def_int(key, inode_ts->data(), inode_ts->size(), info);
80 return def<kids_real>(key, S, info);
84 for (
int i = 0; i < S.size(); ++i) arr[i] = arr_in[i];
88 auto inode =
node(key_in);
90 throw std::runtime_error(std::string{key_in} +
" : failed copying dataset");
93 return def_real(key, inode_ts->data(), inode_ts->size(), info);
101 return def<kids_complex>(key, S, info);
105 for (
int i = 0; i < S.size(); ++i) arr[i] = arr_in[i];
109 auto inode =
node(key_in);
111 throw std::runtime_error(std::string{key_in} +
" : failed copying dataset");
114 return def_complex(key, inode_ts->data(), inode_ts->size(), info);
123 auto leaf_node =
node(key_in);
124 switch (leaf_node->type()) {
142 std::shared_ptr<DataType> d_ptr =
_data;
145 for (
size_t i = 0; i < kh.
terms.size() - 1; ++i) {
147 if (!
node)
return *
this;
150 d_ptr = currentNode->
_data;
152 auto it = d_ptr->find(kh.
terms.back());
153 if (it != d_ptr->end()) {
161 auto&& leaf_node =
node(key);
162 switch (leaf_node->type()) {
165 return std::make_tuple(
kids_int_type, conv_node->data(), &(conv_node->shape()));
170 return std::make_tuple(
kids_real_type, conv_node->data(), &(conv_node->shape()));
175 return std::make_tuple(
kids_complex_type, conv_node->data(), &(conv_node->shape()));
179 throw std::runtime_error(
"bad obtain!");
187 std::shared_ptr<DataType> d_ptr =
_data;
190 for (
size_t i = 0; i < kh.
terms.size() - 1; ++i) {
192 if (!
node)
throw std::runtime_error(std::string{key} +
" : access undefined key!");
195 d_ptr = currentNode->_data;
198 auto& leaf_node = (*d_ptr)[kh.
terms.back()];
199 if (!leaf_node)
throw std::runtime_error(std::string{key} +
" : access undefined key!");
200 return leaf_node.get();
204 auto leaf_node =
node(key);
206 return static_cast<DataSet*
>(leaf_node);
208 throw std::runtime_error(
"bad conversion!");
214 std::ostringstream os;
215 std::vector<std::tuple<std::string, Node*>> stack;
218 if (name !=
"") inode =
node(name);
220 stack.push_back(std::make_tuple(
"", inode));
221 while (!stack.empty()) {
222 auto [parent, currentNode] = stack.back();
225 std::shared_ptr<DataType> d_ptr =
static_cast<DataSet*
>(currentNode)->
_data;
227 for (
auto& i : (*d_ptr)) {
228 std::string key = (parent ==
"") ? i.first : parent +
"." + i.first;
229 Node* inode = i.second.get();
231 stack.push_back(std::make_tuple(key, inode));
233 os << key <<
":\n\t" << inode->
help(
"") <<
"\n";
241 std::ostringstream os;
242 std::vector<std::tuple<std::string, Node*>> stack;
244 stack.push_back(std::make_tuple(
"",
this));
246 while (!stack.empty()) {
247 auto [parent, currentNode] = stack.back();
249 std::shared_ptr<DataType> d_ptr =
static_cast<DataSet*
>(currentNode)->
_data;
250 for (
auto& i : (*d_ptr)) {
251 std::string key = (parent ==
"") ? i.first : parent +
"." + i.first;
252 if (!i.second)
continue;
253 Node* inode = i.second.get();
256 stack.push_back(std::make_tuple(key, inode));
258 os << key <<
"\n" << inode->
repr() <<
"\n\n";
268 std::string key, typeflag;
270 while (is >> key >> typeflag >> size) {
271 if (typeflag == as_str<int>()) {
272 int* ptr = def<int>(key, size);
273 for (
int i = 0; i < size; ++i) is >> ptr[i];
274 }
else if (typeflag == as_str<kids_real>()) {
275 kids_real* ptr = def<kids_real>(key, size);
276 for (
int i = 0; i < size; ++i) is >> ptr[i];
277 }
else if (typeflag == as_str<kids_complex>()) {
279 for (
int i = 0; i < size; ++i) is >> ptr[i];
Declaration of the DataSet class and related classes.
provide Exception structs
Declaration of the Shape class.
definition of types in the project and some utiles for types
this file provide Variable class
std::vector< std::string > terms
DataSet class is a tree-structured container for storage of Tensor and other DataSet.
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.
std::map< std::string, std::shared_ptr< Node > > DataType
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.
virtual void dump(std::ostream &os)
Dump the DataSet to an output stream.
DataSet * at(const std::string &key)
Access the DataSet corresponding to a variable with a specified key.
virtual std::string repr()
Get a string representation of the DataSet.
DataSet & _undef(const std::string &key)
Undefine a variable with a specified key.
virtual void load(std::istream &is)
Load the DataSet from an input stream.
Node * node(const std::string &key)
Get the node corresponding to a variable with a specified key.
DataSet()
Constructor for DataSet.
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.
std::tuple< kids_dtype, void *, Shape * > obtain(const std::string &key)
Obtain information about a variable with a specified key.
virtual std::string help(const std::string &name)
Get help information for a variable with a specified name.
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.
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.
kids_int * def(VARIABLE< kids_int > &var)
Define a variable of type kids_int.
std::shared_ptr< DataType > _data
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.
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.
Node class is an abstract interface.
virtual std::string help(const std::string &name)=0
virtual std::string repr()=0
Shape class provide information about of a Tensor's shape.
Tensor class is the container for array-like data.
< http://warp.povusers.org/FunctionParser/fparser.html
@ kids_real_type
Represents real number type.
@ kids_complex_type
Represents complex number type.
@ kids_dataset_type
Represents DataSet type.
@ kids_int_type
Represents integer type.
double kids_real
Alias for real number type.
std::complex< double > kids_complex
Alias for complex number type.
int kids_int
Alias for integer type.