8 #include "../core/core-data.hpp"
9 #include "helics_cxx_export.h"
14 #include <string_view>
51 template<
typename BaseType, Identifiers ID, BaseType inval
idValue>
58 using UnderlyingType = BaseType;
62 constexpr
explicit IdentifierId(BaseType val) noexcept: ivalue(val) {}
75 BaseType
value() const noexcept {
return ivalue; };
83 bool isValid() const noexcept {
return (ivalue !=
invalidValue); }
90 template<
typename BaseType, helics::Identifiers ID, BaseType inval
idValue>
91 struct hash<
helics::IdentifierId<BaseType, ID, invalidValue>> {
98 return std::hash<BaseType>{}(key.value());
104 using PublicationId = IdentifierId<IdentifierType, Identifiers::PUBLICATION, invalid_id_value>;
105 using InputId = IdentifierId<IdentifierType, Identifiers::INPUT, invalid_id_value>;
107 using QueryId = IdentifierId<IdentifierType, Identifiers::QUERY, invalid_id_value>;
114 std::numeric_limits<double>::quiet_NaN();
125 return ((std::isnan(
value)) && (std::isnan(np.
value))) ?
151 return typeid(X).name();
153 namespace typestrings {
154 constexpr
auto svecstr =
"string_vector";
155 constexpr
auto dvecstr =
"double_vector";
156 constexpr
auto cvecstr =
"complex_vector";
158 constexpr
auto doublestr =
"double";
159 constexpr
auto floatstr =
"float";
160 constexpr
auto boolstr =
"bool";
162 constexpr
auto charstr =
"char";
163 constexpr
auto ucharstr =
"uchar";
164 constexpr
auto i32str =
"int32";
165 constexpr
auto ui32str =
"uint32";
166 constexpr
auto i64str =
"int64";
167 constexpr
auto ui64str =
"uint64";
169 constexpr
auto cfloatstr =
"complex_f";
170 constexpr
auto cdoublestr =
"complex";
171 constexpr
auto npstr =
"named_point";
172 constexpr
auto strstr =
"string";
176 inline constexpr
const char* typeNameString<std::vector<std::string>>()
178 return typestrings::svecstr;
181 inline constexpr
const char* typeNameString<std::vector<double>>()
183 return typestrings::dvecstr;
187 inline constexpr
const char* typeNameString<std::vector<std::complex<double>>>()
189 return typestrings::cvecstr;
196 return typestrings::doublestr;
203 return typestrings::floatstr;
210 return typestrings::boolstr;
217 return typestrings::charstr;
223 return typestrings::ucharstr;
227 inline constexpr
const char* typeNameString<std::int32_t>()
229 return typestrings::i32str;
233 inline constexpr
const char* typeNameString<std::uint32_t>()
235 return typestrings::ui32str;
241 return typestrings::i64str;
245 inline constexpr
const char* typeNameString<std::uint64_t>()
247 return typestrings::ui64str;
251 inline constexpr
const char* typeNameString<std::complex<float>>()
253 return typestrings::cfloatstr;
257 inline constexpr
const char* typeNameString<std::complex<double>>()
259 return typestrings::cdoublestr;
262 inline constexpr
const char* typeNameString<std::string>()
264 return typestrings::strstr;
268 inline constexpr
const char* typeNameString<NamedPoint>()
270 return typestrings::npstr;
274 HELICS_UNKNOWN = HELICS_DATA_TYPE_UNKNOWN,
292 inline constexpr
bool isBytesType(
DataType type)
294 return (type == DataType::HELICS_ANY) || (type == DataType::HELICS_CUSTOM);
323 HELICS_CXX_EXPORT std::string
331 HELICS_CXX_EXPORT std::complex<double>
helicsGetComplex(std::string_view val);
333 HELICS_CXX_EXPORT std::vector<double>
helicsGetVector(std::string_view val);
334 HELICS_CXX_EXPORT
void helicsGetVector(std::string_view val, std::vector<double>& data);
341 std::vector<std::complex<double>>& data);
354 HELICS_CXX_EXPORT
double vectorNorm(
const std::vector<double>& vec);
356 HELICS_CXX_EXPORT
double vectorNorm(
const std::vector<std::complex<double>>& vec);
366 HELICS_CXX_EXPORT SmallBuffer typeConvertComplex(
DataType type,
const double* vals,
size_t size);
368 const std::vector<std::complex<double>>& val);
371 HELICS_CXX_EXPORT SmallBuffer
typeConvert(
DataType type, std::string_view str,
double val);
380 return DataType::HELICS_CUSTOM;
384 constexpr
DataType helicsType<int64_t>()
386 return DataType::HELICS_INT;
390 constexpr
DataType helicsType<bool>()
392 return DataType::HELICS_BOOL;
396 constexpr
DataType helicsType<std::string>()
398 return DataType::HELICS_STRING;
402 constexpr
DataType helicsType<NamedPoint>()
404 return DataType::HELICS_NAMED_POINT;
407 constexpr
DataType helicsType<double>()
409 return DataType::HELICS_DOUBLE;
413 constexpr
DataType helicsType<Time>()
415 return DataType::HELICS_TIME;
419 constexpr
DataType helicsType<std::complex<double>>()
421 return DataType::HELICS_COMPLEX;
425 constexpr
DataType helicsType<std::vector<double>>()
427 return DataType::HELICS_VECTOR;
431 constexpr
DataType helicsType<std::vector<std::complex<double>>>()
433 return DataType::HELICS_COMPLEX_VECTOR;
438 constexpr
bool isConvertableType()
444 constexpr
bool isConvertableType<float>()
450 constexpr
bool isConvertableType<long double>()
456 constexpr
bool isConvertableType<int32_t>()
462 constexpr
bool isConvertableType<int16_t>()
468 constexpr
bool isConvertableType<uint16_t>()
474 constexpr
bool isConvertableType<char>()
480 constexpr
bool isConvertableType<unsigned char>()
486 constexpr
bool isConvertableType<uint64_t>()
502 constexpr
double invalidValue<double>()
508 constexpr int64_t invalidValue<int64_t>()
510 return (std::numeric_limits<int64_t>::min)();
514 constexpr uint64_t invalidValue<uint64_t>()
516 return (std::numeric_limits<uint64_t>::max)();
520 constexpr
Time invalidValue<Time>()
522 return Time::minVal();
526 inline NamedPoint invalidValue<NamedPoint>()
528 return {std::string(), std::nan(
"0")};
532 constexpr std::complex<double> invalidValue<std::complex<double>>()
534 return {invalidValue<double>(), 0.0};
540 constexpr
int primaryType = 0;
541 constexpr
int convertibleType = 1;
542 constexpr
int nonConvertibleType = 2;
549 std::conditional_t<helicsType<remove_cv_ref<X>>() != DataType::HELICS_CUSTOM,
550 std::integral_constant<int, primaryType>,
552 std::integral_constant<int, convertibleType>,
553 std::integral_constant<int, nonConvertibleType>>>;
Definition: helicsTypes.hpp:52
BaseType value() const noexcept
Definition: helicsTypes.hpp:75
IdentifierId & operator=(BaseType val) noexcept
Definition: helicsTypes.hpp:66
constexpr IdentifierId(const IdentifierId &id) noexcept
Definition: helicsTypes.hpp:64
IdentifierId & operator=(const IdentifierId &id)=default
bool operator!=(IdentifierId id) const noexcept
Definition: helicsTypes.hpp:79
bool operator<(IdentifierId id) const noexcept
Definition: helicsTypes.hpp:81
constexpr IdentifierId() noexcept
Definition: helicsTypes.hpp:60
static const Identifiers identity
the type of the identifier
Definition: helicsTypes.hpp:57
bool operator==(IdentifierId id) const noexcept
Definition: helicsTypes.hpp:77
constexpr IdentifierId(BaseType val) noexcept
Definition: helicsTypes.hpp:62
Definition: helicsTypes.hpp:110
double value
the data value for the named point
Definition: helicsTypes.hpp:113
bool operator<(const NamedPoint &np) const
Definition: helicsTypes.hpp:133
bool operator==(const NamedPoint &np) const
Definition: helicsTypes.hpp:123
bool operator>(const NamedPoint &np) const
Definition: helicsTypes.hpp:140
NamedPoint(std::string_view valname, double valval)
Definition: helicsTypes.hpp:118
std::string name
the text value for the named point
Definition: helicsTypes.hpp:112
@ HELICS_DATA_TYPE_INT
Definition: helics_enums.h:72
@ HELICS_DATA_TYPE_DOUBLE
Definition: helics_enums.h:70
@ HELICS_DATA_TYPE_STRING
Definition: helics_enums.h:68
@ HELICS_DATA_TYPE_TIME
Definition: helics_enums.h:84
@ HELICS_DATA_TYPE_COMPLEX_VECTOR
Definition: helics_enums.h:78
@ HELICS_DATA_TYPE_RAW
Definition: helics_enums.h:88
@ HELICS_DATA_TYPE_NAMED_POINT
Definition: helics_enums.h:80
@ HELICS_DATA_TYPE_JSON
Definition: helics_enums.h:90
@ HELICS_DATA_TYPE_COMPLEX
Definition: helics_enums.h:74
@ HELICS_DATA_TYPE_CHAR
Definition: helics_enums.h:86
@ HELICS_DATA_TYPE_ANY
Definition: helics_enums.h:95
@ HELICS_DATA_TYPE_MULTI
Definition: helics_enums.h:92
@ HELICS_DATA_TYPE_VECTOR
Definition: helics_enums.h:76
@ HELICS_DATA_TYPE_BOOLEAN
Definition: helics_enums.h:82
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
constexpr DataType helicsType()
Definition: helicsTypes.hpp:378
bool helicsBoolValue(std::string_view val)
Definition: helicsTypes.cpp:645
DataType
Definition: helicsTypes.hpp:273
NamedPoint helicsGetNamedPoint(std::string_view val)
Definition: helicsTypes.cpp:407
constexpr const char * typeNameString< unsigned char >()
Definition: helicsTypes.hpp:221
std::string helicsVectorString(const std::vector< double > &val)
Definition: helicsTypes.cpp:363
std::vector< std::complex< double > > helicsGetComplexVector(std::string_view val)
Definition: helicsTypes.cpp:400
constexpr double invalidDouble
defined constant for an invalid value as a double
Definition: helicsTypes.hpp:499
constexpr IdentifierType invalid_id_value
defining an invalid id value
Definition: helicsTypes.hpp:26
constexpr const char * typeNameString< int64_t >()
Definition: helicsTypes.hpp:239
std::vector< double > helicsGetVector(std::string_view val)
Definition: helicsTypes.cpp:393
constexpr const char * typeNameString< double >()
Definition: helicsTypes.hpp:194
const std::string & typeNameStringRef(DataType type)
Definition: helicsTypes.cpp:58
constexpr const char * typeNameString< bool >()
Definition: helicsTypes.hpp:208
std::string_view getCleanedTypeName(std::string_view typeName)
Definition: helicsTypes.cpp:264
std::int64_t getIntFromString(std::string_view val)
Definition: helicsTypes.cpp:481
std::complex< double > helicsGetComplex(std::string_view val)
Definition: helicsTypes.cpp:294
SmallBuffer typeConvert(DataType type, double val)
Definition: helicsTypes.cpp:732
std::string helicsDoubleString(double val)
Definition: helicsTypes.cpp:358
std::remove_cv_t< std::remove_reference_t< T > > remove_cv_ref
Helper template to remove const volatile references.
Definition: helicsTypes.hpp:538
constexpr const char * typeNameString< float >()
Definition: helicsTypes.hpp:201
constexpr const char * typeNameString()
Definition: helicsTypes.hpp:148
DataType getTypeFromString(std::string_view typeName)
Definition: helicsTypes.cpp:238
Identifiers
Definition: helicsTypes.hpp:30
std::string helicsIntString(std::int64_t val)
Definition: helicsTypes.cpp:353
constexpr const char * typeNameString< char >()
Definition: helicsTypes.hpp:215
double getDoubleFromString(std::string_view val)
Definition: helicsTypes.cpp:492
std::string helicsNamedPointString(const NamedPoint &point)
Definition: helicsTypes.cpp:378
std::uint32_t IdentifierType
specify the underlying type used in the identifiers
Definition: helicsTypes.hpp:22
double vectorNorm(const std::vector< double > &vec)
Definition: helicsTypes.cpp:103
std::string helicsComplexString(double real, double imag)
Definition: helicsTypes.cpp:121
InterfaceVisibility
Definition: helicsTypes.hpp:40
X invalidValue()
Definition: helicsTypes.hpp:493
std::conditional_t< helicsType< remove_cv_ref< X > >() !=DataType::HELICS_CUSTOM, std::integral_constant< int, primaryType >, std::conditional_t< isConvertableType< remove_cv_ref< X > >(), std::integral_constant< int, convertibleType >, std::integral_constant< int, nonConvertibleType > >> typeCategory
Definition: helicsTypes.hpp:553
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
std::string helicsComplexVectorString(const std::vector< std::complex< double >> &val)
Definition: helicsTypes.cpp:373
std::complex< double > getComplexFromString(std::string_view val)
Definition: helicsTypes.cpp:463
std::size_t result_type
the result type of the hash code
Definition: helicsTypes.hpp:94
result_type operator()(argument_type const &key) const noexcept
Definition: helicsTypes.hpp:96