GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 23.1% 3 / 0 / 13
Functions: 28.6% 2 / 0 / 7
Branches: -% 0 / 0 / 0

src/utilities/bcl/BCLFileReference.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_BCLFILEREFERENCE_HPP
7 #define UTILITIES_BCL_BCLFILEREFERENCE_HPP
8
9 #include "../core/Logger.hpp"
10 #include "../core/Path.hpp"
11 #include "../UtilitiesAPI.hpp"
12
13 namespace pugi {
14 class xml_node;
15 }
16
17 namespace Json {
18 class Value;
19 }
20
21 namespace openstudio {
22
23 /** BCLFileReference is a class for tracking files that come with BCL components and measures.
24 **/
25 class UTILITIES_API BCLFileReference
26 {
27
28 public:
29 /** @name Constructors */
30 //@{
31
32 /// Constructor from file path.
33 explicit BCLFileReference(const openstudio::path& measureRootDir, const openstudio::path& relativePath, const bool setMembers = false);
34
35 //@}
36 /** @name Destructor */
37 //@{
38
39 /// Virtual destructor
40 6450 virtual ~BCLFileReference() = default;
41
42 //@}
43 /** @name Getters */
44 //@{
45
46 /// Returns absolute path to file.
47 openstudio::path path() const;
48
49 // Returns path to file, relative to measure root directory (including subdirectory, eg 'docs/subfolder/docs.rb')
50 openstudio::path relativePath() const;
51
52 /// Returns the last recorded checksum.
53 std::string checksum() const;
54
55 std::string softwareProgram() const;
56
57 std::string softwareProgramVersion() const;
58
59 boost::optional<VersionString> minCompatibleVersion() const;
60
61 boost::optional<VersionString> maxCompatibleVersion() const;
62
63 // This returns filename to write to the XML. It omits the subdirectory based on usageType
64 // eg: a file at docs/subfolder/docs.rb has a usageType='doc' and filename() = 'subfolder/docs.rb'
65 std::string fileName() const;
66
67 std::string fileType() const;
68
69 std::string usageType() const;
70
71 //@}
72 /** @name Setters */
73 //@{
74
75 void setChecksum(const std::string& checksum);
76
77 void setSoftwareProgram(const std::string& softwareProgram);
78
79 void setSoftwareProgramVersion(const std::string& softwareProgramVersion);
80
81 void setMinCompatibleVersion(const VersionString& minCompatibleVersion);
82
83 void resetMinCompatibleVersion();
84
85 void setMaxCompatibleVersion(const VersionString& maxCompatibleVersion);
86
87 void resetMaxCompatibleVersion();
88
89 void setUsageType(const std::string& usageType);
90
91 //@}
92 /** @name Operators */
93 //@{
94
95 void writeValues(pugi::xml_node& element) const;
96
97 Json::Value toJSON() const;
98 std::string toJSONString() const;
99
100 /// Check if the file has been updated and return if so. Will update checksum.
101 bool checkForUpdate();
102
103 //@}
104
105 protected:
106 // Declaring the equality operator and the spaceship operator (three-way comparison operator) will end up defining all comparison operators
107 // We really need only the operator< for sorting a STL container of BCLFileReference, but might as well be consistent
108 // Comparison is done on m_path. Sorting is useful for BCLXML to avoid reordering of files (see #4748)
109 // TODO: compiler/SWIG support still seems too sparse (need GCC 10+, Apple Clang 13 at least), let's avoid it for now
110 // friend bool operator==(const BCLFileReference& lhs, const BCLFileReference& rhs);
111 // friend std::strong_ordering operator<=>(const BCLFileReference& lhs, const BCLFileReference& rhs);
112 ✗ friend inline bool operator==(const BCLFileReference& lhs, const BCLFileReference& rhs) {
113 ✗ return lhs.m_path == rhs.m_path;
114 }
115 325 friend inline bool operator<(const BCLFileReference& lhs, const BCLFileReference& rhs) {
116 650 return lhs.m_path < rhs.m_path;
117 }
118
119 private:
120 // configure logging
121 REGISTER_LOGGER("utilities.bcl.BCLFileReference");
122
123 openstudio::path m_measureRootDir;
124 openstudio::path m_path;
125 std::string m_checksum;
126 std::string m_softwareProgram;
127 std::string m_softwareProgramVersion;
128 boost::optional<VersionString> m_minCompatibleVersion;
129 boost::optional<VersionString> m_maxCompatibleVersion;
130 std::string m_fileName;
131 std::string m_fileType;
132 std::string m_usageType;
133 };
134
135 /** Prints BCLFileReference to os. \relates BCLFileReference */
136 UTILITIES_API std::ostream& operator<<(std::ostream& os, const BCLFileReference& file);
137
138 ✗ inline bool operator!=(const BCLFileReference& lhs, const BCLFileReference& rhs) {
139 ✗ return !operator==(lhs, rhs);
140 }
141 ✗ inline bool operator>(const BCLFileReference& lhs, const BCLFileReference& rhs) {
142 ✗ return operator<(rhs, lhs);
143 }
144 ✗ inline bool operator<=(const BCLFileReference& lhs, const BCLFileReference& rhs) {
145 ✗ return !operator>(lhs, rhs);
146 }
147 ✗ inline bool operator>=(const BCLFileReference& lhs, const BCLFileReference& rhs) {
148 ✗ return !operator<(lhs, rhs);
149 }
150
151 } // namespace openstudio
152
153 #endif // UTILITIES_BCL_BCLFILEREFERENCE_HPP
154