KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Types.h
Go to the documentation of this file.
1
29#ifndef KIDS_TYPES_H
30#define KIDS_TYPES_H
31
32#include <complex>
33// #include "generate/version.h"
34
35namespace PROJECT_NS {
36
37// Forward declarations
38class Param;
39class Node;
40class DataSet;
41
42// Enumeration for data types
53
54// Alias declarations for data types
55using kids_void = void;
56using kids_bool = bool;
57using kids_int = int;
58using kids_bint = int;
59using kids_real = double;
60using kids_complex = std::complex<double>;
61using kids_str = std::string;
64
69// Casts a value from one type to another
70template <class Tto, class Tfrom = void>
71inline Tto cast(Tfrom value) {
72 return static_cast<Tto>(value);
73}
74
75template <class Tto>
77 return static_cast<Tto>(real(value));
78}
79
80template <>
84
85// Specialization for casting complex numbers to another type
86template <class Tto>
87inline Tto cast(kids_complex value) {
88 return cast_from_complex<Tto>(value);
89}
90
91// Casts a value at a specific memory location to another type
92template <class Tto, class Tfrom>
93inline Tto cast_at(void* data, int index = 0) {
94 return cast<Tto>(*((Tfrom*) data + index));
95}
97
101template <typename T>
103
107template <typename T>
108std::string as_str();
109
110// Macro for defining utility functions for type binding
111#define DEFINE_BIND_UTILS_FOR(T) \
112 template <> \
113 inline kids_dtype as_enum<T>() { \
114 return T##_type; \
115 } \
116 template <> \
117 inline std::string as_str<T>() { \
118 return #T; \
119 }
120
121// Define utility functions for each data type
130
131}; // namespace PROJECT_NS
132
133#endif // KIDS_TYPES_H
#define DEFINE_BIND_UTILS_FOR(T)
Definition Types.h:111
DataSet class is a tree-structured container for storage of Tensor and other DataSet.
Definition DataSet.h:74
this class provides an interface wrapper for the parameter data.
Definition Param.h:82
Param::LoadOption::fromString value("fromFile", Param::LoadOption::fromFile) .export_values()
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
@ kids_real_type
Represents real number type.
Definition Types.h:47
@ kids_str_type
Represents string type.
Definition Types.h:49
@ kids_param_type
Represents Param type.
Definition Types.h:50
@ kids_complex_type
Represents complex number type.
Definition Types.h:48
@ kids_bool_type
Represents bool type.
Definition Types.h:45
@ kids_dataset_type
Represents DataSet type.
Definition Types.h:51
@ kids_int_type
Represents integer type.
Definition Types.h:46
@ kids_void_type
Represents void type.
Definition Types.h:44
kids_dtype as_enum()
Converts a C++ type to its corresponding kids_dtype enumeration.
double kids_real
Alias for real number type.
Definition Types.h:59
bool kids_bool
Alias for bool type.
Definition Types.h:56
std::complex< double > kids_complex
Alias for complex number type.
Definition Types.h:60
std::string as_str()
Converts a C++ type to its string representation.
Tto cast(Tfrom value)
Definition Types.h:71
int kids_bint
Alias for integer type.
Definition Types.h:58
Tto cast_from_complex(kids_complex value)
Definition Types.h:76
std::string kids_str
Alias for string type.
Definition Types.h:61
void kids_void
Alias for void type.
Definition Types.h:55
Tto cast_at(void *data, int index=0)
Definition Types.h:93
int kids_int
Alias for integer type.
Definition Types.h:57