GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.7% 45 / 0 / 47
Functions: 93.3% 14 / 0 / 15
Branches: 88.2% 30 / 0 / 34

src/utilities/core/UUID.cpp
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 #include "UUID.hpp"
7 #include "String.hpp"
8
9 #include <sstream>
10
11 #include <boost/uuid/uuid_io.hpp>
12 #include <boost/uuid/uuid_generators.hpp>
13 #include <boost/thread/tss.hpp>
14
15 namespace openstudio {
16
17 5797816 UUID::UUID() : boost::uuids::uuid(boost::uuids::nil_uuid()) {}
18
19 2035595 UUID::UUID(const boost::uuids::uuid& t_other) : boost::uuids::uuid(t_other) {}
20
21 879205 UUID UUID::random_generate() {
22
2/2
✓ Branch 0 taken 4026 times.
✓ Branch 1 taken 875179 times.
879205 static thread_local boost::uuids::random_generator gen;
23
2/2
✓ Branch 1 taken 879205 times.
✓ Branch 4 taken 879205 times.
879205 return UUID(gen());
24 }
25
26 1163405 UUID UUID::string_generate(const std::string& t_str) {
27 static thread_local boost::uuids::string_generator gen;
28
2/2
✓ Branch 1 taken 1156390 times.
✓ Branch 4 taken 1156390 times.
1163405 return UUID(gen(t_str));
29 }
30
31 879205 UUID createUUID() {
32 879205 return UUID::random_generate();
33 }
34
35 1163405 UUID toUUID(const std::string& str) {
36 try {
37
1/1
✓ Branch 1 taken 1156390 times.
1163405 return UUID::string_generate(str);
38 7015 } catch (...) {
39
1/1
✓ Branch 1 taken 7015 times.
7015 return {};
40 7015 }
41 }
42
43 // Finds Version 4 uuid in a string including {}
44 665 const boost::regex& uuidInString() {
45
4/7
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 495 times.
✓ Branch 3 taken 170 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 170 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
665 static const boost::regex result("(\\{[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}\\})");
46 665 return result;
47 }
48
49 7026 bool operator!=(const UUID& lhs, const UUID& rhs) {
50 7026 return static_cast<const boost::uuids::uuid&>(lhs) != static_cast<const boost::uuids::uuid&>(rhs);
51 }
52
53 3079037 bool operator<(const UUID& lhs, const UUID& rhs) {
54 3079037 return static_cast<const boost::uuids::uuid&>(lhs) < static_cast<const boost::uuids::uuid&>(rhs);
55 }
56
57 4043212862 bool operator==(const UUID& lhs, const UUID& rhs) {
58 4043212862 return static_cast<const boost::uuids::uuid&>(lhs) == static_cast<const boost::uuids::uuid&>(rhs);
59 }
60
61 ✗ bool operator>(const UUID& lhs, const UUID& rhs) {
62 ✗ return static_cast<const boost::uuids::uuid&>(lhs) > static_cast<const boost::uuids::uuid&>(rhs);
63 }
64
65 3107219 std::string toString(const UUID& uuid) {
66
1/1
✓ Branch 1 taken 3107219 times.
3107219 std::stringstream ss;
67
1/1
✓ Branch 1 taken 3107219 times.
3107219 ss << '{';
68
1/1
✓ Branch 1 taken 3107219 times.
3107219 boost::uuids::operator<<(ss, uuid);
69
1/1
✓ Branch 1 taken 3107219 times.
3107219 ss << '}';
70
1/1
✓ Branch 1 taken 3107219 times.
6214438 return ss.str();
71 3107219 }
72
73 1 std::string createUniqueName(const std::string& prefix) {
74
1/1
✓ Branch 1 taken 1 time.
1 std::stringstream ss;
75
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 if (!prefix.empty()) {
76
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 ss << prefix << " ";
77 }
78
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 ss << toString(createUUID());
79
1/1
✓ Branch 1 taken 1 time.
2 return ss.str();
80 1 }
81
82 78170 std::string removeBraces(const UUID& uuid) {
83
1/1
✓ Branch 1 taken 78170 times.
78170 std::stringstream ss;
84
1/1
✓ Branch 1 taken 78170 times.
78170 boost::uuids::operator<<(ss, uuid);
85
1/1
✓ Branch 1 taken 78170 times.
156340 return ss.str();
86 78170 }
87
88 390328 std::ostream& operator<<(std::ostream& os, const UUID& uuid) {
89
2/2
✓ Branch 1 taken 390328 times.
✓ Branch 4 taken 390328 times.
390328 os << toString(uuid);
90 390328 return os;
91 }
92
93 } // namespace openstudio
94