GCC Code Coverage Report


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

src/utilities/bcl/BCL.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_BCL_BCL_HPP
7 #define UTILITIES_BCL_BCL_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "BCLComponent.hpp"
11 #include "BCLMeasure.hpp"
12 #include "../core/Path.hpp"
13 #include "../core/Logger.hpp"
14 #include "../data/Attribute.hpp"
15 #include "../time/DateTime.hpp"
16
17 namespace pugi {
18 class xml_node;
19 }
20
21 namespace openstudio {
22
23 /// This gives information about items from a BCL facet from a meta search result.
24 /// A facet is an optional search filter which may be applied to narrow down search results.
25 class UTILITIES_API BCLFacet
26 {
27 public:
28 BCLFacet(const pugi::xml_node& facetElement);
29
30 /// Field name of the facet to use during meta searches,
31 /// e.g. 'construction_type'
32 std::string field() const;
33
34 /// Human readable name of the facet,
35 /// e.g. 'Construction Type'
36 std::string label() const;
37
38 /// Possible values for the facet as well as the number of search results after applying each value,
39 /// e.g. [['steel framed', 30], ['metal building', 21], ...]
40 std::vector<std::pair<std::string, unsigned>> items() const;
41
42 private:
43 std::string m_field;
44 std::string m_label;
45 std::vector<std::pair<std::string, unsigned>> m_items;
46 };
47
48 /// This gives information about a taxonomy term from the taxonomy.
49 class UTILITIES_API BCLTaxonomyTerm
50 {
51 public:
52 BCLTaxonomyTerm(const pugi::xml_node& taxonomyElement);
53
54 std::string name() const;
55 unsigned tid() const;
56 unsigned numResults() const;
57
58 private:
59 std::string m_name;
60 unsigned m_tid;
61 unsigned m_numResults;
62 };
63
64 /// This gives information about a single file in a BCL search result.
65 class UTILITIES_API BCLFile
66 {
67 public:
68 BCLFile(const pugi::xml_node& fileElement);
69
70 std::string softwareProgram() const;
71 std::string identifier() const;
72 boost::optional<VersionString> minCompatibleVersion() const;
73 boost::optional<VersionString> maxCompatibleVersion() const;
74 std::string filename() const;
75 std::string url() const;
76 std::string filetype() const;
77 std::string usageType() const;
78 std::string checksum() const;
79
80 private:
81 std::string m_softwareProgram;
82 std::string m_identifier;
83 boost::optional<VersionString> m_minCompatibleVersion;
84 boost::optional<VersionString> m_maxCompatibleVersion;
85 std::string m_filename;
86 std::string m_url;
87 std::string m_filetype;
88 std::string m_usageType;
89 std::string m_checksum;
90 };
91
92 /// This gives information about the provenance of a single file in a BCL search result.
93 class UTILITIES_API BCLProvenance
94 {
95 public:
96 BCLProvenance(const pugi::xml_node& provenanceElement);
97
98 std::string author() const;
99 std::string datetime() const;
100 std::string comment() const;
101
102 private:
103 std::string m_author;
104 std::string m_datetime;
105 std::string m_comment;
106 };
107
108 /// This gives information about a cost in a BCL search result.
109 class UTILITIES_API BCLCost
110 {
111 public:
112 BCLCost(const pugi::xml_node& costElement);
113
114 std::string instanceName() const;
115 std::string costType() const;
116 std::string category() const;
117 double value() const;
118 std::string units() const;
119 std::string interval() const;
120 std::string intervalUnits() const;
121 unsigned year() const;
122 std::string location() const;
123 std::string currency() const;
124 std::string source() const;
125 std::string referenceComponentName() const;
126 std::string referenceComponentId() const;
127
128 private:
129 std::string m_instanceName;
130 std::string m_costType;
131 std::string m_category;
132 double m_value;
133 std::string m_units;
134 std::string m_interval;
135 std::string m_intervalUnits;
136 unsigned m_year;
137 std::string m_location;
138 std::string m_currency;
139 std::string m_source;
140 std::string m_referenceComponentName;
141 std::string m_referenceComponentId;
142 };
143
144 /// This gives information about a meta search result.
145 /// A meta search is used to determine the number and types of results of a search
146 /// before performing a full search.
147 class UTILITIES_API BCLMetaSearchResult
148 {
149 public:
150 BCLMetaSearchResult(const pugi::xml_node& resultElement);
151
152 unsigned numResults() const;
153 std::vector<BCLFacet> facets() const;
154 std::vector<BCLTaxonomyTerm> taxonomyTerms() const;
155
156 private:
157 REGISTER_LOGGER("openstudio.BCLMetaSearchResult");
158
159 unsigned m_numResults;
160 std::vector<BCLFacet> m_facets;
161 std::vector<BCLTaxonomyTerm> m_taxonomyTerms;
162 };
163
164 /// This gives information about an item in a BCL search result.
165 class UTILITIES_API BCLSearchResult
166 {
167 public:
168 BCLSearchResult(const pugi::xml_node& componentElement);
169
170 std::string name() const;
171 std::string uid() const;
172 std::string versionId() const;
173 std::string description() const;
174 std::string modelerDescription() const;
175 std::string fidelityLevel() const;
176 std::string componentType() const;
177 bool provenanceRequired() const;
178 std::vector<BCLProvenance> provenances() const;
179 std::vector<std::string> tags() const;
180 std::vector<Attribute> attributes() const;
181 std::vector<BCLFile> files() const;
182 std::vector<BCLCost> costs() const;
183
184 std::string org() const;
185 std::string repo() const;
186 std::string releaseTag() const;
187 boost::optional<openstudio::DateTime> versionModified() const;
188
189 private:
190 REGISTER_LOGGER("openstudio.BCLSearchResult");
191
192 std::string m_name;
193 std::string m_uid;
194 std::string m_versionId;
195 std::string m_description;
196 std::string m_modelerDescription;
197 std::string m_fidelityLevel;
198 std::string m_componentType;
199 bool m_provenanceRequired = false;
200 std::vector<BCLProvenance> m_provenances;
201 std::vector<std::string> m_tags;
202 std::vector<Attribute> m_attributes;
203 std::vector<BCLFile> m_files;
204 std::vector<BCLCost> m_costs;
205
206 std::string m_org;
207 std::string m_repo;
208 std::string m_releaseTag;
209 boost::optional<openstudio::DateTime> m_versionModified;
210 };
211
212 /// This is a generic interface that can be used for searching either the local or remote bcl.
213 class UTILITIES_API BCL
214 {
215 public:
216 /** @name Constructor */
217 //@{
218
219 //@}
220 /** @name Destructor */
221 //@{
222
223 /// Virtual destructor
224 32 virtual ~BCL() = default;
225
226 //@}
227 /** @name Inherited members */
228 //@{
229
230 // todo: add the following methods to this interface
231 // unsigned resultsPerQuery() const;
232 // bool setResultsPerQuery(const int numResults);
233 // unsigned numResultPages(unsigned numResults) const;
234
235 /// Get the component by uid
236 virtual boost::optional<BCLComponent> getComponent(const std::string& uid, const std::string& versionId = "") const = 0;
237
238 /// Get the measure by uid
239 virtual boost::optional<BCLMeasure> getMeasure(const std::string& uid, const std::string& versionId = "") const = 0;
240
241 //@}
242 private:
243 REGISTER_LOGGER("openstudio.BCL");
244
245 // no body on purpose, do not want this generated
246 BCL(const BCL& other);
247
248 protected:
249 /// Default constructor
250 BCL();
251 };
252
253 /** Uses LocalBCL and RemoteBCL to get a component from the BCL. Will update LocalBCL with the
254 * downloaded component if that is appropriate. Ultimately returns a BCLComponent from the
255 * LocalBCL (existing or just downloaded). */
256 UTILITIES_API boost::optional<BCLComponent> getComponent(const std::string& uid, const std::string& versionId = "");
257
258 /** Uses LocalBCL and RemoteBCL to get a measure from the BCL. Will update LocalBCL with the
259 * downloaded measure if that is appropriate. Ultimately returns a BCLMeasure from the
260 * LocalBCL (existing or just downloaded). */
261 UTILITIES_API boost::optional<BCLMeasure> getMeasure(const std::string& uid, const std::string& versionId = "");
262
263 } // namespace openstudio
264
265 #endif // UTILITIES_BCL_BCL_HPP
266