2 #ifndef SYDEVS_QUALIFIED_TYPE_H_
3 #define SYDEVS_QUALIFIED_TYPE_H_
25 static constexpr
bool valid =
false;
27 static std::string
tostring(
const T& X);
43 return [](
const pointer& val) -> std::string {
53 static constexpr
bool valid =
true;
55 static std::string
tostring(
const bool& X);
61 static constexpr
bool valid =
true;
69 static constexpr
bool valid =
true;
77 static constexpr
bool valid =
true;
79 static std::string
tostring(
const std::string& X);
85 static constexpr
bool valid =
true;
93 static constexpr
bool valid =
true;
99 template<
typename T,
int64 ndims>
107 template<
typename T1,
typename T2>
111 static std::string
tostring(
const std::pair<T1, T2>& X);
119 static std::string
tostring(
const std::tuple<T>& X);
123 template<
typename T,
typename... Ts>
127 static std::string
tostring(
const std::tuple<T, Ts...>& X);
128 static pointer copy(
const std::tuple<T, Ts...>& X);
135 static std::string
tostring(
const std::vector<T>& X);
143 static std::string
tostring(
const std::set<T>& X);
147 template<
typename Key,
typename T>
151 static std::string
tostring(
const std::map<Key, T>& X);
159 static std::string
tostring(
const std::shared_ptr<T>& X);
169 throw std::logic_error(
"Conversion to string unavailable for a type that is not a qualified type");
176 throw std::logic_error(
"Copying unavailable for a type that is not a qualified type");
185 return X ? std::string(
"true") : std::string(
"false");
224 return "\"" + X +
"\"";
229 return pointer(
new std::string(X));
265 template<
typename T,
int64 ndims>
268 auto indices = std::array<int64, ndims>();
269 for (
int64 idim = 0; idim < ndims; ++idim) {
274 auto s = std::string(
"{");
276 if (indices[idim] < X.
dims()[idim]) {
277 if (indices[idim] > 0) {
280 if (idim == ndims - 1) {
305 template<
typename T,
int64 ndims>
314 template<
typename T1,
typename T2>
320 template<
typename T1,
typename T2>
323 return pointer(
new std::pair<T1, T2>(X));
338 return pointer(
new std::tuple<T>(X));
344 template<
typename Tuple, std::
size_t N>
351 template<
typename Tuple>
358 template<
typename T,
typename... Ts>
364 template<
typename T,
typename... Ts>
367 return pointer(
new std::tuple<T, Ts...>(X));
376 auto s = std::string(
"{");
377 for (
const auto& item : X) {
378 if (s.back() !=
'{') {
390 return pointer(
new std::vector<T>(X));
399 auto s = std::string(
"{");
400 for (
const auto& item : X) {
401 if (s.back() !=
'{') {
413 return pointer(
new std::set<T>(X));
419 template<
typename Key,
typename T>
422 auto s = std::string(
"{");
423 for (
const auto& entry : X) {
424 if (s.back() !=
'{') {
433 template<
typename Key,
typename T>
436 return pointer(
new std::map<Key, T>(X));
445 return "(shared_ptr:" +
447 std::string(
"nullptr"))
454 return pointer(
new std::shared_ptr<T>(X));
std::string tostring(const T &val)
Definition: qualified_type.h:35
std::function< std::string(const pointer &)> tostring_function
Definition: qualified_type.h:19
std::array< int64, ndims > dims() const
Returns the lengths of each dimension.
Definition: arraynd_base.h:197
std::array< int64, ndims > strides() const
Returns the number of element-size steps in memory between successive elements for each dimension...
Definition: arraynd_base.h:205
Definition: qualified_type.h:345
const T * data() const
Returns a pointer to the element data (const).
Definition: arraynd_base.h:237
Definition: qualified_type.h:24
A class for converting stream objects to string values.
Definition: string_builder.h:27
static constexpr bool valid_and_sortable
Indicates whether type T is both a qualified type and a sortable type.
Definition: qualified_type.h:26
A class template for a multidimensional array with elements of type T arranged in a lattice of ndims ...
Definition: arraynd.h:187
static pointer copy(const T &X)
If T is a qualified type, returns a deep copy of X.
Definition: qualified_type.h:174
static std::string tostring(const Tuple &X)
Definition: qualified_type.h:346
A data type which identifies an item by combining an encapsulated integer-valued index with a dimensi...
Definition: identity.h:41
int64 offset() const
Returns the number of element-size steps in memory before the first element.
Definition: arraynd_base.h:229
static std::string tostring(const Tuple &X)
Definition: qualified_type.h:353
arraynd< T, ndims > copy() const
Create a deep copy of the multidimensional array (data is copied).
Definition: arraynd.h:450
tostring_function tostring_converter()
Definition: qualified_type.h:41
int64_t int64
Definition: number_types.h:14
static std::string tostring(const T &X)
If T is a qualified type, converts X to a std::string.
Definition: qualified_type.h:167
double float64
Definition: number_types.h:22
static constexpr bool valid
Indicates whether type T is a qualified type.
Definition: qualified_type.h:25
A data type template which represents a dimensioned quantity as a multiple of a precision level...
Definition: quantity.h:234
A data type which represents a pointer to anything.
Definition: pointer.h:27