1 // Copyright(C) 1999-2020 National Technology & Engineering Solutions 2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with 3 // NTESS, the U.S. Government retains certain rights in this software. 4 // 5 // See packages/seacas/LICENSE for details 6 7 #ifndef IOSS_Ioss_Property_h 8 #define IOSS_Ioss_Property_h 9 10 #include "vtk_ioss_mangle.h" 11 12 #include <cstdint> // for int64_t 13 #include <string> // for string 14 #include <vector> 15 16 namespace Ioss { 17 class GroupingEntity; 18 } // namespace Ioss 19 20 namespace Ioss { 21 22 /** \brief A named value that has a known type. 23 * 24 */ 25 class Property 26 { 27 public: 28 enum BasicType { INVALID = -1, REAL, INTEGER, POINTER, STRING, VEC_INTEGER, VEC_DOUBLE }; 29 enum Origin { 30 INTERNAL = -1, //<! Property is for internal use 31 IMPLICIT, //<! Property is calculated on the fly based on current state of entity containing 32 // property 33 EXTERNAL, //<! Property was created by client 34 ATTRIBUTE //<! Property created from an Exodus or Database Attribute 35 }; 36 37 Property() = default; 38 Property(std::string name, int64_t value, Origin origin = INTERNAL); 39 Property(std::string name, int value, Origin origin = INTERNAL); 40 Property(std::string name, double value, Origin origin = INTERNAL); 41 Property(std::string name, const std::string &value, Origin origin = INTERNAL); 42 Property(std::string name, const char *value, Origin origin = INTERNAL); 43 Property(std::string name, void *value, Origin origin = INTERNAL); 44 Property(std::string name, const std::vector<int> &value, Origin origin = INTERNAL); 45 Property(std::string name, const std::vector<double> &value, Origin origin = INTERNAL); 46 47 // To set implicit property 48 Property(const GroupingEntity *ge, std::string name, BasicType type); 49 50 Property(const Property &from); 51 Property &operator=(Property const& rhs); 52 53 ~Property(); 54 55 std::string get_string() const; 56 int64_t get_int() const; 57 double get_real() const; 58 void * get_pointer() const; 59 std::vector<double> get_vec_double() const; 60 std::vector<int> get_vec_int() const; 61 set_origin(Origin origin)62 void set_origin(Origin origin) { origin_ = origin; } get_origin()63 Origin get_origin() const { return origin_; } 64 65 /** \brief Tells whether the property is calculated, rather than stored. 66 * 67 * \returns True if property is calculated; False if it is stored directly. 68 */ is_implicit()69 bool is_implicit() const { return origin_ == IMPLICIT; } 70 71 /** \brief Tells whether the property is stored, rather than calculated. 72 * 73 * \returns True if property is stored directly; False if it is calculated. 74 */ is_explicit()75 bool is_explicit() const { return origin_ != IMPLICIT; } 76 77 /** Tells whether the property has a valid type (currently REAL, INTEGER, POINTER, or STRING) 78 * 79 * \returns True if the property type is valid. 80 */ is_valid()81 bool is_valid() const { return type_ != INVALID; } 82 83 /** Tells whether the property has an invalid type (currently not one of REAL, INTEGER, POINTER, 84 * or STRING) 85 * 86 * \returns True if the property type is invalid. 87 */ is_invalid()88 bool is_invalid() const { return type_ == INVALID; } 89 90 /** \brief Get the property name. 91 * 92 * \returns The property name. 93 */ get_name()94 std::string get_name() const { return name_; } 95 96 /** \brief Get the property type. 97 * 98 * \returns The property type. 99 */ get_type()100 BasicType get_type() const { return type_; } 101 102 bool operator!=(const Ioss::Property rhs) const; 103 bool operator==(const Ioss::Property rhs) const; 104 105 private: 106 std::string name_{}; 107 BasicType type_{INVALID}; 108 109 /// True if property is calculated rather than stored. 110 /// False if property is stored in 'data_' 111 Origin origin_{INTERNAL}; 112 113 bool get_value(int64_t *value) const; 114 bool get_value(double *value) const; 115 bool get_value(std::string *value) const; 116 bool get_value(void *&value) const; 117 bool get_value(std::vector<double> *value) const; 118 bool get_value(std::vector<int> *value) const; 119 120 /// The actual value of the property. Use 'type_' to 121 /// discriminate the actual type of the property. 122 union Data { 123 std::string * sval; 124 void * pval{nullptr}; 125 const GroupingEntity *ge; 126 double rval; 127 int64_t ival; 128 std::vector<double> * dvec; 129 std::vector<int> * ivec; 130 }; 131 Data data_{}; 132 }; 133 } // namespace Ioss 134 #endif 135