src/utilities/idd/IddField.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 "IddField.hpp" | ||
| 7 | #include "IddField_Impl.hpp" | ||
| 8 | |||
| 9 | #include "IddRegex.hpp" | ||
| 10 | #include "CommentRegex.hpp" | ||
| 11 | #include <utilities/idd/IddFactory.hxx> | ||
| 12 | |||
| 13 | #include "../units/UnitFactory.hpp" | ||
| 14 | #include "../units/IddUnitString.hpp" | ||
| 15 | #include "../units/QuantityConverter.hpp" | ||
| 16 | #include "../units/SIUnit.hpp" | ||
| 17 | #include "../units/IPUnit.hpp" | ||
| 18 | #include "../units/Quantity.hpp" | ||
| 19 | |||
| 20 | #include "../core/ASCIIStrings.hpp" | ||
| 21 | #include "../core/Assert.hpp" | ||
| 22 | #include "../core/Containers.hpp" | ||
| 23 | |||
| 24 | #include <boost/lexical_cast.hpp> | ||
| 25 | |||
| 26 | using boost::algorithm::trim; | ||
| 27 | |||
| 28 | namespace openstudio { | ||
| 29 | |||
| 30 | namespace detail { | ||
| 31 | |||
| 32 | // CONSTRUCTORS | ||
| 33 | |||
| 34 | /// default constructor for serialization | ||
| 35 | ✗ | IddField_Impl::IddField_Impl() = default; | |
| 36 | |||
| 37 |
2/2✓ Branch 3 taken 13984868 times.
✓ Branch 6 taken 13984868 times.
|
13984868 | IddField_Impl::IddField_Impl(const std::string& name, const std::string& objectName) : m_name(name), m_objectName(objectName) {} |
| 38 | |||
| 39 | // GETTERS | ||
| 40 | |||
| 41 | 18392969 | std::string IddField_Impl::name() const { | |
| 42 | 18392969 | return m_name; | |
| 43 | } | ||
| 44 | |||
| 45 | 3 | std::string IddField_Impl::fieldId() const { | |
| 46 | 3 | return m_fieldId; | |
| 47 | } | ||
| 48 | |||
| 49 | 126561627 | const IddFieldProperties& IddField_Impl::properties() const { | |
| 50 | 126561627 | return m_properties; | |
| 51 | } | ||
| 52 | |||
| 53 | 457 | boost::optional<Unit> IddField_Impl::getUnits(bool returnIP) const { | |
| 54 | 457 | OptionalUnit result; | |
| 55 | |||
| 56 |
3/3✓ Branch 1 taken 457 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 453 times.
|
457 | if (unitsBasedOnOtherField()) { |
| 57 | 4 | return result; | |
| 58 | } | ||
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 243 times.
✓ Branch 1 taken 210 times.
|
453 | if (returnIP) { |
| 61 |
4/4✓ Branch 1 taken 243 times.
✓ Branch 4 taken 243 times.
✓ Branch 6 taken 149 times.
✓ Branch 7 taken 94 times.
|
486 | if (OptionalString units = properties().ipUnits) { |
| 62 |
2/2✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
|
149 | IddUnitString iddUnits(*units); |
| 63 | // let factory determine best system | ||
| 64 |
2/2✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
|
149 | result = createUnit(iddUnits.toStandardUnitString()); |
| 65 |
6/19✓ Branch 1 taken 149 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 149 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 149 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 149 times.
✓ Branch 21 taken 149 times.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 149 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
298 | if (result && !iddUnits.prettyString().empty() && result->prettyString(false).empty()) { |
| 66 | ✗ | result->setPrettyString(iddUnits.prettyString()); | |
| 67 | } | ||
| 68 | 149 | } else { | |
| 69 | // figure out based on SIUnits | ||
| 70 |
1/1✓ Branch 1 taken 94 times.
|
94 | OptionalUnit siUnit = getUnits(false); |
| 71 |
1/2✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
94 | if (siUnit) { |
| 72 | // if default is Celsius, return Fahrenheit | ||
| 73 |
5/5✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 7 taken 94 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 93 times.
|
94 | if (siUnit->system() == UnitSystem::Celsius) { |
| 74 |
7/7✓ 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.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
|
1 | return convert(Quantity(1.0, *siUnit), UnitSystem(UnitSystem::Fahrenheit)).get().units(); |
| 75 | } | ||
| 76 | // if default is not SI, return as-is | ||
| 77 |
5/5✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 79 times.
|
93 | if (siUnit->system() != UnitSystem::SI) { |
| 78 | 14 | return siUnit; | |
| 79 | } | ||
| 80 | // if dimensionless, return IP dimensionless | ||
| 81 |
4/4✓ Branch 1 taken 79 times.
✓ Branch 4 taken 79 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 71 times.
|
79 | if (siUnit->standardString(false).empty()) { |
| 82 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 8 taken 8 times.
|
16 | return IPUnit(); |
| 83 | } | ||
| 84 |
1/1✓ Branch 1 taken 71 times.
|
71 | UnitSystem sys(UnitSystem::IP); |
| 85 | // if pretty string contains W or J, use BTU system | ||
| 86 |
2/2✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
|
71 | std::string tempString = siUnit->prettyString(false); |
| 87 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 40 times.
|
71 | if (!tempString.empty()) { |
| 88 |
1/1✓ Branch 1 taken 31 times.
|
31 | Unit tempUnit = parseUnitString(tempString); |
| 89 |
16/26✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 12 times.
✓ Branch 9 taken 19 times.
✓ Branch 12 taken 19 times.
✓ Branch 14 taken 11 times.
✓ Branch 15 taken 8 times.
✓ Branch 16 taken 19 times.
✓ Branch 17 taken 12 times.
✓ Branch 19 taken 19 times.
✓ Branch 20 taken 12 times.
✓ Branch 21 taken 31 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 31 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 23 times.
✓ Branch 27 taken 8 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
|
131 | if ((tempUnit.baseUnitExponent("W") != 0) || (tempUnit.baseUnitExponent("J") != 0)) { |
| 90 |
1/1✓ Branch 1 taken 23 times.
|
23 | sys = UnitSystem::BTU; |
| 91 | } | ||
| 92 | 31 | } | |
| 93 | // otherwise, if standard string contains m and s, use CFM system | ||
| 94 |
23/31✓ Branch 1 taken 71 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 23 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 13 taken 48 times.
✓ Branch 15 taken 25 times.
✓ Branch 16 taken 23 times.
✓ Branch 18 taken 25 times.
✓ Branch 21 taken 25 times.
✓ Branch 24 taken 25 times.
✓ Branch 26 taken 21 times.
✓ Branch 27 taken 4 times.
✓ Branch 28 taken 25 times.
✓ Branch 29 taken 46 times.
✓ Branch 31 taken 25 times.
✓ Branch 32 taken 46 times.
✓ Branch 33 taken 48 times.
✓ Branch 34 taken 23 times.
✓ Branch 36 taken 48 times.
✓ Branch 37 taken 23 times.
✓ Branch 38 taken 21 times.
✓ Branch 39 taken 50 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
|
217 | if ((sys == UnitSystem::IP) && (siUnit->baseUnitExponent("s") != 0) && (siUnit->baseUnitExponent("m") != 0)) { |
| 95 |
1/1✓ Branch 1 taken 21 times.
|
21 | sys = UnitSystem::CFM; |
| 96 | } | ||
| 97 |
6/6✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
✓ Branch 7 taken 71 times.
✓ Branch 10 taken 71 times.
✓ Branch 13 taken 71 times.
✓ Branch 16 taken 71 times.
|
71 | return convert(Quantity(1.0, *siUnit), sys).get().units(); |
| 98 | 71 | } | |
| 99 | 337 | } | |
| 100 | } else { | ||
| 101 |
3/4✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
✓ Branch 6 taken 210 times.
✗ Branch 7 not taken.
|
420 | if (OptionalString units = properties().units) { |
| 102 |
2/2✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
|
210 | IddUnitString iddUnits(*units); |
| 103 | // even here let factory determine best system (SI already preferred) | ||
| 104 |
2/2✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
|
210 | result = createUnit(iddUnits.toStandardUnitString()); |
| 105 |
13/19✓ Branch 1 taken 210 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 210 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 205 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 3 times.
✓ Branch 18 taken 5 times.
✓ Branch 19 taken 205 times.
✓ Branch 21 taken 210 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 208 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
420 | if (result && !iddUnits.prettyString().empty() && result->prettyString(false).empty()) { |
| 106 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | result->setPrettyString(iddUnits.prettyString()); |
| 107 | } | ||
| 108 |
0/4✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
210 | } else if (properties().type == IddFieldType::RealType) { |
| 109 | // dimensionless by default | ||
| 110 | ✗ | return SIUnit(); | |
| 111 | 210 | } | |
| 112 | } | ||
| 113 | |||
| 114 | 359 | return result; | |
| 115 | 457 | } | |
| 116 | |||
| 117 | 465 | bool IddField_Impl::unitsBasedOnOtherField() const { | |
| 118 |
3/4✓ Branch 1 taken 465 times.
✓ Branch 4 taken 465 times.
✓ Branch 6 taken 465 times.
✗ Branch 7 not taken.
|
930 | if (OptionalString units = properties().units) { |
| 119 |
5/5✓ Branch 1 taken 465 times.
✓ Branch 4 taken 465 times.
✓ Branch 7 taken 465 times.
✓ Branch 10 taken 12 times.
✓ Branch 11 taken 453 times.
|
465 | if (boost::regex_match(*units, boost::regex("BasedOnField A\\d+"))) { |
| 120 | 12 | return true; | |
| 121 | } | ||
| 122 | 465 | } | |
| 123 | 453 | return false; | |
| 124 | } | ||
| 125 | |||
| 126 | 18 | OptionalIddKey IddField_Impl::getKey(const std::string& keyName) const { | |
| 127 | 18 | OptionalIddKey result; | |
| 128 |
1/2✓ Branch 5 taken 43 times.
✗ Branch 6 not taken.
|
43 | for (const IddKey& key : m_keys) { |
| 129 |
4/4✓ Branch 2 taken 43 times.
✓ Branch 5 taken 43 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 25 times.
|
43 | if (boost::iequals(key.name(), keyName)) { |
| 130 |
1/1✓ Branch 1 taken 18 times.
|
18 | result = key; |
| 131 | 18 | break; | |
| 132 | } | ||
| 133 | } | ||
| 134 | 18 | return result; | |
| 135 | ✗ | } | |
| 136 | |||
| 137 | 1444558 | IddKeyVector IddField_Impl::keys() const { | |
| 138 | 1444558 | return m_keys; | |
| 139 | } | ||
| 140 | |||
| 141 | // SETTERS | ||
| 142 | |||
| 143 | 346189 | void IddField_Impl::setName(const std::string& name) { | |
| 144 | 346189 | m_name = name; | |
| 145 | 346189 | } | |
| 146 | |||
| 147 | 4 | void IddField_Impl::incrementFieldId(const boost::regex& fieldType) { | |
| 148 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::regex fieldIdRegex("([AN])([0-9]+)"); |
| 149 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::smatch m; |
| 150 |
1/1✓ Branch 1 taken 4 times.
|
4 | bool ok = boost::regex_match(m_fieldId, m, fieldIdRegex); |
| 151 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
|
4 | OS_ASSERT(ok); |
| 152 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | std::string letterStr(m[1].first, m[1].second); |
| 153 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
|
4 | if (boost::regex_match(letterStr, fieldType)) { |
| 154 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | std::string numberStr(m[2].first, m[2].second); |
| 155 |
1/1✓ Branch 1 taken 1 time.
|
1 | int n = boost::lexical_cast<int>(numberStr); |
| 156 | 1 | ++n; | |
| 157 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | m_fieldId = letterStr + boost::lexical_cast<std::string>(n); |
| 158 | 1 | } | |
| 159 | 4 | } | |
| 160 | |||
| 161 | // QUERIES | ||
| 162 | |||
| 163 | 5735392 | bool IddField_Impl::isNameField() const { | |
| 164 |
3/3✓ Branch 2 taken 320385 times.
✓ Branch 5 taken 27 times.
✓ Branch 6 taken 320358 times.
|
6055777 | return (((!properties().references.empty()) && (properties().objectLists.empty())) |
| 165 |
19/23✓ Branch 1 taken 5735392 times.
✓ Branch 3 taken 320385 times.
✓ Branch 4 taken 5415007 times.
✓ Branch 7 taken 5415034 times.
✓ Branch 10 taken 5415034 times.
✓ Branch 12 taken 29467 times.
✓ Branch 13 taken 5385567 times.
✓ Branch 15 taken 29467 times.
✓ Branch 18 taken 29467 times.
✓ Branch 21 taken 2530 times.
✓ Branch 22 taken 26937 times.
✓ Branch 24 taken 2530 times.
✓ Branch 27 taken 2530 times.
✓ Branch 30 taken 2492 times.
✓ Branch 31 taken 38 times.
✓ Branch 32 taken 5415034 times.
✓ Branch 33 taken 320358 times.
✓ Branch 35 taken 5415034 times.
✓ Branch 36 taken 320358 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
|
11791169 | || (boost::iequals("Name", name()) && ((properties().type == IddFieldType::AlphaType) || (properties().type == IddFieldType::NodeType)))); |
| 166 | } | ||
| 167 | |||
| 168 | 25933372 | bool IddField_Impl::isObjectListField() const { | |
| 169 |
8/9✓ Branch 1 taken 25933372 times.
✓ Branch 4 taken 25933372 times.
✓ Branch 7 taken 1917454 times.
✓ Branch 8 taken 24015918 times.
✓ Branch 10 taken 1917454 times.
✓ Branch 13 taken 1917454 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1917454 times.
✓ Branch 16 taken 24015918 times.
|
25933372 | if ((properties().type == IddFieldType::ObjectListType) && (!properties().objectLists.empty())) { |
| 170 | 1917454 | return true; | |
| 171 | } | ||
| 172 | 24015918 | return false; | |
| 173 | } | ||
| 174 | |||
| 175 | 390 | bool IddField_Impl::operator==(const IddField_Impl& other) const { | |
| 176 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 389 times.
|
390 | if (this == &other) { |
| 177 | 1 | return true; | |
| 178 | } | ||
| 179 | |||
| 180 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 388 times.
|
389 | if (m_name != other.m_name) { |
| 181 | 1 | return false; | |
| 182 | } | ||
| 183 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (m_fieldId != other.m_fieldId) { |
| 184 | ✗ | return false; | |
| 185 | } | ||
| 186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (m_objectName != other.m_objectName) { |
| 187 | ✗ | return false; | |
| 188 | } | ||
| 189 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (m_properties != other.m_properties) { |
| 190 | ✗ | return false; | |
| 191 | } | ||
| 192 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (m_keys != other.m_keys) { |
| 193 | ✗ | return false; | |
| 194 | } | ||
| 195 | |||
| 196 | 388 | return true; | |
| 197 | } | ||
| 198 | |||
| 199 | 1 | bool IddField_Impl::operator!=(const IddField_Impl& other) const { | |
| 200 | 1 | return !(*this == other); | |
| 201 | } | ||
| 202 | |||
| 203 | // SERIALIZATION | ||
| 204 | |||
| 205 | 13984868 | std::shared_ptr<IddField_Impl> IddField_Impl::load(const std::string& name, const std::string& text, const std::string& objectName) { | |
| 206 | |||
| 207 | 13984868 | std::shared_ptr<IddField_Impl> result; | |
| 208 |
1/1✓ Branch 1 taken 13984868 times.
|
13984868 | IddField_Impl iddFieldImpl(name, objectName); |
| 209 | |||
| 210 | try { | ||
| 211 |
1/1✓ Branch 1 taken 13984868 times.
|
13984868 | iddFieldImpl.parse(text); |
| 212 | ✗ | } catch (...) { | |
| 213 | ✗ | return result; | |
| 214 | ✗ | } | |
| 215 | |||
| 216 |
3/5✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✓ Branch 7 taken 13984868 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
13984868 | result = std::shared_ptr<IddField_Impl>(new IddField_Impl(iddFieldImpl)); |
| 217 | 13984868 | return result; | |
| 218 | 13984868 | } | |
| 219 | |||
| 220 | 737462 | std::ostream& IddField_Impl::print(std::ostream& os, bool lastField) const { | |
| 221 |
8/12✓ Branch 0 taken 57482 times.
✓ Branch 1 taken 679980 times.
✓ Branch 3 taken 57482 times.
✓ Branch 6 taken 679980 times.
✓ Branch 8 taken 679980 times.
✓ Branch 9 taken 57482 times.
✓ Branch 10 taken 57482 times.
✓ Branch 11 taken 679980 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
2154904 | std::string separator = (lastField ? std::string(";") : std::string(",")); |
| 222 | |||
| 223 |
3/3✓ Branch 1 taken 737462 times.
✓ Branch 4 taken 737462 times.
✓ Branch 7 taken 737462 times.
|
737462 | os << " " << m_fieldId << separator; |
| 224 | |||
| 225 |
2/2✓ Branch 1 taken 737229 times.
✓ Branch 2 taken 233 times.
|
737462 | if (m_name != m_fieldId) { |
| 226 |
2/2✓ Branch 1 taken 737229 times.
✓ Branch 4 taken 737229 times.
|
737229 | os << " \\field " << m_name; |
| 227 | } | ||
| 228 | |||
| 229 |
1/1✓ Branch 1 taken 737462 times.
|
737462 | os << '\n'; |
| 230 | |||
| 231 |
1/1✓ Branch 1 taken 737462 times.
|
737462 | m_properties.print(os); |
| 232 | |||
| 233 |
2/2✓ Branch 5 taken 346368 times.
✓ Branch 6 taken 737462 times.
|
1083830 | for (const auto& key : m_keys) { |
| 234 |
1/1✓ Branch 1 taken 346368 times.
|
346368 | key.print(os); |
| 235 | } | ||
| 236 | |||
| 237 | 737462 | return os; | |
| 238 | 737462 | } | |
| 239 | |||
| 240 | 13984868 | void IddField_Impl::parse(const std::string& text) { | |
| 241 |
1/1✓ Branch 1 taken 13984868 times.
|
13984868 | boost::smatch matches; |
| 242 |
3/4✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✓ Branch 6 taken 13984868 times.
✗ Branch 7 not taken.
|
13984868 | if (boost::regex_search(text, matches, iddRegex::field())) { |
| 243 | // find and parse the field text | ||
| 244 |
3/3✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✓ Branch 7 taken 13984868 times.
|
27969736 | std::string fieldTypeChar(matches[1].first, matches[1].second); |
| 245 |
3/3✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✓ Branch 7 taken 13984868 times.
|
27969736 | std::string fieldTypeNumber(matches[2].first, matches[2].second); |
| 246 |
3/3✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✓ Branch 7 taken 13984868 times.
|
13984868 | std::string fieldProperties(matches[3].first, matches[3].second); |
| 247 | |||
| 248 | // keep track of field id | ||
| 249 |
1/1✓ Branch 1 taken 13984868 times.
|
13984868 | m_fieldId = fieldTypeChar + fieldTypeNumber; |
| 250 | |||
| 251 | // check for base content type | ||
| 252 |
3/3✓ Branch 2 taken 13984868 times.
✓ Branch 5 taken 7720937 times.
✓ Branch 6 taken 6263931 times.
|
13984868 | if (boost::iequals(fieldTypeChar, "A")) { |
| 253 |
1/1✓ Branch 1 taken 7720937 times.
|
7720937 | m_properties.type = IddFieldType(IddFieldType::AlphaType); |
| 254 |
2/3✓ Branch 2 taken 6263931 times.
✓ Branch 5 taken 6263931 times.
✗ Branch 6 not taken.
|
6263931 | } else if (boost::iequals(fieldTypeChar, "N")) { |
| 255 | // default numerics to real, can be overwritten later | ||
| 256 |
1/1✓ Branch 1 taken 6263931 times.
|
6263931 | m_properties.type = IddFieldType(IddFieldType::RealType); |
| 257 | } else { | ||
| 258 | ✗ | LOG_AND_THROW("Unknown field type identifier found: '" << fieldTypeChar << "'"); | |
| 259 | } | ||
| 260 | |||
| 261 | // parse all the properties | ||
| 262 |
4/4✓ Branch 1 taken 86879126 times.
✓ Branch 4 taken 86879126 times.
✓ Branch 6 taken 72894258 times.
✓ Branch 7 taken 13984868 times.
|
86879126 | while (boost::regex_search(fieldProperties, matches, iddRegex::metaDataComment())) { |
| 263 |
3/3✓ Branch 1 taken 72894258 times.
✓ Branch 4 taken 72894258 times.
✓ Branch 7 taken 72894258 times.
|
72894258 | std::string thisProperty(matches[1].first, matches[1].second); |
| 264 |
1/1✓ Branch 1 taken 72894258 times.
|
72894258 | openstudio::ascii_trim(thisProperty); |
| 265 |
1/1✓ Branch 1 taken 72894258 times.
|
72894258 | parseProperty(thisProperty); |
| 266 | |||
| 267 |
3/3✓ Branch 1 taken 72894258 times.
✓ Branch 4 taken 72894258 times.
✓ Branch 7 taken 72894258 times.
|
72894258 | fieldProperties = std::string(matches[2].first, matches[2].second); |
| 268 |
1/1✓ Branch 1 taken 72894258 times.
|
72894258 | openstudio::ascii_trim(fieldProperties); |
| 269 | 72894258 | } | |
| 270 | |||
| 271 |
4/6✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13984868 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 13984868 times.
|
13984868 | if (!((boost::regex_match(fieldProperties, commentRegex::whitespaceOnlyBlock())) |
| 272 | ✗ | || (boost::regex_match(fieldProperties, iddRegex::commentOnlyLine())))) { | |
| 273 | ✗ | LOG_AND_THROW("Unable to parse remaining fields: '" << fieldProperties << "'"); | |
| 274 | } | ||
| 275 | 13984868 | } else { | |
| 276 | ✗ | LOG_AND_THROW("Field text does not match expected pattern: '" << text << "'"); | |
| 277 | } | ||
| 278 | |||
| 279 |
3/3✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 1539144 times.
✓ Branch 5 taken 12445724 times.
|
13984868 | if (m_properties.type == IddFieldType::ChoiceType) { |
| 280 | // if this is a choice, assert we have some keys | ||
| 281 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1539144 times.
|
1539144 | if (m_keys.empty()) { |
| 282 | ✗ | LOG(Error, "Field is of type choice but keys are empty: '" << m_name << "'"); | |
| 283 | } | ||
| 284 | } else { | ||
| 285 | // else assert we have no keys | ||
| 286 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12445724 times.
|
12445724 | if (!m_keys.empty()) { |
| 287 | ✗ | LOG(Error, "Field is not of type choice but has non-empty keys: '" << m_name << "'"); | |
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 |
2/3✓ Branch 1 taken 13984868 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13984868 times.
|
13984868 | if (m_properties.type == IddFieldType::UnknownType) { |
| 292 | |||
| 293 | ✗ | LOG_AND_THROW("Field is of unknown type after parsing: '" << m_name << "'"); | |
| 294 | } | ||
| 295 | |||
| 296 | // If the field has a default then it is not required. This overrides the idd text. | ||
| 297 |
2/2✓ Branch 1 taken 2816170 times.
✓ Branch 2 taken 11168698 times.
|
27969736 | if (m_properties.stringDefault) { |
| 298 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 2816090 times.
|
2816170 | if (m_properties.required) { |
| 299 |
9/9✓ Branch 1 taken 80 times.
✓ Branch 4 taken 80 times.
✓ Branch 7 taken 80 times.
✓ Branch 10 taken 80 times.
✓ Branch 13 taken 80 times.
✓ Branch 16 taken 80 times.
✓ Branch 19 taken 80 times.
✓ Branch 22 taken 80 times.
✓ Branch 25 taken 80 times.
|
80 | LOG(Info, "Field '" << m_name << "' of object '" << m_objectName << "' is both required and has default value, setting required = false."); |
| 300 | 80 | m_properties.required = false; | |
| 301 | } | ||
| 302 | } | ||
| 303 | 13984868 | } | |
| 304 | |||
| 305 | 72894258 | void IddField_Impl::parseProperty(const std::string& text) { | |
| 306 | // this function is called very often and has been identified as a bottleneck | ||
| 307 | // that is why some of the optimizations below have been applied | ||
| 308 | |||
| 309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 72894258 times.
|
72894258 | if (text.empty()) { |
| 310 | ✗ | return; | |
| 311 | } | ||
| 312 | |||
| 313 | 72894258 | bool notHandled = true; | |
| 314 |
1/1✓ Branch 1 taken 72894258 times.
|
72894258 | boost::smatch matches; |
| 315 | |||
| 316 |
1/1✓ Branch 2 taken 72894258 times.
|
72894258 | std::string lowerText = openstudio::ascii_to_lower_copy(text); |
| 317 | |||
| 318 | 72894258 | const char index = lowerText[0]; | |
| 319 | |||
| 320 | //sort inside the case statements based on the probability of that value being in the string.(so we don't run 5 unlikely | ||
| 321 | //regex tofind the likely one) Keep the case statements in aphabitical order for ease of maintance, since it doesn't | ||
| 322 | //effect the speed | ||
| 323 |
13/14✓ Branch 0 taken 814705 times.
✓ Branch 1 taken 394026 times.
✓ Branch 2 taken 2819730 times.
✓ Branch 3 taken 2742 times.
✓ Branch 4 taken 13973218 times.
✓ Branch 5 taken 673672 times.
✓ Branch 6 taken 6636895 times.
✓ Branch 7 taken 5305370 times.
✓ Branch 8 taken 12771030 times.
✓ Branch 9 taken 3535505 times.
✓ Branch 10 taken 8751262 times.
✓ Branch 11 taken 13123591 times.
✓ Branch 12 taken 4092512 times.
✗ Branch 13 not taken.
|
72894258 | switch (index) { |
| 324 | |||
| 325 | 814705 | case 'a': { | |
| 326 |
3/3✓ Branch 1 taken 814705 times.
✓ Branch 3 taken 740554 times.
✓ Branch 4 taken 74151 times.
|
814705 | if (boost::algorithm::starts_with(lowerText, "autosizable")) { |
| 327 | 740554 | m_properties.autosizable = true; | |
| 328 | 740554 | notHandled = false; | |
| 329 |
2/3✓ Branch 1 taken 74151 times.
✓ Branch 3 taken 74151 times.
✗ Branch 4 not taken.
|
74151 | } else if (boost::algorithm::starts_with(lowerText, "autocalculatable")) { |
| 330 | 74151 | m_properties.autocalculatable = true; | |
| 331 | 74151 | notHandled = false; | |
| 332 | } | ||
| 333 | 814705 | break; | |
| 334 | } | ||
| 335 | 394026 | case 'b': { | |
| 336 |
2/3✓ Branch 1 taken 394026 times.
✓ Branch 3 taken 394026 times.
✗ Branch 4 not taken.
|
394026 | if (boost::algorithm::starts_with(lowerText, "begin-extensible")) { |
| 337 | 394026 | m_properties.beginExtensible = true; | |
| 338 | 394026 | notHandled = false; | |
| 339 | } | ||
| 340 | 394026 | break; | |
| 341 | } | ||
| 342 | |||
| 343 | 2819730 | case 'd': { | |
| 344 |
3/3✓ Branch 1 taken 2819730 times.
✓ Branch 3 taken 2816436 times.
✓ Branch 4 taken 3294 times.
|
2819730 | if (boost::algorithm::starts_with(lowerText, "default")) { |
| 345 |
3/5✓ Branch 1 taken 2816436 times.
✓ Branch 4 taken 2816436 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2816436 times.
✗ Branch 9 not taken.
|
2816436 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::defaultProperty())); |
| 346 |
3/3✓ Branch 1 taken 2816436 times.
✓ Branch 4 taken 2816436 times.
✓ Branch 7 taken 2816436 times.
|
2816436 | std::string stringDefault(matches[1].first, matches[1].second); |
| 347 |
1/1✓ Branch 1 taken 2816436 times.
|
2816436 | openstudio::ascii_trim(stringDefault); |
| 348 |
1/1✓ Branch 1 taken 2816436 times.
|
2816436 | m_properties.stringDefault = stringDefault; |
| 349 | 2816436 | notHandled = false; | |
| 350 | // if we are numeric type and not set to autosize, set the numeric property | ||
| 351 |
8/8✓ Branch 1 taken 2816436 times.
✓ Branch 4 taken 1008518 times.
✓ Branch 5 taken 1807918 times.
✓ Branch 7 taken 1008518 times.
✓ Branch 10 taken 124330 times.
✓ Branch 11 taken 884188 times.
✓ Branch 12 taken 1932248 times.
✓ Branch 13 taken 884188 times.
|
2816436 | if ((m_properties.type == IddFieldType::RealType) || (m_properties.type == IddFieldType::IntegerType)) { |
| 352 |
4/4✓ Branch 1 taken 1932248 times.
✓ Branch 4 taken 1932248 times.
✓ Branch 6 taken 1771129 times.
✓ Branch 7 taken 161119 times.
|
1932248 | if (!boost::regex_match(text, iddRegex::automaticDefault())) { |
| 353 |
2/2✓ Branch 1 taken 1771129 times.
✓ Branch 4 taken 1771129 times.
|
1771129 | m_properties.numericDefault = boost::lexical_cast<double>(stringDefault); |
| 354 | } else { | ||
| 355 | // otherwise this is -9999 | ||
| 356 |
1/1✓ Branch 1 taken 161119 times.
|
161119 | m_properties.numericDefault = -9999; |
| 357 | } | ||
| 358 | } | ||
| 359 |
2/3✓ Branch 2 taken 3294 times.
✓ Branch 4 taken 3294 times.
✗ Branch 5 not taken.
|
2819730 | } else if (boost::algorithm::starts_with(lowerText, "deprecated")) { |
| 360 | 3294 | m_properties.deprecated = true; | |
| 361 | 3294 | notHandled = false; | |
| 362 | } | ||
| 363 | 2819730 | break; | |
| 364 | } | ||
| 365 | 2742 | case 'e': { | |
| 366 |
2/3✓ Branch 1 taken 2742 times.
✓ Branch 3 taken 2742 times.
✗ Branch 4 not taken.
|
2742 | if (boost::algorithm::starts_with(lowerText, "external-list")) { |
| 367 |
3/5✓ Branch 1 taken 2742 times.
✓ Branch 4 taken 2742 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2742 times.
✗ Branch 9 not taken.
|
2742 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::externalListProperty())); |
| 368 |
3/3✓ Branch 1 taken 2742 times.
✓ Branch 4 taken 2742 times.
✓ Branch 7 taken 2742 times.
|
2742 | std::string externalList(matches[1].first, matches[1].second); |
| 369 |
1/1✓ Branch 1 taken 2742 times.
|
2742 | openstudio::ascii_trim(externalList); |
| 370 |
1/1✓ Branch 1 taken 2742 times.
|
2742 | m_properties.externalLists.push_back(externalList); |
| 371 | 2742 | notHandled = false; | |
| 372 | 2742 | } | |
| 373 | |||
| 374 | 2742 | break; | |
| 375 | } | ||
| 376 | 13973218 | case 'f': { | |
| 377 |
2/3✓ Branch 1 taken 13973218 times.
✓ Branch 3 taken 13973218 times.
✗ Branch 4 not taken.
|
13973218 | if (boost::algorithm::starts_with(lowerText, "field")) { |
| 378 |
3/5✓ Branch 1 taken 13973218 times.
✓ Branch 4 taken 13973218 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13973218 times.
✗ Branch 9 not taken.
|
13973218 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::nameProperty())); |
| 379 |
3/3✓ Branch 1 taken 13973218 times.
✓ Branch 4 taken 13973218 times.
✓ Branch 7 taken 13973218 times.
|
13973218 | std::string fieldName(matches[1].first, matches[1].second); |
| 380 |
1/1✓ Branch 1 taken 13973218 times.
|
13973218 | openstudio::ascii_trim(fieldName); |
| 381 | 13973218 | notHandled = false; | |
| 382 |
2/3✓ Branch 1 taken 13973218 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13973218 times.
|
13973218 | if (!boost::equals(m_name, fieldName)) { |
| 383 | ✗ | LOG_AND_THROW("Field name '" << fieldName << "' does not match expected '" << m_name << "' in object '" << m_objectName << "'"); | |
| 384 | } | ||
| 385 | 13973218 | } | |
| 386 | 13973218 | break; | |
| 387 | } | ||
| 388 | 673672 | case 'i': { | |
| 389 |
2/3✓ Branch 1 taken 673672 times.
✓ Branch 3 taken 673672 times.
✗ Branch 4 not taken.
|
673672 | if (boost::algorithm::starts_with(lowerText, "ip-units")) { |
| 390 |
3/5✓ Branch 1 taken 673672 times.
✓ Branch 4 taken 673672 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 673672 times.
✗ Branch 9 not taken.
|
673672 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::ipUnitsProperty())); |
| 391 |
3/3✓ Branch 1 taken 673672 times.
✓ Branch 4 taken 673672 times.
✓ Branch 7 taken 673672 times.
|
673672 | std::string ipUnits(matches[1].first, matches[1].second); |
| 392 |
1/1✓ Branch 1 taken 673672 times.
|
673672 | openstudio::ascii_trim(ipUnits); |
| 393 |
1/1✓ Branch 1 taken 673672 times.
|
673672 | m_properties.ipUnits = ipUnits; |
| 394 | 673672 | notHandled = false; | |
| 395 | 673672 | } | |
| 396 | 673672 | break; | |
| 397 | } | ||
| 398 | |||
| 399 | 6636895 | case 'k': { | |
| 400 |
2/3✓ Branch 1 taken 6636895 times.
✓ Branch 3 taken 6636895 times.
✗ Branch 4 not taken.
|
6636895 | if (boost::algorithm::starts_with(lowerText, "key")) { |
| 401 |
3/5✓ Branch 1 taken 6636895 times.
✓ Branch 4 taken 6636895 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6636895 times.
✗ Branch 9 not taken.
|
6636895 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::keyProperty())); |
| 402 |
3/3✓ Branch 1 taken 6636895 times.
✓ Branch 4 taken 6636895 times.
✓ Branch 7 taken 6636895 times.
|
6636895 | std::string keyText(matches[1].first, matches[1].second); |
| 403 | 6636895 | notHandled = false; | |
| 404 |
1/1✓ Branch 1 taken 6636895 times.
|
6636895 | boost::smatch keyMatches; |
| 405 |
3/4✓ Branch 1 taken 6636895 times.
✓ Branch 4 taken 6636895 times.
✓ Branch 6 taken 6636895 times.
✗ Branch 7 not taken.
|
6636895 | if (boost::regex_search(keyText, keyMatches, iddRegex::contentAndCommentLine())) { |
| 406 |
3/3✓ Branch 1 taken 6636895 times.
✓ Branch 4 taken 6636895 times.
✓ Branch 7 taken 6636895 times.
|
6636895 | std::string keyName(keyMatches[1].first, keyMatches[1].second); |
| 407 |
1/1✓ Branch 1 taken 6636895 times.
|
6636895 | openstudio::ascii_trim(keyName); |
| 408 | |||
| 409 | // construct the key | ||
| 410 |
1/1✓ Branch 1 taken 6636895 times.
|
6636895 | OptionalIddKey key = IddKey::load(keyName, keyText); |
| 411 | |||
| 412 | // add the key to the keys | ||
| 413 |
1/2✓ Branch 0 taken 6636895 times.
✗ Branch 1 not taken.
|
6636895 | if (key) { |
| 414 |
2/2✓ Branch 1 taken 6636895 times.
✓ Branch 4 taken 6636895 times.
|
6636895 | m_keys.push_back(*key); |
| 415 | } else { | ||
| 416 | ✗ | LOG_AND_THROW("Key could not be loaded from text '" << keyText << "'."); | |
| 417 | } | ||
| 418 | |||
| 419 | 6636895 | } else { | |
| 420 | ✗ | LOG_AND_THROW("Key name could not be determined from text '" << keyText << "'."); | |
| 421 | } | ||
| 422 | 6636895 | } | |
| 423 | 6636895 | break; | |
| 424 | } | ||
| 425 | 5305370 | case 'm': { | |
| 426 |
3/3✓ Branch 1 taken 5305370 times.
✓ Branch 3 taken 3898889 times.
✓ Branch 4 taken 1406481 times.
|
5305370 | if (boost::algorithm::starts_with(lowerText, "minimum")) { |
| 427 |
4/4✓ Branch 1 taken 3898889 times.
✓ Branch 4 taken 3898889 times.
✓ Branch 6 taken 1436061 times.
✓ Branch 7 taken 2462828 times.
|
3898889 | if (boost::regex_search(text, matches, iddRegex::minExclusiveProperty())) { |
| 428 | 1436061 | m_properties.minBoundType = IddFieldProperties::ExclusiveBound; | |
| 429 |
3/3✓ Branch 1 taken 1436061 times.
✓ Branch 4 taken 1436061 times.
✓ Branch 7 taken 1436061 times.
|
1436061 | std::string minExclusive(matches[1].first, matches[1].second); |
| 430 |
1/1✓ Branch 1 taken 1436061 times.
|
1436061 | openstudio::ascii_trim(minExclusive); |
| 431 |
2/2✓ Branch 1 taken 1436061 times.
✓ Branch 4 taken 1436061 times.
|
1436061 | m_properties.minBoundValue = boost::lexical_cast<double>(minExclusive); |
| 432 |
1/1✓ Branch 1 taken 1436061 times.
|
1436061 | m_properties.minBoundText = minExclusive; |
| 433 | 1436061 | notHandled = false; | |
| 434 |
3/4✓ Branch 2 taken 2462828 times.
✓ Branch 5 taken 2462828 times.
✓ Branch 7 taken 2462828 times.
✗ Branch 8 not taken.
|
3898889 | } else if (boost::regex_search(text, matches, iddRegex::minInclusiveProperty())) { |
| 435 | 2462828 | m_properties.minBoundType = IddFieldProperties::InclusiveBound; | |
| 436 |
3/3✓ Branch 1 taken 2462828 times.
✓ Branch 4 taken 2462828 times.
✓ Branch 7 taken 2462828 times.
|
2462828 | std::string minInclusive(matches[1].first, matches[1].second); |
| 437 |
1/1✓ Branch 1 taken 2462828 times.
|
2462828 | openstudio::ascii_trim(minInclusive); |
| 438 |
2/2✓ Branch 1 taken 2462828 times.
✓ Branch 4 taken 2462828 times.
|
2462828 | m_properties.minBoundValue = boost::lexical_cast<double>(minInclusive); |
| 439 |
1/1✓ Branch 1 taken 2462828 times.
|
2462828 | m_properties.minBoundText = minInclusive; |
| 440 | 2462828 | notHandled = false; | |
| 441 | 2462828 | } | |
| 442 |
3/3✓ Branch 1 taken 1406481 times.
✓ Branch 3 taken 1375081 times.
✓ Branch 4 taken 31400 times.
|
1406481 | } else if (boost::algorithm::starts_with(lowerText, "maximum")) { |
| 443 |
4/4✓ Branch 1 taken 1375081 times.
✓ Branch 4 taken 1375081 times.
✓ Branch 6 taken 149150 times.
✓ Branch 7 taken 1225931 times.
|
1375081 | if (boost::regex_search(text, matches, iddRegex::maxExclusiveProperty())) { |
| 444 | 149150 | m_properties.maxBoundType = IddFieldProperties::ExclusiveBound; | |
| 445 |
3/3✓ Branch 1 taken 149150 times.
✓ Branch 4 taken 149150 times.
✓ Branch 7 taken 149150 times.
|
149150 | std::string maxExclusive(matches[1].first, matches[1].second); |
| 446 |
1/1✓ Branch 1 taken 149150 times.
|
149150 | openstudio::ascii_trim(maxExclusive); |
| 447 |
2/2✓ Branch 1 taken 149150 times.
✓ Branch 4 taken 149150 times.
|
149150 | m_properties.maxBoundValue = boost::lexical_cast<double>(maxExclusive); |
| 448 |
1/1✓ Branch 1 taken 149150 times.
|
149150 | m_properties.maxBoundText = maxExclusive; |
| 449 | 149150 | notHandled = false; | |
| 450 |
3/4✓ Branch 2 taken 1225931 times.
✓ Branch 5 taken 1225931 times.
✓ Branch 7 taken 1225931 times.
✗ Branch 8 not taken.
|
1375081 | } else if (boost::regex_search(text, matches, iddRegex::maxInclusiveProperty())) { |
| 451 | 1225931 | m_properties.maxBoundType = IddFieldProperties::InclusiveBound; | |
| 452 |
3/3✓ Branch 1 taken 1225931 times.
✓ Branch 4 taken 1225931 times.
✓ Branch 7 taken 1225931 times.
|
1225931 | std::string maxInclusive(matches[1].first, matches[1].second); |
| 453 |
1/1✓ Branch 1 taken 1225931 times.
|
1225931 | openstudio::ascii_trim(maxInclusive); |
| 454 |
2/2✓ Branch 1 taken 1225931 times.
✓ Branch 4 taken 1225931 times.
|
1225931 | m_properties.maxBoundValue = boost::lexical_cast<double>(maxInclusive); |
| 455 |
1/1✓ Branch 1 taken 1225931 times.
|
1225931 | m_properties.maxBoundText = maxInclusive; |
| 456 | 1225931 | notHandled = false; | |
| 457 | 1225931 | } | |
| 458 |
2/3✓ Branch 1 taken 31400 times.
✓ Branch 3 taken 31400 times.
✗ Branch 4 not taken.
|
31400 | } else if (boost::algorithm::starts_with(lowerText, "memo")) { |
| 459 | 31400 | notHandled = false; | |
| 460 |
3/5✓ Branch 1 taken 31400 times.
✓ Branch 4 taken 31400 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 31400 times.
✗ Branch 9 not taken.
|
31400 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::memoProperty())); |
| 461 |
3/3✓ Branch 1 taken 31400 times.
✓ Branch 4 taken 31400 times.
✓ Branch 7 taken 31400 times.
|
31400 | std::string memo(matches[1].first, matches[1].second); |
| 462 |
1/1✓ Branch 2 taken 31400 times.
|
31400 | trim(memo); |
| 463 |
2/2✓ Branch 1 taken 7368 times.
✓ Branch 2 taken 24032 times.
|
31400 | if (m_properties.note.empty()) { |
| 464 |
1/1✓ Branch 1 taken 7368 times.
|
7368 | m_properties.note = memo; |
| 465 | } else { | ||
| 466 |
2/2✓ Branch 1 taken 24032 times.
✓ Branch 4 taken 24032 times.
|
24032 | m_properties.note += "\n" + memo; |
| 467 | } | ||
| 468 | 31400 | } | |
| 469 | 5305370 | break; | |
| 470 | } | ||
| 471 | 12771030 | case 'n': { | |
| 472 |
2/3✓ Branch 1 taken 12771030 times.
✓ Branch 3 taken 12771030 times.
✗ Branch 4 not taken.
|
12771030 | if (boost::algorithm::starts_with(lowerText, "note")) { |
| 473 | 12771030 | notHandled = false; | |
| 474 |
3/5✓ Branch 1 taken 12771030 times.
✓ Branch 4 taken 12771030 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12771030 times.
✗ Branch 9 not taken.
|
12771030 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::noteProperty())); |
| 475 |
3/3✓ Branch 1 taken 12771030 times.
✓ Branch 4 taken 12771030 times.
✓ Branch 7 taken 12771030 times.
|
12771030 | std::string note(matches[1].first, matches[1].second); |
| 476 |
1/1✓ Branch 2 taken 12771030 times.
|
12771030 | trim(note); |
| 477 |
2/2✓ Branch 1 taken 5342500 times.
✓ Branch 2 taken 7428530 times.
|
12771030 | if (m_properties.note.empty()) { |
| 478 |
1/1✓ Branch 1 taken 5342500 times.
|
5342500 | m_properties.note = note; |
| 479 | } else { | ||
| 480 |
2/2✓ Branch 1 taken 7428530 times.
✓ Branch 4 taken 7428530 times.
|
7428530 | m_properties.note += "\n" + note; |
| 481 | } | ||
| 482 | 12771030 | } | |
| 483 | 12771030 | break; | |
| 484 | } | ||
| 485 | 3535505 | case 'o': { | |
| 486 |
2/3✓ Branch 1 taken 3535505 times.
✓ Branch 3 taken 3535505 times.
✗ Branch 4 not taken.
|
3535505 | if (boost::algorithm::starts_with(lowerText, "object-list")) { |
| 487 |
3/5✓ Branch 1 taken 3535505 times.
✓ Branch 4 taken 3535505 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3535505 times.
✗ Branch 9 not taken.
|
3535505 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::objectListProperty())); |
| 488 |
3/3✓ Branch 1 taken 3535505 times.
✓ Branch 4 taken 3535505 times.
✓ Branch 7 taken 3535505 times.
|
3535505 | std::string objectList(matches[1].first, matches[1].second); |
| 489 |
1/1✓ Branch 1 taken 3535505 times.
|
3535505 | openstudio::ascii_trim(objectList); |
| 490 |
1/1✓ Branch 1 taken 3535505 times.
|
3535505 | m_properties.objectLists.push_back(objectList); |
| 491 | 3535505 | notHandled = false; | |
| 492 | 3535505 | } | |
| 493 | 3535505 | break; | |
| 494 | } | ||
| 495 | 8751262 | case 'r': { | |
| 496 |
3/3✓ Branch 1 taken 8751262 times.
✓ Branch 3 taken 7111708 times.
✓ Branch 4 taken 1639554 times.
|
8751262 | if (boost::algorithm::starts_with(lowerText, "required-field")) { |
| 497 | 7111708 | m_properties.required = true; | |
| 498 | 7111708 | notHandled = false; | |
| 499 |
3/3✓ Branch 1 taken 1639554 times.
✓ Branch 3 taken 15989 times.
✓ Branch 4 taken 1623565 times.
|
1639554 | } else if (boost::algorithm::starts_with(lowerText, "reference-class-name")) { |
| 500 |
3/5✓ Branch 1 taken 15989 times.
✓ Branch 4 taken 15989 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 15989 times.
✗ Branch 9 not taken.
|
15989 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::referenceClassNameProperty())); |
| 501 |
3/3✓ Branch 1 taken 15989 times.
✓ Branch 4 taken 15989 times.
✓ Branch 7 taken 15989 times.
|
15989 | std::string reference(matches[1].first, matches[1].second); |
| 502 |
1/1✓ Branch 1 taken 15989 times.
|
15989 | openstudio::ascii_trim(reference); |
| 503 |
1/1✓ Branch 1 taken 15989 times.
|
15989 | m_properties.referenceClassNames.push_back(reference); |
| 504 | 15989 | notHandled = false; | |
| 505 |
3/3✓ Branch 2 taken 1623565 times.
✓ Branch 4 taken 1485340 times.
✓ Branch 5 taken 138225 times.
|
1639554 | } else if (boost::algorithm::starts_with(lowerText, "reference")) { |
| 506 |
3/5✓ Branch 1 taken 1485340 times.
✓ Branch 4 taken 1485340 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1485340 times.
✗ Branch 9 not taken.
|
1485340 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::referenceProperty())); |
| 507 |
3/3✓ Branch 1 taken 1485340 times.
✓ Branch 4 taken 1485340 times.
✓ Branch 7 taken 1485340 times.
|
1485340 | std::string reference(matches[1].first, matches[1].second); |
| 508 |
1/1✓ Branch 1 taken 1485340 times.
|
1485340 | openstudio::ascii_trim(reference); |
| 509 |
1/1✓ Branch 1 taken 1485340 times.
|
1485340 | m_properties.references.push_back(reference); |
| 510 | 1485340 | notHandled = false; | |
| 511 |
2/3✓ Branch 2 taken 138225 times.
✓ Branch 4 taken 138225 times.
✗ Branch 5 not taken.
|
1623565 | } else if (boost::algorithm::starts_with(lowerText, "retaincase")) { |
| 512 | 138225 | m_properties.retaincase = true; | |
| 513 | 138225 | notHandled = false; | |
| 514 | } | ||
| 515 | 8751262 | break; | |
| 516 | } | ||
| 517 | |||
| 518 | 13123591 | case 't': { | |
| 519 |
2/3✓ Branch 1 taken 13123591 times.
✓ Branch 3 taken 13123591 times.
✗ Branch 4 not taken.
|
13123591 | if (boost::algorithm::starts_with(lowerText, "type")) { |
| 520 |
3/5✓ Branch 1 taken 13123591 times.
✓ Branch 4 taken 13123591 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13123591 times.
✗ Branch 9 not taken.
|
13123591 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::typeProperty())); |
| 521 |
3/3✓ Branch 1 taken 13123591 times.
✓ Branch 4 taken 13123591 times.
✓ Branch 7 taken 13123591 times.
|
13123591 | std::string fieldType(matches[1].first, matches[1].second); |
| 522 |
1/1✓ Branch 1 taken 13123591 times.
|
13123591 | openstudio::ascii_trim(fieldType); |
| 523 |
1/1✓ Branch 1 taken 13123591 times.
|
13123591 | m_properties.type = IddFieldType(fieldType); |
| 524 | 13123591 | notHandled = false; | |
| 525 | 13123591 | } | |
| 526 | 13123591 | break; | |
| 527 | } | ||
| 528 | 4092512 | case 'u': { | |
| 529 |
2/3✓ Branch 1 taken 4092512 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4092512 times.
|
4092512 | if (boost::algorithm::starts_with(lowerText, "unitsBasedOnField")) { |
| 530 | // unhandled | ||
| 531 | //I like how we spend time comparing to this, but then don't handle it! | ||
| 532 | ✗ | notHandled = false; | |
| 533 |
2/3✓ Branch 1 taken 4092512 times.
✓ Branch 3 taken 4092512 times.
✗ Branch 4 not taken.
|
4092512 | } else if (boost::algorithm::starts_with(lowerText, "units")) { |
| 534 |
3/5✓ Branch 1 taken 4092512 times.
✓ Branch 4 taken 4092512 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4092512 times.
✗ Branch 9 not taken.
|
4092512 | OS_ASSERT(boost::regex_search(text, matches, iddRegex::unitsProperty())); |
| 535 |
3/3✓ Branch 1 taken 4092512 times.
✓ Branch 4 taken 4092512 times.
✓ Branch 7 taken 4092512 times.
|
4092512 | std::string units(matches[1].first, matches[1].second); |
| 536 |
1/1✓ Branch 1 taken 4092512 times.
|
4092512 | openstudio::ascii_trim(units); |
| 537 |
1/1✓ Branch 1 taken 4092512 times.
|
4092512 | m_properties.units = units; |
| 538 | 4092512 | notHandled = false; | |
| 539 | 4092512 | } | |
| 540 | 4092512 | break; | |
| 541 | } | ||
| 542 | } | ||
| 543 | |||
| 544 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72894258 times.
|
72894258 | if (notHandled) { |
| 545 | ✗ | LOG_AND_THROW("Unknown field property text '" << text << "' detected in field '" << m_name << "'"); | |
| 546 | } | ||
| 547 | 72894258 | } | |
| 548 | |||
| 549 | } // namespace detail | ||
| 550 | |||
| 551 | // CONSTRUCTORS | ||
| 552 | |||
| 553 | ✗ | IddField::IddField() : m_impl(std::shared_ptr<detail::IddField_Impl>(new detail::IddField_Impl())) {} | |
| 554 | |||
| 555 | // GETTERS | ||
| 556 | |||
| 557 | 12977935 | std::string IddField::name() const { | |
| 558 | 12977935 | return m_impl->name(); | |
| 559 | } | ||
| 560 | |||
| 561 | 3 | std::string IddField::fieldId() const { | |
| 562 | 3 | return m_impl->fieldId(); | |
| 563 | } | ||
| 564 | |||
| 565 | /// get properties | ||
| 566 | 92622109 | const IddFieldProperties& IddField::properties() const { | |
| 567 | 92622109 | return m_impl->properties(); | |
| 568 | } | ||
| 569 | |||
| 570 | 363 | boost::optional<Unit> IddField::getUnits(bool returnIP) const { | |
| 571 | 363 | return m_impl->getUnits(returnIP); | |
| 572 | } | ||
| 573 | |||
| 574 | 8 | bool IddField::unitsBasedOnOtherField() const { | |
| 575 | 8 | return m_impl->unitsBasedOnOtherField(); | |
| 576 | } | ||
| 577 | |||
| 578 | /// get key by name | ||
| 579 | 18 | OptionalIddKey IddField::getKey(const std::string& keyName) const { | |
| 580 | 18 | return m_impl->getKey(keyName); | |
| 581 | } | ||
| 582 | |||
| 583 | /// get all keys | ||
| 584 | 1444558 | IddKeyVector IddField::keys() const { | |
| 585 | 1444558 | return m_impl->keys(); | |
| 586 | } | ||
| 587 | |||
| 588 | // SETTERS | ||
| 589 | |||
| 590 | /// set name | ||
| 591 | 346189 | void IddField::setName(const std::string& name) { | |
| 592 | 346189 | m_impl->setName(name); | |
| 593 | 346189 | } | |
| 594 | |||
| 595 | 4 | void IddField::incrementFieldId(const boost::regex& fieldType) { | |
| 596 | 4 | m_impl->incrementFieldId(fieldType); | |
| 597 | 4 | } | |
| 598 | |||
| 599 | // QUERIES | ||
| 600 | |||
| 601 | 5735392 | bool IddField::isNameField() const { | |
| 602 | 5735392 | return m_impl->isNameField(); | |
| 603 | } | ||
| 604 | |||
| 605 | 25933372 | bool IddField::isObjectListField() const { | |
| 606 | 25933372 | return m_impl->isObjectListField(); | |
| 607 | } | ||
| 608 | |||
| 609 | 389 | bool IddField::operator==(const IddField& other) const { | |
| 610 | 389 | return (*m_impl == *(other.m_impl)); | |
| 611 | } | ||
| 612 | |||
| 613 | 1 | bool IddField::operator!=(const IddField& other) const { | |
| 614 | 1 | return (*m_impl != *(other.m_impl)); | |
| 615 | } | ||
| 616 | |||
| 617 | // SERIALIZATION | ||
| 618 | |||
| 619 | 13984868 | OptionalIddField IddField::load(const std::string& name, const std::string& text, const std::string& objectName) { | |
| 620 |
1/1✓ Branch 1 taken 13984868 times.
|
13984868 | std::shared_ptr<detail::IddField_Impl> p = detail::IddField_Impl::load(name, text, objectName); |
| 621 |
1/2✓ Branch 1 taken 13984868 times.
✗ Branch 2 not taken.
|
13984868 | if (p) { |
| 622 |
2/2✓ Branch 1 taken 13984868 times.
✓ Branch 4 taken 13984868 times.
|
13984868 | return IddField(p); |
| 623 | } else { | ||
| 624 | ✗ | return boost::none; | |
| 625 | } | ||
| 626 | 13984868 | } | |
| 627 | |||
| 628 | // PRIVATE | ||
| 629 | |||
| 630 | 13984868 | IddField::IddField(const std::shared_ptr<detail::IddField_Impl>& impl) : m_impl(impl) {} | |
| 631 | |||
| 632 | // NON-MEMBER FUNCTIONS | ||
| 633 | |||
| 634 | 737462 | std::ostream& IddField::print(std::ostream& os, bool lastField) const { | |
| 635 | 737462 | return m_impl->print(os, lastField); | |
| 636 | } | ||
| 637 | |||
| 638 | ✗ | std::ostream& operator<<(std::ostream& os, const IddField& iddField) { | |
| 639 | ✗ | return iddField.print(os, false); | |
| 640 | } | ||
| 641 | |||
| 642 | 3 | bool referencesEqual(const IddField& field1, const IddField& field2) { | |
| 643 | 3 | bool result = false; | |
| 644 | |||
| 645 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | StringVector refs1 = field1.properties().references; |
| 646 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | StringVector refs2 = field2.properties().references; |
| 647 | |||
| 648 | 3 | unsigned n = refs2.size(); | |
| 649 |
1/1✓ Branch 1 taken 3 times.
|
3 | BoolVector found(n, false); |
| 650 | |||
| 651 | // to be equal, must be same size | ||
| 652 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
|
3 | if (refs1.size() == refs2.size()) { |
| 653 | 1 | unsigned start = 0; // start index for refs2 | |
| 654 | |||
| 655 | // look for refs1 in turn | ||
| 656 |
2/2✓ Branch 5 taken 1 time.
✓ Branch 6 taken 1 time.
|
2 | for (const std::string& ref1 : refs1) { |
| 657 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | for (unsigned i = start; i < n; ++i) { |
| 658 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 | if (!found[i]) { |
| 659 | // refs2[i] not found yet--see if there is a match | ||
| 660 |
2/3✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 | if (istringEqual(ref1, refs2[i])) { |
| 661 |
1/1✓ Branch 1 taken 1 time.
|
1 | found[i] = true; |
| 662 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (i == start) { |
| 663 | // a match and at where we started, so move start marker up | ||
| 664 | 1 | ++start; | |
| 665 | } | ||
| 666 | 1 | break; | |
| 667 | } | ||
| 668 | ✗ | } else if (i == start) { | |
| 669 | // refs[start] already matched, so move start marker up | ||
| 670 | ✗ | ++start; | |
| 671 | } | ||
| 672 | } | ||
| 673 | } | ||
| 674 | // tried to match each ref1 with a refs2. see if we were successful. | ||
| 675 |
3/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
1 | if (found == BoolVector(n, true)) { |
| 676 | 1 | result = true; | |
| 677 | } | ||
| 678 | } | ||
| 679 | |||
| 680 | 3 | return result; | |
| 681 | 3 | } | |
| 682 | |||
| 683 | } // namespace openstudio | ||
| 684 |