KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
VariableDescriptor.cpp
Go to the documentation of this file.
2
3#include <iostream>
4#include <regex>
5
6namespace PROJECT_NS {
7
8VariableDescriptor::VariableDescriptor(const std::string& token_string) : tokenString{token_string} {
9 const std::regex pattern("([^{<:]*)(?:\\{([^@<]*)(?:@(.*?))?\\})?(?:<([^>]*)>)?(?::([^:]*))?");
10 std::smatch match;
11 if (std::regex_match(tokenString, match, pattern)) {
12 std::tie(name, field, time, index, type) = std::make_tuple( //
13 match[1], match[2], match[3], match[4], match[5]);
14 } else {
15 throw kids_error("cannot match variable pattern!");
16 }
17
18 if (field == "0") field = "init";
19 if (field == "I") field = "integrator";
20 if (field == "M") field = "model";
21 if (field == "R") field = "result";
22 if (field == "") field = "integrator";
23
24 if (time == "" || time == "T") time = "t";
25
26 if (index == "") {}; // do nothing
27
28 if (type == "R") {
30 } else if (type == "C") {
32 } else {
34 }
35}
36
37void VariableDescriptor::referIn(std::shared_ptr<DataSet>& DS) {
38 if (field == "" || name == "") throw kids_error("bad key!");
39 std::string key = utils::concat(field, ".", name);
40 std::tie(dataType, dataPointer, shape) = DS->obtain(key);
41#define LOCAL_DEBUG
42#ifdef LOCAL_DEBUG
43 std::cout << LOC() << "VariableDescriptor Data:\n"
44 << ".tokenString = " << tokenString << "\n" //
45 << ".name = " << name << "\n" //
46 << ".field = " << field << "\n" //
47 << ".index = " << index << "\n" //
48 << ".type = " << type << "\n" //
49 << ".time = " << time << "\n" //
50 << ".dataType = " << dataType << "\n" //
51 << ".dataPointer = " << dataPointer << "\n" //
52 << ".shape = " << ((shape) ? shape->to_string() : "") << "\n";
53#endif // LOCAL_DEBUG
54}
55
56void VariableDescriptor::defineIn(std::shared_ptr<DataSet>& DS, kids_dtype data_type,
57 const std::vector<std::size_t>& cxxshape) {
58 if (field == "" || name == "") throw kids_error("bad key!");
59 std::string key = utils::concat(field, ".", name);
60 std::cout << LOC() << key << "," << data_type << "\n";
61
62 switch (data_type) {
63 case kids_real_type:
64 DS->def_real(key, cxxshape, "CUSTOM DEFINED");
65 break;
67 DS->def_complex(key, cxxshape, "CUSTOM DEFINED");
68 break;
69 }
70 std::tie(dataType, dataPointer, shape) = DS->obtain(key);
71 std::cout << LOC() << key << "\n";
72}
73
74}; // namespace PROJECT_NS
provide VariableDescriptor class
std::string to_string()
Definition Shape.h:95
#define LOC()
show the location information for debug
Definition fmt.h:49
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
@ kids_real_type
Represents real number type.
Definition Types.h:47
@ kids_complex_type
Represents complex number type.
Definition Types.h:48
@ kids_void_type
Represents void type.
Definition Types.h:44
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
Definition concat.h:242
std::string name
The name of the variable.
void referIn(std::shared_ptr< DataSet > &DS)
Associates the variable with data in the DataSet.
kids_dtype dataType
The data type of the variable.
VariableDescriptor(const std::string &token_string)
Constructs a VariableDescriptor object.
std::string tokenString
The input token string.
void defineIn(std::shared_ptr< DataSet > &DS, kids_dtype data_type, const std::vector< std::size_t > &cxxshape)
Define variable with data in the DataSet.
Shape * shape
Pointer to the shape of the variable.
std::string field
The field of the variable.
void * dataPointer
Pointer to the data of the variable.
std::string type
The type of the variable.
std::string index
The index of the variable.