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