GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 50.0% 4 / 0 / 8
Functions: 50.0% 4 / 0 / 8
Branches: 59.1% 13 / 0 / 22

src/utilities/core/FileReference.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_CORE_FILEREFERENCE_HPP
7 #define UTILITIES_CORE_FILEREFERENCE_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "Enum.hpp"
12 #include "Path.hpp"
13 #include "UUID.hpp"
14
15 #include "../time/DateTime.hpp"
16
17 #include <boost/optional.hpp>
18
19 #include <vector>
20
21 namespace openstudio {
22
23 // clang-format off
24
25 /** \class FileReferenceType
26 * \brief Type of files we expect to handle with FileReference.
27 * \details See the OPENSTUDIO_ENUM documentation in utilities/core/Enum.hpp. The actual macro
28 * call is:
29 * \code
30 OPENSTUDIO_ENUM(FileReferenceType,
31 ((Unknown)(unknown))
32 ((CSV)(csv))
33 ((EPW)(epw))
34 ((IDF)(idf))
35 ((OSC)(osc))
36 ((OSM)(osm))
37 ((RB)(rb))
38 ((SQL)(sql))
39 ((XML)(xml))
40 ((OSSR)(ossr))
41 );
42 * \endcode */
43
13/22
openstudio::FileReferenceType::buildStringVec[abi:cxx11](bool):
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 10 times.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✓ Branch 12 taken 10 times.
✓ Branch 17 taken 10 times.
✓ Branch 20 taken 10 times.
✓ Branch 23 taken 18 times.
✓ Branch 24 taken 4 times.
✓ Branch 25 taken 2 times.
✓ Branch 26 taken 2 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 2 times.
openstudio::FileReferenceType::enumName[abi:cxx11]():
✗ Branch 1 not taken.
openstudio::operator<<(std::ostream&, openstudio::FileReferenceType const&):
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
52 OPENSTUDIO_ENUM(FileReferenceType,
44 ((Unknown)(unknown))
45 ((CSV)(csv))
46 ((EPW)(epw))
47 ((IDF)(idf))
48 ((OSC)(osc))
49 ((OSM)(osm))
50 ((RB)(rb))
51 ((SQL)(sql))
52 ((XML)(xml))
53 ((OSSR)(ossr))
54 );
55
56 // clang-format on
57
58 class UTILITIES_API FileReference
59 {
60 public:
61 /** @name Constructors and Destructors */
62 //@{
63
64 explicit FileReference(const openstudio::path& p);
65
66 /** De-serialization constructor. Not for general use. */
67 FileReference(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, const std::string& displayName,
68 const std::string& description, const openstudio::path& p, const FileReferenceType& fileType, const DateTime& timestampLast,
69 const std::string& checksumCreate, const std::string& checksumLast);
70
71 4 virtual ~FileReference() = default;
72
73 FileReference clone() const;
74
75 //@}
76 /** @name Getters */
77 //@{
78
79 openstudio::UUID uuid() const;
80
81 openstudio::UUID versionUUID() const;
82
83 std::string name() const;
84
85 std::string displayName() const;
86
87 std::string description() const;
88
89 openstudio::path path() const;
90
91 FileReferenceType fileType() const;
92
93 /** Last modified time of this file, or time object was created if path
94 * does not actually exist on the file system. */
95 DateTime timestampLast() const;
96
97 /** Checksum at time this object was created, if file exists. Otherwise
98 * "00000000". */
99 std::string checksumCreate() const;
100
101 std::string checksumLast() const;
102
103 //@}
104 /** @name Setters */
105 //@{
106
107 void setName(const std::string& newName);
108
109 void setDisplayName(const std::string& newDisplayName);
110
111 void setDescription(const std::string& newDescription);
112
113 void setPath(const openstudio::path& newPath);
114
115 bool makePathAbsolute(const openstudio::path& searchDirectory);
116
117 /** Save the path as relative to basePath, or just keep the file name and extension if
118 * basePath.empty(). */
119 bool makePathRelative(const openstudio::path& basePath = openstudio::path());
120
121 /** Returns true and updates timestampLast and checksumLast if file is located. */
122 bool update(const openstudio::path& searchDirectory);
123
124 //@}
125 private:
126 openstudio::UUID m_uuid;
127 openstudio::UUID m_versionUUID;
128 std::string m_name;
129 std::string m_displayName;
130 std::string m_description;
131 openstudio::path m_path;
132 FileReferenceType m_fileType;
133 DateTime m_timestampLast;
134 std::string m_checksumCreate;
135 std::string m_checksumLast;
136
137 REGISTER_LOGGER("openstudio.utilities.FileReference");
138 };
139
140 /** \relates FileReference*/
141 using OptionalFileReference = boost::optional<FileReference>;
142
143 /** \relates FileReference*/
144 using FileReferenceVector = std::vector<FileReference>;
145
146 } // namespace openstudio
147
148 #endif // UTILITIES_CORE_FILEREFERENCE_HPP
149