GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 51.1% 24 / 1 / 48
Functions: 76.9% 10 / 1 / 14
Branches: 35.0% 7 / 1 / 21

src/utilities/idf/IdfExtensibleGroup.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_IDF_IDFEXTENSIBLEGROUP_HPP
7 #define UTILITIES_IDF_IDFEXTENSIBLEGROUP_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "../idd/ExtensibleIndex.hpp"
11 #include "Handle.hpp"
12
13 #include "../core/Logger.hpp"
14
15 namespace openstudio {
16
17 namespace detail {
18
19 // forward declarations
20 class IdfObject_Impl;
21
22 } // namespace detail
23
24 // forward declarations
25 class IdfObject;
26
27 /** IdfExtensibleGroup wraps a single set of extensible fields in an IdfObject. For instance,
28 * many geometric objects have extensible groups each of which represents a single vertex
29 * (one three-dimensional point). (Also see the documentation for IddObject,
30 * IddObjectProperties, and ExtensibleIndex.) */
31 class UTILITIES_API IdfExtensibleGroup
32 {
33 public:
34 /** @name Constructors and Destructors */
35 //@{
36
37 11415755 virtual ~IdfExtensibleGroup() = default;
38
39 //@}
40 /** @name Getters */
41 //@{
42
43 /** Returns this extensible group's fields. Return value will be empty() if this group is empty(). */
44 std::vector<std::string> fields(bool returnDefault = false) const;
45
46 /** Returns this extensible group's fields. Return value will be empty() if this group is empty().
47 * Unlike fields(), in the case it's a WorkspaceObject_Impl, it uses handles as string and not the name of the target object */
48 std::vector<std::string> fieldsWithHandles(bool returnDefault = false) const;
49
50 /** Returns the comments associated with this extensible group's fields. */
51 std::vector<std::string> fieldComments(bool returnDefault = false) const;
52
53 /** Returns the comment associated with this extensible group's field fieldIndex. */
54 boost::optional<std::string> fieldComment(unsigned fieldIndex, bool returnDefault = false) const;
55
56 /** Returns the string value of this extensible group's field fieldIndex, if that field
57 * exists (isValid(fieldIndex)). */
58 boost::optional<std::string> getString(unsigned fieldIndex, bool returnDefault = false) const;
59
60 /** Like getString except for reference fields getString will return the name of the referenced object.
61 * This method, getField, will always return the string value of the field. */
62 boost::optional<std::string> getField(unsigned index, bool returnDefault = false) const;
63
64 /** Returns true if the field is empty. */
65 bool isEmpty(unsigned fieldIndex) const;
66
67 /** Returns the value, converted to type double, of this extensible group's field fieldIndex,
68 * if possible. */
69 boost::optional<double> getDouble(unsigned fieldIndex, bool returnDefault = false) const;
70
71 /** Returns the value, converted to type unsigned, of this extensible group's field fieldIndex,
72 * if possible. */
73 boost::optional<unsigned> getUnsigned(unsigned fieldIndex, bool returnDefault = false) const;
74
75 /** Returns the value, converted to type int, of this extensible group's field fieldIndex,
76 * if possible. */
77 boost::optional<int> getInt(unsigned fieldIndex, bool returnDefault = false) const;
78
79 //@}
80 /** @name Setters */
81 //@{
82
83 /** Sets the comment associated with this extensible group's field fieldIndex, if possible.
84 * Otherwise, returns false. */
85 bool setFieldComment(unsigned fieldIndex, const std::string& cmnt);
86
87 /** Set all the fields in this IdfExtensibleGroup, if possible. Returns false if values is wrong
88 * size or setString fails on any individual fields. */
89 bool setFields(const std::vector<std::string>& values);
90
91 /** Set this extensible group's field fieldIndex to value, if possible. Returns false if it
92 * cannot be set for any reason. */
93 bool setString(unsigned fieldIndex, const std::string& value);
94
95 /** setString that can delay signal emits. */
96 bool setString(unsigned fieldIndex, const std::string& value, bool checkValidity);
97
98 /** Set this extensible group's field fieldIndex to value, if possible. Returns false if it
99 * cannot be set for any reason. */
100 bool setDouble(unsigned fieldIndex, double value);
101
102 /** Set this extensible group's field fieldIndex to value, if possible. Returns false if it
103 * cannot be set for any reason. */
104 bool setUnsigned(unsigned fieldIndex, unsigned value);
105
106 /** Set this extensible group's field fieldIndex to value, if possible. Returns false if it
107 * cannot be set for any reason. */
108 bool setInt(unsigned fieldIndex, int value);
109
110 /** Clones the data in this extensible group, and pushes the new extensible group onto the end
111 * of the enclosing object. The returned IdfExtensibleGroup will be empty() if the operation
112 * cannot be completed. */
113 IdfExtensibleGroup pushClone() const;
114
115 /** Clones the data in this extensible group, and inserts the new extensible group at groupIndex
116 * within the enclosing object. The returned IdfExtensibleGroup will be empty() if the operation
117 * cannot be completed. */
118 IdfExtensibleGroup insertClone(unsigned groupIndex) const;
119
120 //@}
121 /** @name Queries */
122 //@{
123
124 /** Returns true if this ExtensibleGroup holds no data. */
125 bool empty() const;
126
127 /** Returns the (group) index of this ExtensibleGroup. Indexing starts at 0. Throws if
128 * ExtensibleGroup is empty(). */
129 unsigned groupIndex() const;
130
131 /** Returns the number of fields in this ExtensibleGroup. */
132 unsigned numFields() const;
133
134 /** Returns true if fieldIndex is valid for this extensible group. */
135 bool isValid(unsigned fieldIndex) const;
136
137 /** Returns the indices of all fields that can point to other objects. */
138 std::vector<unsigned> objectListFields() const;
139
140 /** Returns the indices of all fields that are not objectListFields() (and are therefore plain
141 * alpha or numeric data). */
142 std::vector<unsigned> dataFields() const;
143
144 /** Returns the indices of all fields in this ExtensibleGroup that are required, as defined
145 * by the IddObject. */
146 std::vector<unsigned> requiredFields() const;
147
148 /** Equality comparator for \link IdfExtensibleGroup IdfExtensibleGroups\endlink. Tests for
149 * strict identity (same IdfObject, same groupIndex()). */
150 bool operator==(const IdfExtensibleGroup& other) const;
151
152 /** Negation of operator==.*/
153 bool operator!=(const IdfExtensibleGroup& other) const;
154
155 //@}
156 /** @name Type Casting */
157 //@{
158
159 /// cast to type T, can throw std::bad_cast
160 template <typename T>
161 341372 T cast() const {
162
4/4
openstudio::WorkspaceExtensibleGroup openstudio::IdfExtensibleGroup::cast<openstudio::WorkspaceExtensibleGroup>() const:
✓ Branch 2 taken 11764 times.
openstudio::model::BillingPeriod openstudio::IdfExtensibleGroup::cast<openstudio::model::BillingPeriod>() const:
✓ Branch 2 taken 12 times.
openstudio::model::ClimateZone openstudio::IdfExtensibleGroup::cast<openstudio::model::ClimateZone>() const:
✓ Branch 2 taken 17 times.
openstudio::model::ModelExtensibleGroup openstudio::IdfExtensibleGroup::cast<openstudio::model::ModelExtensibleGroup>() const:
✓ Branch 2 taken 329579 times.
341372 return T(this->getImpl<typename T::ImplType>(), m_index);
163 }
164
165 /// cast to optional of type T
166 template <typename T>
167 2 boost::optional<T> optionalCast() const {
168 2 boost::optional<T> result;
169 2 std::shared_ptr<typename T::ImplType> impl = this->getImpl<typename T::ImplType>();
170
1/8
boost::optional<openstudio::WorkspaceExtensibleGroup> openstudio::IdfExtensibleGroup::optionalCast<openstudio::WorkspaceExtensibleGroup>() const:
✗ Branch 1 not taken.
✗ Branch 2 not taken.
boost::optional<openstudio::model::BillingPeriod> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::BillingPeriod>() const:
✗ Branch 1 not taken.
✗ Branch 2 not taken.
boost::optional<openstudio::model::ClimateZone> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::ClimateZone>() const:
✗ Branch 1 not taken.
✗ Branch 2 not taken.
boost::optional<openstudio::model::ModelExtensibleGroup> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::ModelExtensibleGroup>() const:
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (impl) {
171
2/8
boost::optional<openstudio::WorkspaceExtensibleGroup> openstudio::IdfExtensibleGroup::optionalCast<openstudio::WorkspaceExtensibleGroup>() const:
✗ Branch 3 not taken.
✗ Branch 6 not taken.
boost::optional<openstudio::model::BillingPeriod> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::BillingPeriod>() const:
✗ Branch 3 not taken.
✗ Branch 6 not taken.
boost::optional<openstudio::model::ClimateZone> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::ClimateZone>() const:
✗ Branch 3 not taken.
✗ Branch 6 not taken.
boost::optional<openstudio::model::ModelExtensibleGroup> openstudio::IdfExtensibleGroup::optionalCast<openstudio::model::ModelExtensibleGroup>() const:
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
2 result = T(std::move(impl), m_index);
172 }
173 4 return result;
174 2 }
175
176 /** Get the parent object. */
177 template <typename T>
178 T getObject() const {
179 T result(std::move(std::dynamic_pointer_cast<typename T::ImplType>(m_impl)));
180 return result;
181 }
182
183 /** Get the parent object. */
184 template <typename T>
185 boost::optional<T> getOptionalObject() const {
186 boost::optional<T> result;
187 std::shared_ptr<typename T::ImplType> p = std::dynamic_pointer_cast<typename T::ImplType>(m_impl);
188 if (p) {
189 result = T(std::move(p));
190 }
191 return result;
192 }
193
194 //@}
195 protected:
196 ///@cond
197 using ImplType = detail::IdfObject_Impl;
198
199 friend class detail::IdfObject_Impl;
200
201 std::shared_ptr<detail::IdfObject_Impl> m_impl;
202 unsigned m_index; // index corresponding to first field of the extensible group
203
204 // get the impl
205 template <typename T>
206 385003 std::shared_ptr<T> getImpl() const {
207 385003 return std::dynamic_pointer_cast<T>(m_impl);
208 }
209
210 /** Private constructor to be used by IdfObject. */
211 IdfExtensibleGroup(std::shared_ptr<detail::IdfObject_Impl> impl, unsigned index);
212
213 /** Set all the fields in this group, if possible. Returns false if values is wrong size or
214 * setString fails on any individual fields. Emits signals if checkValidity == true. Function
215 * provided so object method implementations can call it with checkValidity == false. */
216 bool setFields(const std::vector<std::string>& values, bool checkValidity);
217
218 unsigned mf_toIndex(unsigned fieldIndex) const;
219
220 /** Return all object indices accessible through this extensible group. */
221 std::vector<unsigned> mf_indices() const;
222
223 std::vector<unsigned> mf_subsetAndToFieldIndices(std::vector<unsigned> indices) const;
224 ///@endcond
225 private:
226 /** Private default constructor. */
227 IdfExtensibleGroup();
228
229 − REGISTER_LOGGER("openstudio.IdfExtensibleGroup");
230 };
231
232 /** \relates IdfExtensibleGroup */
233 using IdfExtensibleGroupVector = std::vector<IdfExtensibleGroup>;
234
235 } // namespace openstudio
236
237 #endif // UTILITIES_IDF_IDFEXTENSIBLEGROUP_HPP
238