13#pragma  warning(disable:2586)  
   29    template <> 
string ts(
const PropArray &p, 
int width, 
char notation, 
int precision, 
char fill);
 
   31    using PropBase = std::variant<int64,   double,   bool,     string,      DVect2,
 
   38        using PropBase::PropBase;
 
   40        enum class Type { Int,     Double,   Bool,     
String, DVect2,
 
   41                          DVect3,  I64Vect2, I64Vect3, 
Matrix, DAVect2,
 
   48        inline Type type() 
const;
 
   51        inline bool isNull()
 const { 
return type()==Type::Null; }
 
   52        inline bool isValid()
 const { 
return not isNull(); }
 
   57        bool canConvert()
 const { 
static_assert(
sizeof(T)==0);  
return false; } 
 
   61        bool canConvertVec() 
const;
 
   65        bool canConvertType()
 const { 
return canConvert<decltype(std::get<static_cast<int>(t)>(*this))>(); }
 
   69        T to()
 const { 
static_assert(
sizeof(T)==0);  
return false; } 
 
   71        std::vector<T> toVec() 
const;
 
   75        auto toType()
 const { 
return to<decltype(std::get<static_cast<int>(t)>(*this))>(); }
 
   80        typename std::tuple<T,bool> toTest() 
const;
 
   84        typename std::variant_alternative_t<static_cast<int>(t),
Property> toTestType() 
const;
 
   87        void setValue(
const T &t) { *
this = t; }
 
   89        void setVec(
const std::vector<T> &v);
 
   92        T value()
 const { 
return to<T>(); }
 
   95        inline double toDouble() 
const;
 
   96        inline string toString() 
const;
 
   97        inline int64  toInt() 
const;
 
   98        inline uint32 toUInt() 
const;
 
   99        inline double toDouble(
bool *ok) 
const;
 
  100        inline int64  toInt(
bool *ok) 
const;
 
  102        static constexpr Type DVectType(uint32 dim) { 
return dim==2 ? Type::DVect2 : Type::DVect3; }
 
  103        static constexpr Type DAVectType(uint32 dim) { 
return dim==2 ? Type::DAVect2 : Type::DAVect3; }
 
  104        static constexpr Type IVectType(uint32 dim) { 
return dim==2 ? Type::I64Vect2 : Type::I64Vect3; }
 
 
  107    Property::Type Property::type()
 const { 
 
  108        return static_cast<Type
>(index());  
 
  112    template <> 
BASE_EXPORT bool Property::canConvert<int64>() 
const;
 
  113    template <> 
BASE_EXPORT bool Property::canConvert<double>() 
const;
 
  114    template <> 
BASE_EXPORT bool Property::canConvert<bool>() 
const;
 
  115    template <> 
BASE_EXPORT bool Property::canConvert<string>() 
const;
 
  116    template <> 
BASE_EXPORT bool Property::canConvert<DVect2>() 
const;
 
  117    template <> 
BASE_EXPORT bool Property::canConvert<DVect3>() 
const;
 
  118    template <> 
BASE_EXPORT bool Property::canConvert<I64Vect2>() 
const;
 
  119    template <> 
BASE_EXPORT bool Property::canConvert<I64Vect3>() 
const;
 
  120    template <> 
BASE_EXPORT bool Property::canConvert<itasca::Mat>() 
const;
 
  121    template <> 
BASE_EXPORT bool Property::canConvert<DAVect2>() 
const;
 
  122    template <> 
BASE_EXPORT bool Property::canConvert<DAVect3>() 
const;
 
  123    template <> 
BASE_EXPORT bool Property::canConvert<Quat2>() 
const;
 
  124    template <> 
BASE_EXPORT bool Property::canConvert<Quat3>() 
const;
 
  125    template <> 
BASE_EXPORT bool Property::canConvert<SymTensor>() 
const;
 
  126    template <> 
BASE_EXPORT bool Property::canConvert<PropArray>() 
const;
 
  128    template <> 
BASE_EXPORT int64       Property::to<int64>() 
const;
 
  129    template <> 
BASE_EXPORT double      Property::to<double>() 
const;
 
  130    template <> 
BASE_EXPORT bool        Property::to<bool>() 
const;
 
  131    template <> 
BASE_EXPORT string      Property::to<string>() 
const;
 
  132    template <> 
BASE_EXPORT DVect2      Property::to<DVect2>() 
const;
 
  133    template <> 
BASE_EXPORT DVect3      Property::to<DVect3>() 
const;
 
  134    template <> 
BASE_EXPORT I64Vect2    Property::to<I64Vect2>() 
const;
 
  135    template <> 
BASE_EXPORT I64Vect3    Property::to<I64Vect3>() 
const;
 
  137    template <> 
BASE_EXPORT DAVect2     Property::to<DAVect2>() 
const;
 
  138    template <> 
BASE_EXPORT DAVect3     Property::to<DAVect3>() 
const;
 
  142    template <> 
BASE_EXPORT PropArray   Property::to<PropArray>() 
const;
 
  147            Exception(
"Error converting Property from {} to {}.",
 
  148                Property::nameFromType(from),Property::nameFromType(
to)) {
 
 
  152    template <
typename T>
 
  153    void Property::setVec(
const std::vector<T> &v) {
 
  156        for (
size_t i=0;i<v.size();++i) {
 
  158            pa.back().setValue(v[0]);
 
  159            if (not i) t = pa.back().type();
 
  160            else if (t!=pa.back().type()) 
throw Exception(
"All elements of a property array must be of the same type.");
 
  165    double Property::toDouble()
 const { 
return to<double>(); }
 
  166    string Property::toString()
 const { 
return to<string>(); }
 
  167    int64  Property::toInt()
 const { 
return to<int64>();}
 
  168    uint32 Property::toUInt()
 const { 
return static_cast<uint32
>(to<int64>()); }
 
  170    double Property::toDouble(
bool *ok)
 const { 
 
  171        *ok = canConvert<double>(); 
 
  172        if (*ok) 
return to<double>();  
 
  176    int64  Property::toInt(
bool *ok)
 const { 
 
  177        *ok = canConvert<int64>();  
 
  178        if (*ok) 
return to<int64>();  
 
  182    template <
typename T>
 
  183    typename std::tuple<T,bool> Property::toTest()
 const {
 
  184        bool b = canConvert<T>();
 
  190    template <Property::Type t>
 
  191    typename std::variant_alternative_t<static_cast<int>(t),Property> Property::toTestType()
 const {
 
  192        using target_type = 
decltype(std::get<static_cast<int>(t)>(*this));
 
  193        using return_type = std::tuple<target_type,bool>;
 
  194        bool b = canConvert<target_type>();
 
  195        if (b) 
return return_type(to<target_type>(),
true);
 
  196        return return_type(target_type{},
false);
 
  199    template <
typename T>
 
  200    bool Property::canConvertVec()
 const {
 
  201        if (type()!=Type::Array) 
return false;
 
  202        auto &a = std::get<PropArray>(*
this);
 
  203        if (not a.size()) 
return true;
 
  204        return a[0].canConvert<T>();
 
  207    template <
typename T>
 
  208    std::vector<T> Property::toVec()
 const {
 
  209        if (type()!=Type::Array) 
throw PropertyConvertException(type(),Type::Array);
 
  210        auto &a = std::get<PropArray>(*
this);
 
  211        if (not a.size()) 
return {};
 
  214            ret.push_back(v.to<T>());
 
  220    template <Property::Type t>
 
  221    const auto &get(
const Property &v) { 
return std::get<static_cast<int>(t)>(v); }
 
  230        PropDesc(
const string &name,Property::Type type,UVect2 size) : name_(name), type_(type), size_(size) { }
 
  233        Property::Type type_ = Property::Type::Int;
 
  234        UVect2         size_ = UVect2(0);
 
  235        auto operator<=>(
const PropDesc &p) 
const = 
default;
 
 
  245struct std::formatter<base::Property> : 
public std::formatter<string> {
 
  246    template <
typename ParseContext>
 
  247    constexpr auto parse(ParseContext &ctx) { 
return std::formatter<string>::parse(ctx); }
 
  249    template <
typename FormatContext>
 
  250    constexpr auto format(
base::Property const &val, FormatContext &ctx)
 const {
 
  251        return std::formatter<string>::format(val.to<
string>(), ctx);
 
 
includes std::string and additional functions not included in the standard.
Base exception class for all Itasca code.
Definition baseexception.h:10
A template-based matrix class, size fixed at compile time. Defaults to symmetric sized matrix.
Definition matrix.h:22
2D quaternion-like utility class. In this case only the angle (in radians) is stored as opposed to th...
Definition quat.h:20
3D quaternion utility class.
Definition quat.h:111
A symmetric 2nd order tensor.
Definition symtensor.h:22
Definition property.h:144
std::basic_string< char8 > String
std::string of type Char
Definition basebool.h:9
#define BASE_EXPORT
Definition basedef.h:25
constexpr D to(const T &t)
This template function serves as an alternative to static_cast<T>().
Definition to.h:28
2D and 3D quaternion utility classes.
Definition property.h:228
2D and 3D vector utility classes.