GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.4% 34 / 0 / 36
Functions: 100.0% 1 / 0 / 1
Branches: 84.5% 87 / 0 / 103

src/radiance/HeaderInfo.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 "HeaderInfo.hpp"
7
8 #include "../utilities/core/Logger.hpp"
9
10 #include <boost/lexical_cast.hpp>
11 #include <boost/regex.hpp>
12 #include <boost/algorithm/string.hpp>
13
14 using namespace std;
15 using namespace boost;
16 using namespace openstudio;
17
18 namespace openstudio {
19 namespace radiance {
20
21 /// header consists of two lines
22
1/1
✓ Branch 2 taken 1 time.
1 HeaderInfo::HeaderInfo(const std::string& line1, const std::string& line2) {
23
24 // this will contain matches to regular expressions
25
1/1
✓ Branch 1 taken 1 time.
2 smatch matches;
26
27 // matches a single number followed by either tabs or spaces
28
1/1
✓ Branch 1 taken 1 time.
1 string singleNumber("([-+]?[0-9]*\\.?[0-9]+)[\\s\\t]*");
29
30 // coordinate system
31
1/1
✓ Branch 1 taken 1 time.
1 Vector origin(3);
32
1/1
✓ Branch 1 taken 1 time.
1 Vector maxX(3);
33
1/1
✓ Branch 1 taken 1 time.
1 Vector maxY(3);
34 1 double xSpacing = 0.0;
35 1 double ySpacing = 0.0;
36 1 double offset = 0.0;
37
38 // first line defines coordinate system for illuminance map
39 // there will be 9 numbers separated by spaces or tabs
40 // first 3 are origin point, second 3 are max x, last 3 are max y
41
1/1
✓ Branch 1 taken 1 time.
1 stringstream coordSystemSS;
42
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 time.
10 for (unsigned i = 0; i < 9; ++i) {
43
1/1
✓ Branch 1 taken 9 times.
9 coordSystemSS << singleNumber;
44 }
45
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 const regex coordSystem(coordSystemSS.str());
46
47
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (regex_search(line1, matches, coordSystem)) {
48
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 origin(0) = lexical_cast<double>(string(matches[1].first, matches[1].second));
49
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 origin(1) = lexical_cast<double>(string(matches[2].first, matches[2].second));
50
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 origin(2) = lexical_cast<double>(string(matches[3].first, matches[3].second));
51
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxX(0) = lexical_cast<double>(string(matches[4].first, matches[4].second));
52
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxX(1) = lexical_cast<double>(string(matches[5].first, matches[5].second));
53
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxX(2) = lexical_cast<double>(string(matches[6].first, matches[6].second));
54
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxY(0) = lexical_cast<double>(string(matches[7].first, matches[7].second));
55
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxY(1) = lexical_cast<double>(string(matches[8].first, matches[8].second));
56
5/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
2 maxY(2) = lexical_cast<double>(string(matches[9].first, matches[9].second));
57 } else {
58 ✗ LOG(Fatal, "No coordinate system defined in line1: '" << line1 << "'");
59 }
60
61 // second line defines offsets and spacing
62
1/1
✓ Branch 1 taken 1 time.
1 stringstream spacingOffsetSS;
63
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
4 for (unsigned i = 0; i < 3; ++i) {
64
1/1
✓ Branch 1 taken 3 times.
3 spacingOffsetSS << singleNumber;
65 }
66
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 const regex spacingOffset(spacingOffsetSS.str());
67
68
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (regex_search(line2, matches, spacingOffset)) {
69
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
2 xSpacing = lexical_cast<double>(string(matches[1].first, matches[1].second));
70
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
2 ySpacing = lexical_cast<double>(string(matches[2].first, matches[2].second));
71
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
2 offset = lexical_cast<double>(string(matches[3].first, matches[3].second));
72 } else {
73 ✗ LOG(Fatal, "No spacing or offsets defined in line2: '" << line2 << "'");
74 }
75
76 // we can now initialize x and y vectors
77 // DLM@20090803: this is not correct for arbitrary grids, revist
78
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 m_xVector = deltaSpace(origin(0) + offset, maxX(0), xSpacing);
79
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 m_yVector = deltaSpace(origin(1) + offset, maxY(1), ySpacing);
80 1 }
81
82 } // namespace radiance
83 } // namespace openstudio
84