GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 0 / 1 / 1
Functions: -% 0 / 1 / 1
Branches: -% 0 / 1 / 1

src/utilities/idd/IddField_Impl.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_IDD_IDDFIELD_IMPL_HPP
7 #define UTILITIES_IDD_IDDFIELD_IMPL_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "IddKey.hpp"
12 #include "IddFieldProperties.hpp"
13
14 #include "../core/Logger.hpp"
15
16 #include <string>
17 #include <ostream>
18 #include <vector>
19
20 namespace openstudio {
21
22 class Unit;
23
24 namespace detail {
25
26 // implementation of IddField
27 class UTILITIES_API IddField_Impl
28 {
29 public:
30 /** @name Constructors and Destructors */
31 //@{
32
33 /// Default constructor.
34 IddField_Impl();
35
36 //@}
37 /** @name Getters */
38 //@{
39
40 /** Returns this field's name. */
41 std::string name() const;
42
43 /** Returns this field's id in its parent IddObject, e.g. A1, A2, N1, N2. */
44 std::string fieldId() const;
45
46 /** Returns the properties of this field, that is, a list of IDD-markup information such as
47 * data type, default value, units, and numeric bounds. */
48 const IddFieldProperties& properties() const;
49
50 /** Returns the SI or IP units associated with this field, if they exist. All IDF data is stored
51 * in SI. The return value with returnIP == true can be used to convert underlying data to
52 * the default IP units. If there are no particular IP units specified in the IDD, this
53 * method attempts to choose appropriate units to which one can convert. */
54 boost::optional<Unit> getUnits(bool returnIP = false) const;
55
56 /** Returns true if the units markup for this field specifies that the units are dependent on
57 * the value of another field. Such units are not handled at the IdfFile/Workspace level. They
58 * should be explicitly handled by individual ModelObject classes. */
59 bool unitsBasedOnOtherField() const;
60
61 /** Get the IddKey object by keyName (case insensitive). */
62 boost::optional<IddKey> getKey(const std::string& keyName) const;
63
64 /** Get all of the IddKeys for this field. Only expected to be non-empty if this is a choice
65 * field (properties().type() == IddFieldType::ChoiceType). */
66 std::vector<IddKey> keys() const;
67
68 //@}
69 /** @name Setters */
70 //@{
71
72 /** Set the field name. Not for general use. */
73 void setName(const std::string& name);
74
75 /** Increments the field id number, that is, A1 becomes A2, etc. Added to support
76 * IddObject::insertHandleField(). Not for general use. */
77 void incrementFieldId(const boost::regex& fieldType = boost::regex("A"));
78
79 //@}
80 /** @name Queries */
81 //@{
82
83 /** Returns true if this field defines a reference name in IDF, or can be otherwise distinguised
84 * as an IdfObject name. Returns true if the field has a \\reference property and does not have
85 * an \\object-list property (if it has both, it is an example of a forwarded reference), or if
86 * the field is a plain AlphaType field named 'Name'. */
87 bool isNameField() const;
88
89 /** Returns true if this field is of object-list type and calls out one or more object-lists. */
90 bool isObjectListField() const;
91
92 /** Equality operator. Returns true if this IddField and other share an impl or if all
93 * underlying data is exactly equal. */
94 bool operator==(const IddField_Impl& other) const;
95
96 /** Inequality operator. Negation of operator==. */
97 bool operator!=(const IddField_Impl& other) const;
98
99 //@}
100 /** @name Serialization */
101 //@{
102
103 /** Load the IddField, that is, parse its text. Whitespace is not preserved. The string
104 * following the \\field slash code, or, if that is absent, the 'A' or 'N' identifier,
105 * should be sent in as name. objectName is the IddObject.name() to which this field
106 * belongs. */
107 static std::shared_ptr<IddField_Impl> load(const std::string& name, const std::string& text, const std::string& objectName);
108
109 /** Print the IddField to an output stream. Field slash codes are indented to produce pretty
110 * output. If lastField, then the field id will be followed by a semi-colon; otherwise, a
111 * comma will be used (consistent with IDD formatting). */
112 std::ostream& print(std::ostream& os, bool lastField) const;
113
114 //@}
115 private:
116 std::string m_name;
117 std::string m_fieldId; // e.g. A1, N1
118 std::string m_objectName; // name of IddObject to which this field belongs
119 IddFieldProperties m_properties; // IDD markup information
120 std::vector<IddKey> m_keys; // vector of all keys
121
122 // partial constructor used by load
123 IddField_Impl(const std::string& name, const std::string& objectName);
124
125 // parses the text
126 void parse(const std::string& text);
127
128 // parse single field
129 void parseField(const std::string& text);
130
131 // parse property of field
132 void parseProperty(const std::string& text);
133
134 // configure logging
135 − REGISTER_LOGGER("utilities.idd.IddField");
136 };
137
138 } // namespace detail
139 } // namespace openstudio
140
141 #endif // UTILITIES_IDD_IDDFIELD_IMPL_HPP
142