IOSS  2.0
Ioss_Property.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 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 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 #ifndef IOSS_Ioss_Property_h
34 #define IOSS_Ioss_Property_h
35 
36 #include <cstdint> // for int64_t
37 #include <string> // for string
38 namespace Ioss {
39  class GroupingEntity;
40 } // namespace Ioss
41 
42 namespace Ioss {
43 
44  /** \brief A named value that has a known type.
45  *
46  */
47  class Property
48  {
49  public:
51 
52  Property();
53  Property(std::string name, BasicType type, void *data, bool is_it_implicit = false);
54  Property(std::string name, int64_t value, bool is_it_implicit = false);
55  Property(std::string name, int value, bool is_it_implicit = false);
56  Property(std::string name, double value, bool is_it_implicit = false);
57  Property(std::string name, const std::string &value, bool is_it_implicit = false);
58  Property(std::string name, void *value, bool is_it_implicit);
59 
60  // To set implicit property
61  Property(const GroupingEntity *ge, std::string name, BasicType type);
62 
63  Property(const Property &from);
65 
66  ~Property();
67 
68  std::string get_string() const;
69  int64_t get_int() const;
70  double get_real() const;
71  void * get_pointer() const;
72 
73  /** \brief Tells whether the property is calculated, rather than stored.
74  *
75  * \returns True if property is calculated; False if it is stored directly.
76  */
77  bool is_implicit() const { return isImplicit_; }
78 
79  /** \brief Tells whether the property is stored, rather than calculated.
80  *
81  * \returns True if property is stored directly; False if it is calculated.
82  */
83  bool is_explicit() const { return !isImplicit_; }
84 
85  /** Tells whether the property has a valid type (currently REAL, INTEGER, POINTER, or STRING)
86  *
87  * \returns True if the property type is valid.
88  */
89  bool is_valid() const { return type_ != INVALID; }
90 
91  /** Tells whether the property has an invalid type (currently not one of REAL, INTEGER, POINTER,
92  * or STRING)
93  *
94  * \returns True if the property type is invalid.
95  */
96  bool is_invalid() const { return type_ == INVALID; }
97 
98  /** \brief Get the property name.
99  *
100  * \returns The property name.
101  */
102  std::string get_name() const { return name_; }
103 
104  /** \brief Get the property type.
105  *
106  * \returns The property type.
107  */
108  BasicType get_type() const { return type_; }
109 
110  private:
111  std::string name_;
113 
114  bool get_value(int64_t *value) const;
115  bool get_value(double *value) const;
116  bool get_value(std::string *value) const;
117  bool get_value(void *&value) const;
118 
119  // True if property is calculated rather than stored.
120  // False if property is stored in 'data_'
122 
123  // The actual value of the property. Use 'type_' and 'storage_' to
124  // discriminate the actual type of the property.
125  union Data {
126  std::string * sval;
127  void * pval;
129  double rval;
130  int64_t ival;
131  };
133  };
134 } // namespace Ioss
135 #endif
void * pval
Definition: Ioss_Property.h:127
A named value that has a known type.
Definition: Ioss_Property.h:47
const GroupingEntity * ge
Definition: Ioss_Property.h:128
BasicType get_type() const
Get the property type.
Definition: Ioss_Property.h:108
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
int64_t ival
Definition: Ioss_Property.h:130
int64_t get_int() const
Get the property value if it is of type INTEGER.
Definition: Ioss_Property.C:199
bool is_implicit() const
Tells whether the property is calculated, rather than stored.
Definition: Ioss_Property.h:77
Base class for all &#39;grouping&#39; entities. The following derived classes are typical: ...
Definition: Ioss_GroupingEntity.h:93
Data data_
Definition: Ioss_Property.h:132
Definition: Ioss_Property.h:50
bool get_value(int64_t *value) const
Definition: Ioss_Property.C:237
Definition: Ioss_Property.h:50
std::string get_name() const
Get the property name.
Definition: Ioss_Property.h:102
bool is_valid() const
Definition: Ioss_Property.h:89
Definition: Ioss_Property.h:50
BasicType type_
Definition: Ioss_Property.h:112
std::string name_
Definition: Ioss_Property.h:111
double get_real() const
Get the property value if it is of type REAL.
Definition: Ioss_Property.C:213
Definition: Ioss_Property.h:50
std::string get_string() const
Get the property value if it is of type STRING.
Definition: Ioss_Property.C:185
Property & operator=(Property rhs)
Definition: Ioss_Property.C:175
Definition: Ioss_Property.h:125
~Property()
Definition: Ioss_Property.C:168
bool is_invalid() const
Definition: Ioss_Property.h:96
double rval
Definition: Ioss_Property.h:129
bool is_explicit() const
Tells whether the property is stored, rather than calculated.
Definition: Ioss_Property.h:83
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:71
std::string * sval
Definition: Ioss_Property.h:126
Definition: Ioss_Property.h:50
std::vector< char > data
Definition: Ioss_Utils.C:78
Property()
Create an explicit, empty property having no name, INVALID type.
Definition: Ioss_Property.C:64
void * get_pointer() const
Get the property value if it is of type POINTER.
Definition: Ioss_Property.C:227
BasicType
Definition: Ioss_Property.h:50
bool isImplicit_
Definition: Ioss_Property.h:121