3#include "base/src/basei.h"
8using IVariantBase = std::variant<uint8,char,bool,int32,uint32,int64,uint64,double,IString,IList<IVariant>,
9 IVect2,DVect2,IVect3,DVect3,DAVect2,DAVect3,
SymTensor,
Variant,std::vector<bool>,std::vector<int>,
10 std::vector<int64>,std::vector<double>,std::vector<IString>,std::vector<DVect2>,std::vector<DVect3>,
11 std::vector<DAVect2>,std::vector<DAVect3>,std::vector<SymTensor>,std::vector<string>,
12 FVect2,FVect3,UVect2,UVect3,IAVect2,IAVect3,FAVect2,FAVect3,UAVect2,UAVect3>;
16 using IVariantBase::variant;
18 enum Type { Invalid, Char, Bool, Int, UInt, LongLong, ULongLong, Double,
String, List, UserType };
19 static constexpr int uinvalid = 0;
20 static constexpr int uivect2 = 10;
21 static constexpr int udvect2 = 11;
22 static constexpr int uivect3 = 12;
23 static constexpr int udvect3 = 13;
24 static constexpr int uavect2 = 14;
25 static constexpr int uavect3 = 15;
26 static constexpr int utensor = 16;
27 static constexpr int uvariant = 17;
28 static constexpr int uvbool = 18;
29 static constexpr int uvint = 19;
30 static constexpr int uvint64 = 20;
31 static constexpr int uvdouble = 21;
32 static constexpr int uvistring = 22;
33 static constexpr int uvdvect2 = 23;
34 static constexpr int uvdvect3 = 24;
35 static constexpr int uvdavect2 = 25;
36 static constexpr int uvdavect3 = 26;
37 static constexpr int uvtensor = 27;
38 static constexpr int uvstring = 28;
39 static constexpr int ufvect2 = 29;
40 static constexpr int ufvect3 = 30;
41 static constexpr int uuvect2 = 31;
42 static constexpr int uuvect3 = 32;
43 static constexpr int uiavect2 = 33;
44 static constexpr int uiavect3 = 34;
45 static constexpr int ufavect2 = 35;
46 static constexpr int ufavect3 = 36;
47 static constexpr int uuavect2 = 37;
48 static constexpr int uuavect3 = 38;
53 bool isNull()
const {
return index()==0; }
60 char toChar()
const {
return std::get<char>(*
this); }
61 bool toBool()
const {
return std::get<bool>(*
this); }
62 int32 toInt()
const {
return std::get<int32>(*
this); }
63 uint32 toUInt()
const {
return std::get<uint32>(*
this); }
64 int64 toLongLong()
const {
return std::get<int64>(*
this); }
65 uint64 toULongLong()
const {
return std::get<uint64>(*
this); }
66 BASE_EXPORT double toDouble(
bool *ok=
nullptr)
const;
67 IString toString()
const {
return std::get<IString>(*
this); }
68 IList<IVariant> toList()
const {
return std::get<IList<IVariant>>(*this); }
70 IString typeName()
const {
return base::ts(index()); }
74 template <
typename T> T value()
const {
return std::get<T>(*
this); }
76 template <
typename T>
void setValue(
const T &t) { *
this = t; }
78 template <
typename T>
bool canConvert()
const {
static_assert(
sizeof(T)<0);
return false; }
84template <>
BASE_EXPORT bool IVariant::canConvert<bool>()
const;
85template <>
BASE_EXPORT bool IVariant::canConvert<int32>()
const;
86template <>
BASE_EXPORT bool IVariant::canConvert<uint32>()
const;
87template <>
BASE_EXPORT bool IVariant::canConvert<int64>()
const;
88template <>
BASE_EXPORT bool IVariant::canConvert<uint64>()
const;
89template <>
BASE_EXPORT bool IVariant::canConvert<double>()
const;
90template <>
BASE_EXPORT bool IVariant::canConvert<string>()
const;
91template <>
BASE_EXPORT bool IVariant::canConvert<IString>()
const;
92template <>
BASE_EXPORT bool IVariant::canConvert<IVect2>()
const;
93template <>
BASE_EXPORT bool IVariant::canConvert<DVect2>()
const;
94template <>
BASE_EXPORT bool IVariant::canConvert<IVect3>()
const;
95template <>
BASE_EXPORT bool IVariant::canConvert<DVect3>()
const;
96template <>
BASE_EXPORT bool IVariant::canConvert<DAVect2>()
const;
97template <>
BASE_EXPORT bool IVariant::canConvert<DAVect3>()
const;
98template <>
BASE_EXPORT bool IVariant::canConvert<SymTensor>()
const;
103template <
typename T>
int getIVariantUserType() {
static_assert(
sizeof(T)<0);
return 0; }
104template <>
inline int getIVariantUserType<IString>() {
return static_cast<int>(IVariant::String); }
105template <>
inline int getIVariantUserType<Variant>() {
return IVariant::uvariant; }
106template <>
inline int getIVariantUserType<IVect2>() {
return IVariant::uivect2; }
107template <>
inline int getIVariantUserType<DVect2>() {
return IVariant::udvect2; }
108template <>
inline int getIVariantUserType<IVect3>() {
return IVariant::uivect3; }
109template <>
inline int getIVariantUserType<DVect3>() {
return IVariant::udvect3; }
110template <>
inline int getIVariantUserType<FVect2>() {
return IVariant::ufvect2; }
111template <>
inline int getIVariantUserType<FVect3>() {
return IVariant::ufvect3; }
112template <>
inline int getIVariantUserType<UVect2>() {
return IVariant::uuvect2; }
113template <>
inline int getIVariantUserType<UVect3>() {
return IVariant::uuvect3; }
114template <>
inline int getIVariantUserType<DAVect2>() {
return IVariant::uavect2; }
115template <>
inline int getIVariantUserType<DAVect3>() {
return IVariant::uavect3; }
116template <>
inline int getIVariantUserType<IAVect2>() {
return IVariant::uiavect2; }
117template <>
inline int getIVariantUserType<IAVect3>() {
return IVariant::uiavect3; }
118template <>
inline int getIVariantUserType<FAVect2>() {
return IVariant::ufavect2; }
119template <>
inline int getIVariantUserType<FAVect3>() {
return IVariant::ufavect3; }
120template <>
inline int getIVariantUserType<UAVect2>() {
return IVariant::uuavect2; }
121template <>
inline int getIVariantUserType<UAVect3>() {
return IVariant::uuavect3; }
122template <>
inline int getIVariantUserType<SymTensor>() {
return IVariant::utensor; }
123template <>
inline int getIVariantUserType<std::vector<bool>>() {
return IVariant::uvbool; }
124template <>
inline int getIVariantUserType<std::vector<int>>() {
return IVariant::uvint; }
125template <>
inline int getIVariantUserType<std::vector<int64>>() {
return IVariant::uvint64; }
126template <>
inline int getIVariantUserType<std::vector<double>>() {
return IVariant::uvdouble; }
127template <>
inline int getIVariantUserType<std::vector<IString>>() {
return IVariant::uvistring; }
128template <>
inline int getIVariantUserType<std::vector<DVect2>>() {
return IVariant::uvdvect2; }
129template <>
inline int getIVariantUserType<std::vector<DVect3>>() {
return IVariant::uvdvect3; }
130template <>
inline int getIVariantUserType<std::vector<DAVect2>>() {
return IVariant::uvdavect2; }
131template <>
inline int getIVariantUserType<std::vector<DAVect3>>() {
return IVariant::uvdavect3; }
132template <>
inline int getIVariantUserType<std::vector<SymTensor>>() {
return IVariant::uvtensor; }
133template <>
inline int getIVariantUserType<std::vector<string>>() {
return IVariant::uvstring; }
136template <>
struct fmt::formatter<
IVariant> :
public fmt::formatter<string> {
137 template <
typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
138 return fmt::formatter<string>::parse(ctx);
141 template <
typename FormatContext>
auto format(
IVariant const& val, FormatContext& ctx) {
143 switch (val.type()) {
145 out = base::ts(val.toBool());
148 out = base::ts(val.toInt());
151 out = base::ts(val.toUInt());
153 case IVariant::LongLong:
154 out = base::ts(val.toLongLong());
156 case IVariant::ULongLong:
157 out = base::ts(val.toULongLong());
159 case IVariant::Double:
160 out = base::ts(val.toDouble());
162 case IVariant::String:
163 out = base::ts(val.toString());
165 case IVariant::UserType: {
166 switch (val.userType()) {
167 case IVariant::uivect2:
168 out = base::ts(val.value<IVect2>());
170 case IVariant::udvect2:
171 out = base::ts(val.value<DVect2>());
173 case IVariant::uivect3:
174 out = base::ts(val.value<IVect3>());
176 case IVariant::udvect3:
177 out = base::ts(val.value<DVect3>());
179 case IVariant::uavect2:
180 out = base::ts(val.value<DAVect2>());
182 case IVariant::uavect3:
183 out = base::ts(val.value<DAVect3>());
189 throw Exception(
"Unable to format IVariant type {}.", val.typeName());
191 return fmt::formatter<string>::format(out, ctx);
Base exception class for all Itasca code.
Definition baseexception.h:10
A symmetric 2nd order tensor.
Definition symtensor.h:22
A simpler (and slightly faster) version of a QVariant, added for interfaces that do not use Qt.
Definition variant.h:32
std::basic_string< char8 > String
std::string of type Char
Definition basebool.h:9
#define BASE_EXPORT
Definition basedef.h:24