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/IddFile.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_IDDFILE_HPP
7 #define UTILITIES_IDD_IDDFILE_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "IddObject.hpp"
12
13 #include "../core/Logger.hpp"
14 #include "../core/Path.hpp"
15
16 #include <string>
17 #include <ostream>
18 #include <vector>
19
20 namespace openstudio {
21
22 // forward declarations
23 class IddFactory;
24 namespace detail {
25 class IddFile_Impl;
26 } // namespace detail
27
28 class VersionString;
29
30 /** IddFile provides parsing and printing of text files in Input Data Definition (IDD) format.
31 * IDD is a schema definition format defined by the EnergyPlus team, adopted with slight
32 * modifications for the OpenStudio project. IddFile is a shared object. */
33 class UTILITIES_API IddFile
34 {
35 public:
36 /** @name Constructors */
37 //@{
38
39 /** Default constructor returns an IddFile with no version, no header, and no objects. */
40 IddFile();
41
42 /** Copy constructor returns an IddFile that shares its data with other. */
43 // IddFile(const IddFile& other);
44
45 /** Returns an IddFile containing a single, default constructed IddObject of Catchall type. */
46 static IddFile catchallIddFile();
47
48 //@}
49 /** @name Getters */
50 //@{
51
52 /** Returns the file version (as specified in the header). */
53 std::string version() const;
54
55 /** Returns the file build (as specified in the header). */
56 std::string build() const;
57
58 /** Returns the file header. */
59 std::string header() const;
60
61 /** Returns all the objects in the file. */
62 std::vector<IddObject> objects() const;
63
64 /** Returns all groups in the file (e.g. "" and "Simulation Parameters"). */
65 std::vector<std::string> groups() const;
66
67 /** Returns all objects in group (e.g. "Simulation Parameters"). */
68 std::vector<IddObject> getObjectsInGroup(const std::string& group) const;
69
70 /** Returns the objects whose names match objectRegex. */
71 std::vector<IddObject> getObjects(const boost::regex& objectRegex) const;
72
73 /** Returns the version IddObject for this file, if possible. */
74 boost::optional<IddObject> versionObject() const;
75
76 /** Returns the object named objectName (case-insensitive). Return value will evaluate to false
77 * if there is no such object in the IddFile. */
78 boost::optional<IddObject> getObject(const std::string& objectName) const;
79
80 /** Returns the object of type objectType, if possible. Return value will evaluate to false if
81 * there is no such object in the IddFile, or if IddObjectType == IddObjectType::UserCustom. */
82 boost::optional<IddObject> getObject(IddObjectType objectType) const;
83
84 /** Returns all objects in the file that are required. An IdfFile or Workspace conforming to
85 * this IddFile must contain at least one object of each of these types to be valid at
86 * StrictnessLevel::Final. */
87 std::vector<IddObject> requiredObjects() const;
88
89 /** Returns all objects in the file that are marked as unique. An IdfFile or Workspace
90 * conforming to this IddFile must contain at most one object of each of these types to be
91 * valid at StrictnessLevel::Final. */
92 std::vector<IddObject> uniqueObjects() const;
93
94 //@}
95 /** @name Serialization */
96 //@{
97
98 /** Load an IddFile from std::istream, if possible. */
99 static boost::optional<IddFile> load(std::istream& is);
100
101 /** Load an IddFile from path p, if possible. */
102 static boost::optional<IddFile> load(const openstudio::path& p);
103
104 /** Prints this file to std::ostream os. */
105 std::ostream& print(std::ostream& os) const;
106
107 /** Saves file to path p. Will construct the parent folder if necessary and if its parent
108 * folder already exists. Will only overwrite an existing file if overwrite==true. If no
109 * extension is provided will use 'idd'. */
110 // cppcheck-suppress functionConst
111 bool save(const openstudio::path& p, bool overwrite = false);
112
113 /** Returns the version and build SHA from the given Idd. If build SHA is not present .second will be empty.
114 *
115 * \throws an exception with a meaningful error message if something goes wrong
116 */
117 static std::pair<VersionString, std::string> parseVersionBuild(const openstudio::path& p);
118
119 //@}
120 protected:
121 friend class IddFactory;
122
123 /// set version
124 void setVersion(const std::string& version);
125
126 /// set build
127 void setBuild(const std::string& build);
128
129 /// set header
130 void setHeader(const std::string& header);
131
132 /// add an object
133 void addObject(const IddObject& object);
134
135 private:
136 // impl
137 std::shared_ptr<detail::IddFile_Impl> m_impl;
138
139 IddFile(const std::shared_ptr<detail::IddFile_Impl>& impl) noexcept;
140 IddFile(std::shared_ptr<detail::IddFile_Impl>&& impl) noexcept;
141
142 // configure logging
143 − REGISTER_LOGGER("utilities.idd.IddFile");
144 };
145
146 /** \relates IddFile */
147 using OptionalIddFile = boost::optional<IddFile>;
148
149 /** \relates IddFile */
150 using IddFileVector = std::vector<IddFile>;
151
152 /** \relates IddFile */
153 UTILITIES_API std::ostream& operator<<(std::ostream& os, const IddFile& iddFile);
154
155 } // namespace openstudio
156
157 #endif // UTILITIES_IDD_IDDFILE_HPP
158