IOSS  2.0
Ioss_Property.h
Go to the documentation of this file.
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 <cstdint> // for int64_t
11 #include <string> // for string
12 #include <vector>
13 
14 namespace Ioss {
15  class GroupingEntity;
16 } // namespace Ioss
17 
18 namespace Ioss {
19 
20  /** \brief A named value that has a known type.
21  *
22  */
23  class Property
24  {
25  public:
27  enum Origin {
28  INTERNAL = -1, //<! Property is for internal use
29  IMPLICIT, //<! Property is calculated on the fly based on current state of entity containing
30  // property
31  EXTERNAL, //<! Property was created by client
32  ATTRIBUTE //<! Property created from an Exodus or Database Attribute
33  };
34 
35  Property() = default;
36  Property(std::string name, int64_t value, Origin origin = INTERNAL);
37  Property(std::string name, int value, Origin origin = INTERNAL);
38  Property(std::string name, double value, Origin origin = INTERNAL);
39  Property(std::string name, const std::string &value, Origin origin = INTERNAL);
40  Property(std::string name, const char *value, Origin origin = INTERNAL);
41  Property(std::string name, void *value, Origin origin = INTERNAL);
42  Property(std::string name, const std::vector<int> &value, Origin origin = INTERNAL);
43  Property(std::string name, const std::vector<double> &value, Origin origin = INTERNAL);
44 
45  // To set implicit property
46  Property(const GroupingEntity *ge, std::string name, BasicType type);
47 
48  Property(const Property &from);
50 
51  ~Property();
52 
53  std::string get_string() const;
54  int64_t get_int() const;
55  double get_real() const;
56  void * get_pointer() const;
57  std::vector<double> get_vec_double() const;
58  std::vector<int> get_vec_int() const;
59 
60  void set_origin(Origin origin) { origin_ = origin; }
61  Origin get_origin() const { return origin_; }
62 
63  /** \brief Tells whether the property is calculated, rather than stored.
64  *
65  * \returns True if property is calculated; False if it is stored directly.
66  */
67  bool is_implicit() const { return origin_ == IMPLICIT; }
68 
69  /** \brief Tells whether the property is stored, rather than calculated.
70  *
71  * \returns True if property is stored directly; False if it is calculated.
72  */
73  bool is_explicit() const { return origin_ != IMPLICIT; }
74 
75  /** Tells whether the property has a valid type (currently REAL, INTEGER, POINTER, or STRING)
76  *
77  * \returns True if the property type is valid.
78  */
79  bool is_valid() const { return type_ != INVALID; }
80 
81  /** Tells whether the property has an invalid type (currently not one of REAL, INTEGER, POINTER,
82  * or STRING)
83  *
84  * \returns True if the property type is invalid.
85  */
86  bool is_invalid() const { return type_ == INVALID; }
87 
88  /** \brief Get the property name.
89  *
90  * \returns The property name.
91  */
92  std::string get_name() const { return name_; }
93 
94  /** \brief Get the property type.
95  *
96  * \returns The property type.
97  */
98  BasicType get_type() const { return type_; }
99 
100  private:
101  std::string name_{};
103 
104  /// True if property is calculated rather than stored.
105  /// False if property is stored in 'data_'
107 
108  bool get_value(int64_t *value) const;
109  bool get_value(double *value) const;
110  bool get_value(std::string *value) const;
111  bool get_value(void *&value) const;
112  bool get_value(std::vector<double> *value) const;
113  bool get_value(std::vector<int> *value) const;
114 
115  /// The actual value of the property. Use 'type_' to
116  /// discriminate the actual type of the property.
117  union Data {
118  std::string * sval;
119  void * pval{nullptr};
121  double rval;
122  int64_t ival;
123  std::vector<double> * dvec;
124  std::vector<int> * ivec;
125  };
127  };
128 } // namespace Ioss
129 #endif
Ioss::Property::Data::ival
int64_t ival
Definition: Ioss_Property.h:122
Ioss::Property::POINTER
@ POINTER
Definition: Ioss_Property.h:26
Ioss::Property::~Property
~Property()
Definition: Ioss_Property.C:170
Ioss::Property::get_vec_int
std::vector< int > get_vec_int() const
Get the property value if it is of type VEC_INT.
Definition: Ioss_Property.C:221
Ioss::Property::EXTERNAL
@ EXTERNAL
Definition: Ioss_Property.h:31
Ioss::Property::STRING
@ STRING
Definition: Ioss_Property.h:26
Ioss::Property::is_explicit
bool is_explicit() const
Tells whether the property is stored, rather than calculated.
Definition: Ioss_Property.h:73
Ioss::Property::is_invalid
bool is_invalid() const
Definition: Ioss_Property.h:86
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:40
Ioss::Property::Data::dvec
std::vector< double > * dvec
Definition: Ioss_Property.h:123
Ioss::Property::IMPLICIT
@ IMPLICIT
Definition: Ioss_Property.h:29
Ioss::Property::get_vec_double
std::vector< double > get_vec_double() const
Get the property value if it is of type VEC_DOUBLE.
Definition: Ioss_Property.C:207
Ioss::Property::INTEGER
@ INTEGER
Definition: Ioss_Property.h:26
Ioss::Property::VEC_DOUBLE
@ VEC_DOUBLE
Definition: Ioss_Property.h:26
Ioss::Property::BasicType
BasicType
Definition: Ioss_Property.h:26
Ioss::Property::get_pointer
void * get_pointer() const
Get the property value if it is of type POINTER.
Definition: Ioss_Property.C:263
Ioss::Property::get_origin
Origin get_origin() const
Definition: Ioss_Property.h:61
Ioss::Property::set_origin
void set_origin(Origin origin)
Definition: Ioss_Property.h:60
Ioss::Property::INVALID
@ INVALID
Definition: Ioss_Property.h:26
Ioss::Property::ATTRIBUTE
@ ATTRIBUTE
Definition: Ioss_Property.h:32
Ioss::Property::origin_
Origin origin_
Definition: Ioss_Property.h:106
Ioss::Property::Data::ivec
std::vector< int > * ivec
Definition: Ioss_Property.h:124
Ioss::Property::get_type
BasicType get_type() const
Get the property type.
Definition: Ioss_Property.h:98
Ioss::Property::get_int
int64_t get_int() const
Get the property value if it is of type INTEGER.
Definition: Ioss_Property.C:235
Ioss::Property::Data
Definition: Ioss_Property.h:117
Ioss::Property::Data::sval
std::string * sval
Definition: Ioss_Property.h:118
Ioss::Property::is_implicit
bool is_implicit() const
Tells whether the property is calculated, rather than stored.
Definition: Ioss_Property.h:67
Ioss::Property::REAL
@ REAL
Definition: Ioss_Property.h:26
Ioss::Property::data_
Data data_
Definition: Ioss_Property.h:126
Ioss::Property::Origin
Origin
Definition: Ioss_Property.h:27
Ioss::Property::get_value
bool get_value(int64_t *value) const
Definition: Ioss_Property.C:273
Ioss::Property::type_
BasicType type_
Definition: Ioss_Property.h:102
Ioss::Property::VEC_INTEGER
@ VEC_INTEGER
Definition: Ioss_Property.h:26
Ioss::Property::is_valid
bool is_valid() const
Definition: Ioss_Property.h:79
Ioss::Property::Data::rval
double rval
Definition: Ioss_Property.h:121
Ioss::Property::get_name
std::string get_name() const
Get the property name.
Definition: Ioss_Property.h:92
Ioss::Property::Data::pval
void * pval
Definition: Ioss_Property.h:119
Ioss::Property::name_
std::string name_
Definition: Ioss_Property.h:101
Ioss::Property::INTERNAL
@ INTERNAL
Definition: Ioss_Property.h:28
Ioss::Property::get_string
std::string get_string() const
Get the property value if it is of type STRING.
Definition: Ioss_Property.C:193
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:65
Ioss::Property::Data::ge
const GroupingEntity * ge
Definition: Ioss_Property.h:120
Ioss::Property::operator=
Property & operator=(Property rhs)
Definition: Ioss_Property.C:183
Ioss::Property
A named value that has a known type.
Definition: Ioss_Property.h:24
Ioss::GroupingEntity
Base class for all 'grouping' entities. The following derived classes are typical:
Definition: Ioss_GroupingEntity.h:68
Ioss::Property::Property
Property()=default
Ioss::Property::get_real
double get_real() const
Get the property value if it is of type REAL.
Definition: Ioss_Property.C:249