GCC Code Coverage Report


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

src/utilities/idf/WorkspaceObject.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_WORKSPACEOBJECT_HPP
7 #define UTILITIES_IDF_WORKSPACEOBJECT_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "IdfObject.hpp"
11
12 namespace openstudio {
13
14 class Workspace;
15 class WorkspaceExtensibleGroup;
16
17 // forward declarations
18 namespace detail {
19 class IdfObject_Impl;
20 class WorkspaceObject_Impl;
21 class Workspace_Impl;
22 } // namespace detail
23
24 /** WorkspaceObject holds and manipulates data objects in Energyplus IDF format in the context of
25 * a Workspace. Over and above IdfObject, WorkspaceObject maintains ObjectListType fields as
26 * pointers (possibly null) to other WorkspaceObjects in the same Workspace, and only commits
27 * changes that maintain the validity of its Workspace at the current StrictnessLevel (typically
28 * Draft, moving to Final right before simulation). */
29 class UTILITIES_API WorkspaceObject : public IdfObject
30 {
31 public:
32 /** @name Constructors and Destructors */
33 //@{
34
35 // TODO: virtual dtor, but no copy ctor / assignment nor move ones... The move ones will **not** be declared/defaulted
36 121147760 virtual ~WorkspaceObject() override = default;
37
38 8962351 WorkspaceObject(const WorkspaceObject& other) = default;
39 58479225 WorkspaceObject(WorkspaceObject&& other) = default;
40 3029 WorkspaceObject& operator=(const WorkspaceObject&) = default;
41 7845240 WorkspaceObject& operator=(WorkspaceObject&&) = default;
42
43 /** Removes the object from the Workspace. Returns an IdfObjectVector of all removed object(s). */
44 // TODO: Replace return type with undo struct including connections.
45 std::vector<openstudio::IdfObject> remove();
46
47 //@}
48 /** @name Getters */
49 //@{
50
51 /** Return the Workspace that contains this WorkspaceObject. */
52 Workspace workspace() const;
53
54 /** Returns the object pointed to by field index, if it exists. */
55 boost::optional<WorkspaceObject> getTarget(unsigned index) const;
56
57 /** Returns all objects pointed to by this object. */
58 std::vector<WorkspaceObject> targets() const;
59
60 /** Returns the index of the field in this object that points to targetHandle, if possible. */
61 std::vector<unsigned> getSourceIndices(const Handle& targetHandle) const;
62
63 /** Returns all objects that point to this object, filtering for duplicate objects. */
64 std::vector<WorkspaceObject> sources() const;
65
66 /** Returns all objects of type that point to this object, filtering for duplicate objects. */
67 std::vector<WorkspaceObject> getSources(IddObjectType type) const;
68
69 //@}
70 /** @name Setters */
71 //@{
72
73 /** Sets the pointer at field index to targetHandle, if possible. The field must be of object-list
74 * type, and targetHandle must be valid (null or in the containing Workspace, and if the strictness
75 * is greater than enums::None, must correspond to an object of a proper type). */
76 bool setPointer(unsigned index, const Handle& targetHandle);
77
78 //@}
79 /** @name Queries */
80 //@{
81
82 bool operator<(const WorkspaceObject& right) const;
83
84 bool initialized() const;
85
86 /** Returns the number of objects that point to this object. */
87 unsigned numSources() const;
88
89 /** Returns true if this object points to another object. To qualify, there must be at least one
90 * pointer field holding a non-null pointer. */
91 bool isSource() const;
92
93 /** Returns true if this object can point to another object. To qualify, there must be at least
94 * one object-list field. */
95 bool canBeSource() const;
96
97 /** Returns true if field index can be a source field. If no refLists are specified, then
98 * this call is equivalent to iddObject().getField(index)->isObjectListField(). If a
99 * non-empty vector of refLists is specified, then true is only returned if there is a match
100 * between field index's object lists and the referencesLists argument. */
101 bool canBeSource(unsigned index, const std::vector<std::string>& refLists = std::vector<std::string>()) const;
102
103 /** Returns true if another object points to this object. */
104 bool isTarget() const;
105
106 /** Returns the reference lists of which this object is a member, if this object has a name. */
107 std::vector<std::string> canBeTarget() const;
108
109 /** Checks for equality of objectListFields(). Prerequisite: iddObject()s must be
110 * equal. Looks for object equality of targets if same workspace(), otherwise, looks for data
111 * field equality of targets. */
112 bool objectListFieldsEqual(const WorkspaceObject& other) const;
113
114 /** Returns true if for all objectListFields() that for both objects are non-empty,
115 * the values are equal (using the same criteria as objectListFieldsEqual).
116 * Prerequisite: iddObject()s must be equal. */
117 bool objectListFieldsNonConflicting(const WorkspaceObject& other) const;
118
119 //@}
120 /** @name Serialization */
121 //@{
122
123 /** Returns an equivalent IdfObject, naming target objects if necessary. All data is cloned.
124 * If the objects have handle fields (as in the OpenStudio IDD), pointers to other objects
125 * are printed as handles; otherwise pointers are printed as names. */
126 //DLM@20101010: don't like const overload, just make sure everything is named all the time
127 IdfObject idfObject();
128
129 /** Returns an equivalent IdfObject, leaving unnamed target objects unnamed. All data is cloned.
130 * If the objects have handle fields (as in the OpenStudio IDD), pointers to other objects
131 * are printed as handles; otherwise pointers are printed as names. */
132 //DLM@20101010: don't like const overload, just make sure everything is named all the time
133 IdfObject idfObject() const;
134
135 //@}
136
137 protected:
138 using ImplType = detail::WorkspaceObject_Impl;
139
140 friend class Workspace;
141 friend class detail::Workspace_Impl;
142 friend class IdfObject;
143 friend class detail::IdfObject_Impl;
144 friend class detail::WorkspaceObject_Impl;
145 friend class WorkspaceExtensibleGroup;
146
147 WorkspaceObject(std::shared_ptr<detail::WorkspaceObject_Impl> impl);
148
149 private:
150 std::vector<WorkspaceObject> objects(const std::vector<Handle>& handles, bool sorted) const;
151
152 REGISTER_LOGGER("utilities.idf.WorkspaceObject");
153 };
154
155 /** \relates WorkspaceObject */
156 using OptionalWorkspaceObject = boost::optional<WorkspaceObject>;
157
158 /** \relates WorkspaceObject */
159 using WorkspaceObjectVector = std::vector<WorkspaceObject>;
160
161 /** \relates WorkspaceObject
162 * Outputs WorkspaceObject as (IDF) text. */
163 UTILITIES_API std::ostream& operator<<(std::ostream& os, const WorkspaceObject& workspaceObject);
164
165 } // namespace openstudio
166
167 #endif // UTILITIES_IDF_WORKSPACEOBJECT_HPP
168