src/utilities/idf/IdfObject.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 "IdfObject.hpp" | ||
| 7 | #include "IdfObject_Impl.hpp" | ||
| 8 | |||
| 9 | #include "IdfExtensibleGroup.hpp" | ||
| 10 | #include "IdfRegex.hpp" | ||
| 11 | #include "ValidityReport.hpp" | ||
| 12 | |||
| 13 | #include "../idd/IddKey.hpp" | ||
| 14 | #include <utilities/idd/IddFactory.hxx> | ||
| 15 | #include <utilities/idd/IddEnums.hxx> | ||
| 16 | #include "../idd/IddRegex.hpp" | ||
| 17 | #include "../idd/CommentRegex.hpp" | ||
| 18 | #include "../idd/Comments.hpp" | ||
| 19 | |||
| 20 | #include "../math/FloatCompare.hpp" | ||
| 21 | #include "../core/Finder.hpp" | ||
| 22 | #include "../core/Assert.hpp" | ||
| 23 | |||
| 24 | #include "../units/Quantity.hpp" | ||
| 25 | #include "../units/OSOptionalQuantity.hpp" | ||
| 26 | #include "../units/QuantityConverter.hpp" | ||
| 27 | |||
| 28 | #include <boost/lexical_cast.hpp> | ||
| 29 | |||
| 30 | #include <iomanip> | ||
| 31 | |||
| 32 | namespace openstudio { | ||
| 33 | |||
| 34 | namespace detail { | ||
| 35 | |||
| 36 | // CONSTRUCTORS | ||
| 37 | |||
| 38 | 1823437 | IdfObject_Impl::IdfObject_Impl(const IdfObject_Impl& other, bool keepHandle) | |
| 39 |
5/5✓ Branch 6 taken 1823437 times.
✓ Branch 9 taken 1823437 times.
✓ Branch 12 taken 1823437 times.
✓ Branch 15 taken 1823437 times.
✓ Branch 18 taken 1823437 times.
|
1823437 | : m_comment(other.comment()), m_iddObject(other.iddObject()), m_fields(other.fields()), m_fieldComments(other.fieldComments()) { |
| 40 |
2/2✓ Branch 0 taken 1229710 times.
✓ Branch 1 taken 593727 times.
|
1823437 | if (keepHandle) { |
| 41 |
2/4✓ Branch 1 taken 1229710 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1229710 times.
✗ Branch 7 not taken.
|
1229710 | OS_ASSERT(!other.handle().isNull()); |
| 42 |
1/1✓ Branch 1 taken 1229710 times.
|
1229710 | m_handle = other.handle(); |
| 43 | } else { | ||
| 44 |
1/1✓ Branch 1 taken 593727 times.
|
593727 | m_handle = openstudio::createUUID(); |
| 45 |
3/3✓ Branch 1 taken 593727 times.
✓ Branch 3 taken 211876 times.
✓ Branch 4 taken 381851 times.
|
593727 | if (m_iddObject.hasHandleField()) { |
| 46 |
2/2✓ Branch 1 taken 211876 times.
✓ Branch 4 taken 211876 times.
|
211876 | bool ok = setString(0, toString(m_handle)); |
| 47 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 211876 times.
✗ Branch 3 not taken.
|
211876 | OS_ASSERT(ok); |
| 48 | } | ||
| 49 | } | ||
| 50 | 1823437 | } | |
| 51 | |||
| 52 |
2/2✓ Branch 6 taken 225262 times.
✓ Branch 10 taken 225262 times.
|
225262 | IdfObject_Impl::IdfObject_Impl(IddObjectType type, bool fastName) : m_handle(openstudio::createUUID()) { |
| 53 |
2/2✓ Branch 1 taken 225262 times.
✓ Branch 4 taken 225262 times.
|
225262 | OptionalIddObject candidate = IddFactory::instance().getObject(type); |
| 54 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 225262 times.
✗ Branch 4 not taken.
|
225262 | OS_ASSERT(candidate); |
| 55 |
1/1✓ Branch 1 taken 225262 times.
|
225262 | m_iddObject = *candidate; |
| 56 |
3/3✓ Branch 1 taken 225262 times.
✓ Branch 3 taken 176435 times.
✓ Branch 4 taken 48827 times.
|
225262 | if (m_iddObject.hasHandleField()) { |
| 57 |
2/2✓ Branch 1 taken 176435 times.
✓ Branch 4 taken 176435 times.
|
176435 | bool ok = setString(0, toString(m_handle)); |
| 58 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 176435 times.
✗ Branch 3 not taken.
|
176435 | OS_ASSERT(ok); |
| 59 | } | ||
| 60 |
2/2✓ Branch 0 taken 1021 times.
✓ Branch 1 taken 224241 times.
|
225262 | if (fastName) { |
| 61 |
1/1✓ Branch 1 taken 1021 times.
|
1021 | boost::optional<unsigned> nameFieldIndex = this->m_iddObject.nameFieldIndex(); |
| 62 |
1/2✓ Branch 0 taken 1021 times.
✗ Branch 1 not taken.
|
1021 | if (nameFieldIndex) { |
| 63 |
4/4✓ Branch 1 taken 1021 times.
✓ Branch 4 taken 1021 times.
✓ Branch 7 taken 1021 times.
✓ Branch 10 taken 1021 times.
|
1021 | bool ok = setString(*nameFieldIndex, toString(createUUID())); |
| 64 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1021 times.
✗ Branch 3 not taken.
|
1021 | OS_ASSERT(ok); |
| 65 | } else { | ||
| 66 | ✗ | LOG(Error, "Requested setting name field to UUID but object of type '" << this->m_iddObject.name() << "' has no name field"); | |
| 67 | } | ||
| 68 | } | ||
| 69 |
1/1✓ Branch 1 taken 225262 times.
|
225262 | resizeToMinFields(); |
| 70 | 225262 | } | |
| 71 | |||
| 72 |
2/2✓ Branch 6 taken 21861 times.
✓ Branch 10 taken 21861 times.
|
21861 | IdfObject_Impl::IdfObject_Impl(const IddObject& iddObject, bool fastName) : m_handle(openstudio::createUUID()), m_iddObject(iddObject) { |
| 73 |
3/3✓ Branch 1 taken 21861 times.
✓ Branch 3 taken 19836 times.
✓ Branch 4 taken 2025 times.
|
21861 | if (this->m_iddObject.hasHandleField()) { |
| 74 |
2/2✓ Branch 1 taken 19836 times.
✓ Branch 4 taken 19836 times.
|
19836 | bool ok = setString(0, toString(m_handle)); |
| 75 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 19836 times.
✗ Branch 3 not taken.
|
19836 | OS_ASSERT(ok); |
| 76 | } | ||
| 77 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 21851 times.
|
21861 | if (fastName) { |
| 78 |
1/1✓ Branch 1 taken 10 times.
|
10 | boost::optional<unsigned> nameFieldIndex = this->m_iddObject.nameFieldIndex(); |
| 79 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (nameFieldIndex) { |
| 80 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
|
10 | bool ok = setString(*nameFieldIndex, toString(createUUID())); |
| 81 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
|
10 | OS_ASSERT(ok); |
| 82 | } else { | ||
| 83 | ✗ | LOG(Error, "Requested setting name field to UUID but object of type '" << this->m_iddObject.name() << "' has no name field"); | |
| 84 | } | ||
| 85 | } | ||
| 86 |
1/1✓ Branch 1 taken 21861 times.
|
21861 | resizeToMinFields(); |
| 87 | 21861 | } | |
| 88 | |||
| 89 |
2/2✓ Branch 6 taken 1250333 times.
✓ Branch 10 taken 1250333 times.
|
1250333 | IdfObject_Impl::IdfObject_Impl(const IddObject& iddObject, bool fastName, bool minimal) : m_iddObject(iddObject) { |
| 90 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1250333 times.
✗ Branch 3 not taken.
|
1250333 | OS_ASSERT(!fastName); |
| 91 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1250333 times.
✗ Branch 3 not taken.
|
1250333 | OS_ASSERT(minimal); |
| 92 | 1250333 | } | |
| 93 | |||
| 94 | 181241 | IdfObject_Impl::IdfObject_Impl(const Handle& handle, const std::string& comment, const IddObject& iddObject, const StringVector& fields, | |
| 95 | 181241 | const StringVector& fieldComments) | |
| 96 |
4/4✓ Branch 6 taken 181241 times.
✓ Branch 9 taken 181241 times.
✓ Branch 12 taken 181241 times.
✓ Branch 15 taken 181241 times.
|
181241 | : m_handle(handle), m_comment(comment), m_iddObject(iddObject), m_fields(fields), m_fieldComments(fieldComments) { |
| 97 |
1/1✓ Branch 1 taken 181241 times.
|
181241 | resizeToMinFields(); |
| 98 | 181241 | } | |
| 99 | |||
| 100 | // GETTERS | ||
| 101 | |||
| 102 | 21132200 | Handle IdfObject_Impl::handle() const { | |
| 103 | 21132200 | return m_handle; | |
| 104 | } | ||
| 105 | |||
| 106 | 124355745 | IddObject IdfObject_Impl::iddObject() const { | |
| 107 | 124355745 | return m_iddObject; | |
| 108 | } | ||
| 109 | |||
| 110 | 1823602 | std::string IdfObject_Impl::comment() const { | |
| 111 | 1823602 | return m_comment; | |
| 112 | } | ||
| 113 | |||
| 114 | 9523402 | boost::optional<std::string> IdfObject_Impl::fieldComment(unsigned index, bool returnDefault) const { | |
| 115 |
3/3✓ Branch 1 taken 9523402 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 9523401 times.
|
9523402 | if (index >= numFields()) { |
| 116 | 1 | return boost::none; | |
| 117 | } | ||
| 118 | |||
| 119 | 9523401 | std::string result; | |
| 120 |
2/2✓ Branch 1 taken 590320 times.
✓ Branch 2 taken 8933081 times.
|
9523401 | if (index < m_fieldComments.size()) { |
| 121 |
1/1✓ Branch 2 taken 590320 times.
|
590320 | result = m_fieldComments[index]; |
| 122 | } | ||
| 123 | |||
| 124 |
6/6✓ Branch 0 taken 9212148 times.
✓ Branch 1 taken 311253 times.
✓ Branch 3 taken 8623640 times.
✓ Branch 4 taken 588508 times.
✓ Branch 5 taken 8623640 times.
✓ Branch 6 taken 899761 times.
|
9523401 | if (returnDefault && result.empty()) { |
| 125 |
2/3✓ Branch 1 taken 8623640 times.
✓ Branch 3 taken 8623640 times.
✗ Branch 4 not taken.
|
17247280 | if (OptionalIddField iddField = m_iddObject.getField(index)) { |
| 126 |
1/1✓ Branch 1 taken 8623640 times.
|
8623640 | std::stringstream ss; |
| 127 |
4/4✓ Branch 1 taken 8623640 times.
✓ Branch 4 taken 8623640 times.
✓ Branch 7 taken 8623640 times.
✓ Branch 10 taken 8623640 times.
|
8623640 | ss << makeIdfEditorComment(iddField->name()); |
| 128 |
3/3✓ Branch 1 taken 8623640 times.
✓ Branch 3 taken 679257 times.
✓ Branch 4 taken 7944383 times.
|
8623640 | if (m_iddObject.isExtensibleField(index)) { |
| 129 |
1/1✓ Branch 1 taken 679257 times.
|
679257 | ExtensibleIndex ei = m_iddObject.extensibleIndex(index); |
| 130 |
2/2✓ Branch 1 taken 679257 times.
✓ Branch 4 taken 679257 times.
|
679257 | ss << " " << ei.group + 1; |
| 131 | } | ||
| 132 |
5/5✓ Branch 1 taken 8623640 times.
✓ Branch 4 taken 8623640 times.
✓ Branch 7 taken 8623640 times.
✓ Branch 9 taken 878607 times.
✓ Branch 10 taken 7745033 times.
|
17247280 | if (OptionalString units = iddField->properties().units) { |
| 133 |
1/2✓ Branch 0 taken 878607 times.
✗ Branch 1 not taken.
|
878607 | if (units) { |
| 134 |
4/4✓ Branch 1 taken 878607 times.
✓ Branch 4 taken 878607 times.
✓ Branch 7 taken 878607 times.
✓ Branch 10 taken 878607 times.
|
878607 | ss << " {" << *units << "}"; |
| 135 | } | ||
| 136 | 8623640 | } | |
| 137 |
1/1✓ Branch 1 taken 8623640 times.
|
8623640 | result = ss.str(); |
| 138 | 17247280 | } | |
| 139 | } | ||
| 140 |
1/1✓ Branch 1 taken 9523401 times.
|
9523401 | return result; |
| 141 | 9523401 | } | |
| 142 | |||
| 143 | 34884964 | boost::optional<std::string> IdfObject_Impl::name(bool returnDefault) const { | |
| 144 |
3/3✓ Branch 1 taken 34884964 times.
✓ Branch 3 taken 33786491 times.
✓ Branch 4 taken 1098473 times.
|
69769928 | if (OptionalUnsigned oi = m_iddObject.nameFieldIndex()) { |
| 145 |
1/1✓ Branch 1 taken 33786491 times.
|
33786491 | unsigned index = *oi; |
| 146 | 33786491 | bool validIndex = m_fields.size() > index; | |
| 147 |
7/8✓ Branch 0 taken 403321 times.
✓ Branch 1 taken 33383170 times.
✓ Branch 2 taken 403321 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 117482 times.
✓ Branch 7 taken 285839 times.
✓ Branch 8 taken 117482 times.
✓ Branch 9 taken 33669009 times.
|
33786491 | if (returnDefault && validIndex && m_fields[index].empty()) { |
| 148 |
5/5✓ Branch 1 taken 117482 times.
✓ Branch 5 taken 117482 times.
✓ Branch 8 taken 117482 times.
✓ Branch 10 taken 48 times.
✓ Branch 11 taken 117434 times.
|
234964 | if (OptionalString stringDefault = m_iddObject.nonextensibleFields()[index].properties().stringDefault) { |
| 149 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (stringDefault) { |
| 150 |
3/3✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
|
48 | return decodeString(*stringDefault); |
| 151 | } else { | ||
| 152 | ✗ | return boost::none; | |
| 153 | } | ||
| 154 | 117482 | } | |
| 155 |
2/2✓ Branch 2 taken 117434 times.
✓ Branch 5 taken 117434 times.
|
117434 | return decodeString(m_fields[index]); |
| 156 |
2/2✓ Branch 0 taken 33659523 times.
✓ Branch 1 taken 9486 times.
|
33669009 | } else if (validIndex) { |
| 157 |
2/2✓ Branch 2 taken 33659523 times.
✓ Branch 5 taken 33659523 times.
|
33659523 | return decodeString(m_fields[index]); |
| 158 | } | ||
| 159 | } | ||
| 160 | 1107959 | return boost::none; | |
| 161 | } | ||
| 162 | |||
| 163 | 437882 | std::string IdfObject_Impl::nameString(bool returnDefault) const { | |
| 164 |
1/1✓ Branch 1 taken 437882 times.
|
437882 | boost::optional<std::string> temp = name(returnDefault); |
| 165 |
2/2✓ Branch 0 taken 431658 times.
✓ Branch 1 taken 6224 times.
|
437882 | if (temp) { |
| 166 |
2/2✓ Branch 1 taken 431658 times.
✓ Branch 4 taken 431658 times.
|
431658 | return temp.get(); |
| 167 | } | ||
| 168 |
1/1✓ Branch 1 taken 6224 times.
|
12448 | return ""; |
| 169 | 437882 | } | |
| 170 | |||
| 171 | 70871 | std::string IdfObject_Impl::briefDescription() const { | |
| 172 |
1/1✓ Branch 1 taken 70871 times.
|
70871 | std::stringstream ss; |
| 173 |
5/5✓ Branch 1 taken 70871 times.
✓ Branch 4 taken 70871 times.
✓ Branch 7 taken 70871 times.
✓ Branch 10 taken 70871 times.
✓ Branch 13 taken 70871 times.
|
70871 | ss << "Object of type '" << m_iddObject.type().valueDescription() << "'"; |
| 174 |
1/1✓ Branch 1 taken 70871 times.
|
70871 | OptionalString oName = name(true); |
| 175 |
6/7✓ Branch 0 taken 54934 times.
✓ Branch 1 taken 15937 times.
✓ Branch 3 taken 54934 times.
✓ Branch 6 taken 54934 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 54934 times.
✓ Branch 9 taken 15937 times.
|
70871 | if (oName && (!oName->empty())) { |
| 176 |
4/4✓ Branch 1 taken 54934 times.
✓ Branch 4 taken 54934 times.
✓ Branch 7 taken 54934 times.
✓ Branch 10 taken 54934 times.
|
54934 | ss << " and named '" << *oName << "'"; |
| 177 | } | ||
| 178 |
1/1✓ Branch 1 taken 70871 times.
|
141742 | return ss.str(); |
| 179 | 70871 | } | |
| 180 | |||
| 181 | 159589 | bool IdfObject_Impl::isEmpty(unsigned index) const { | |
| 182 | 159589 | bool result = true; | |
| 183 |
2/2✓ Branch 1 taken 126908 times.
✓ Branch 2 taken 32681 times.
|
159589 | if (index < m_fields.size()) { |
| 184 |
1/1✓ Branch 1 taken 126908 times.
|
126908 | OptionalString string = getString(index, false, true); |
| 185 |
2/2✓ Branch 0 taken 57061 times.
✓ Branch 1 taken 69847 times.
|
126908 | if (string) { |
| 186 | 57061 | result = false; | |
| 187 | } | ||
| 188 | 126908 | } | |
| 189 | 159589 | return result; | |
| 190 | } | ||
| 191 | |||
| 192 | 19944122 | boost::optional<std::string> IdfObject_Impl::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const { | |
| 193 | 19944122 | OptionalString result; | |
| 194 |
2/2✓ Branch 1 taken 19870144 times.
✓ Branch 2 taken 73978 times.
|
19944122 | if (index < m_fields.size()) { |
| 195 |
1/1✓ Branch 2 taken 19870144 times.
|
19870144 | result = m_fields[index]; |
| 196 | } | ||
| 197 |
11/11✓ Branch 0 taken 1646571 times.
✓ Branch 1 taken 18297551 times.
✓ Branch 2 taken 1577534 times.
✓ Branch 3 taken 69037 times.
✓ Branch 5 taken 1577534 times.
✓ Branch 8 taken 1502695 times.
✓ Branch 9 taken 74839 times.
✓ Branch 11 taken 69037 times.
✓ Branch 12 taken 1502695 times.
✓ Branch 13 taken 143876 times.
✓ Branch 14 taken 19800246 times.
|
21590693 | if (returnDefault && ((result && result->empty()) || (!result))) { |
| 198 |
1/1✓ Branch 1 taken 143876 times.
|
143876 | OptionalIddField iddField = m_iddObject.getField(index); |
| 199 |
8/8✓ Branch 0 taken 143875 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 143875 times.
✓ Branch 6 taken 143875 times.
✓ Branch 9 taken 98451 times.
✓ Branch 10 taken 45424 times.
✓ Branch 11 taken 98451 times.
✓ Branch 12 taken 45425 times.
|
287751 | if (iddField && iddField->properties().stringDefault) { |
| 200 |
4/4✓ Branch 1 taken 98451 times.
✓ Branch 4 taken 98451 times.
✓ Branch 7 taken 98451 times.
✓ Branch 10 taken 98451 times.
|
98451 | result = *(iddField->properties().stringDefault); |
| 201 | } | ||
| 202 | 143876 | } | |
| 203 |
9/9✓ Branch 0 taken 514812 times.
✓ Branch 1 taken 19429310 times.
✓ Branch 2 taken 512553 times.
✓ Branch 3 taken 2259 times.
✓ Branch 5 taken 512553 times.
✓ Branch 8 taken 42369 times.
✓ Branch 9 taken 470184 times.
✓ Branch 10 taken 42369 times.
✓ Branch 11 taken 19901753 times.
|
20458934 | if (returnUninitializedEmpty && (result && result->empty())) { |
| 204 | 42369 | result.reset(); | |
| 205 | } | ||
| 206 |
2/2✓ Branch 0 taken 19876353 times.
✓ Branch 1 taken 67769 times.
|
19944122 | if (result) { |
| 207 |
3/3✓ Branch 1 taken 19876353 times.
✓ Branch 4 taken 19876353 times.
✓ Branch 7 taken 19876353 times.
|
19876353 | return decodeString(*result); |
| 208 | } | ||
| 209 | 67769 | return boost::none; | |
| 210 | 19944122 | } | |
| 211 | |||
| 212 | 809 | boost::optional<std::string> IdfObject_Impl::getField(unsigned index, bool returnDefault) const { | |
| 213 | 809 | return IdfObject_Impl::getString(index, returnDefault, false); | |
| 214 | } | ||
| 215 | |||
| 216 | 11330671 | boost::optional<double> IdfObject_Impl::getDouble(unsigned index, bool returnDefault) const { | |
| 217 | 11330671 | OptionalDouble result; | |
| 218 |
1/1✓ Branch 1 taken 11330671 times.
|
11330671 | OptionalString value = getString(index, returnDefault, false); |
| 219 |
2/2✓ Branch 0 taken 11321984 times.
✓ Branch 1 taken 8687 times.
|
11330671 | if (value) { |
| 220 |
27/41✓ Branch 1 taken 11321984 times.
✓ Branch 4 taken 11321984 times.
✓ Branch 7 taken 11321984 times.
✓ Branch 9 taken 10028672 times.
✓ Branch 10 taken 1293312 times.
✓ Branch 12 taken 10028672 times.
✓ Branch 15 taken 10028672 times.
✓ Branch 18 taken 10028672 times.
✓ Branch 20 taken 9877722 times.
✓ Branch 21 taken 150950 times.
✓ Branch 23 taken 9877722 times.
✓ Branch 26 taken 9877722 times.
✓ Branch 29 taken 9877722 times.
✓ Branch 31 taken 9834301 times.
✓ Branch 32 taken 43421 times.
✓ Branch 33 taken 9877722 times.
✓ Branch 34 taken 1444262 times.
✓ Branch 36 taken 9877722 times.
✓ Branch 37 taken 1444262 times.
✓ Branch 38 taken 10028672 times.
✓ Branch 39 taken 1293312 times.
✓ Branch 41 taken 10028672 times.
✓ Branch 42 taken 1293312 times.
✓ Branch 43 taken 11321984 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 11321984 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 9834301 times.
✓ Branch 49 taken 1487683 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
|
73778740 | if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) { |
| 221 | try { | ||
| 222 |
3/3✓ Branch 1 taken 9834301 times.
✓ Branch 4 taken 9810360 times.
✓ Branch 7 taken 9810360 times.
|
9834301 | result = boost::lexical_cast<double>(*value); |
| 223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23941 times.
|
23941 | } catch (const std::exception&) { |
| 224 |
8/8✓ Branch 1 taken 23941 times.
✓ Branch 4 taken 23941 times.
✓ Branch 7 taken 23941 times.
✓ Branch 10 taken 23941 times.
✓ Branch 13 taken 23941 times.
✓ Branch 16 taken 23941 times.
✓ Branch 19 taken 23941 times.
✓ Branch 22 taken 23941 times.
|
23941 | LOG(Error, "Could not convert '" << *value << "' to double"); |
| 225 | 23941 | } | |
| 226 | } | ||
| 227 | } | ||
| 228 | 11330671 | return result; | |
| 229 | 11330671 | } | |
| 230 | |||
| 231 | 2 | OSOptionalQuantity IdfObject_Impl::getQuantity(unsigned index, bool returnDefault, bool returnIP) const { | |
| 232 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalDouble value = getDouble(index, returnDefault); |
| 233 |
1/1✓ Branch 1 taken 2 times.
|
4 | return getQuantityFromDouble(index, value, returnIP); |
| 234 | } | ||
| 235 | |||
| 236 | 12972 | boost::optional<unsigned> IdfObject_Impl::getUnsigned(unsigned index, bool returnDefault) const { | |
| 237 | 12972 | OptionalUnsigned result; | |
| 238 |
1/1✓ Branch 1 taken 12972 times.
|
12972 | OptionalString value = getString(index, returnDefault, false); |
| 239 |
2/2✓ Branch 0 taken 12971 times.
✓ Branch 1 taken 1 time.
|
12972 | if (value) { |
| 240 |
19/41✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
✓ Branch 7 taken 12971 times.
✓ Branch 9 taken 12971 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 12971 times.
✓ Branch 15 taken 12971 times.
✓ Branch 18 taken 12971 times.
✓ Branch 20 taken 12971 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 12971 times.
✓ Branch 26 taken 12971 times.
✓ Branch 29 taken 12971 times.
✓ Branch 31 taken 12971 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 12971 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 12971 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 12971 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 12971 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 12971 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 12971 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 12971 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
|
90797 | if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) { |
| 241 | try { | ||
| 242 |
2/2✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
|
12971 | auto temp = boost::lexical_cast<double>(*value); |
| 243 |
2/2✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
|
12971 | result = boost::numeric_cast<unsigned>(temp); |
| 244 | ✗ | } catch (const std::exception&) { | |
| 245 | ✗ | LOG(Error, "Could not convert '" << *value << "' to unsigned"); | |
| 246 | ✗ | } | |
| 247 | } | ||
| 248 | } | ||
| 249 | 12972 | return result; | |
| 250 | 12972 | } | |
| 251 | |||
| 252 | 2958584 | boost::optional<int> IdfObject_Impl::getInt(unsigned index, bool returnDefault) const { | |
| 253 | 2958584 | OptionalInt result; | |
| 254 |
1/1✓ Branch 1 taken 2958584 times.
|
2958584 | OptionalString value = getString(index, returnDefault, false); |
| 255 |
2/2✓ Branch 0 taken 2944673 times.
✓ Branch 1 taken 13911 times.
|
2958584 | if (value) { |
| 256 |
25/41✓ Branch 1 taken 2944673 times.
✓ Branch 4 taken 2944673 times.
✓ Branch 7 taken 2944673 times.
✓ Branch 9 taken 2774143 times.
✓ Branch 10 taken 170530 times.
✓ Branch 12 taken 2774143 times.
✓ Branch 15 taken 2774143 times.
✓ Branch 18 taken 2774143 times.
✓ Branch 20 taken 2774143 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 2774143 times.
✓ Branch 26 taken 2774143 times.
✓ Branch 29 taken 2774143 times.
✓ Branch 31 taken 2774143 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 2774143 times.
✓ Branch 34 taken 170530 times.
✓ Branch 36 taken 2774143 times.
✓ Branch 37 taken 170530 times.
✓ Branch 38 taken 2774143 times.
✓ Branch 39 taken 170530 times.
✓ Branch 41 taken 2774143 times.
✓ Branch 42 taken 170530 times.
✓ Branch 43 taken 2944673 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 2944673 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 2774143 times.
✓ Branch 49 taken 170530 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
|
19930591 | if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) { |
| 257 | try { | ||
| 258 |
2/2✓ Branch 1 taken 2774143 times.
✓ Branch 4 taken 2774143 times.
|
2774143 | auto temp = boost::lexical_cast<double>(*value); |
| 259 |
2/2✓ Branch 1 taken 2774068 times.
✓ Branch 4 taken 2774068 times.
|
2774143 | result = boost::numeric_cast<int>(temp); |
| 260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | } catch (const std::exception&) { |
| 261 |
8/8✓ Branch 1 taken 75 times.
✓ Branch 4 taken 75 times.
✓ Branch 7 taken 75 times.
✓ Branch 10 taken 75 times.
✓ Branch 13 taken 75 times.
✓ Branch 16 taken 75 times.
✓ Branch 19 taken 75 times.
✓ Branch 22 taken 75 times.
|
75 | LOG(Error, "Could not convert '" << *value << "' to int"); |
| 262 | 75 | } | |
| 263 | } | ||
| 264 | } | ||
| 265 | 2958584 | return result; | |
| 266 | 2958584 | } | |
| 267 | |||
| 268 | 2845809 | IdfExtensibleGroup IdfObject_Impl::getExtensibleGroup(unsigned groupIndex) const { | |
| 269 |
1/1✓ Branch 1 taken 2845809 times.
|
2845809 | unsigned n = numFields(); |
| 270 | 2845809 | unsigned i = n; | |
| 271 | 2845809 | std::shared_ptr<detail::IdfObject_Impl> p; | |
| 272 |
1/1✓ Branch 2 taken 2845809 times.
|
2845809 | IdfExtensibleGroup eg(p, i); |
| 273 |
2/3✓ Branch 1 taken 2845809 times.
✓ Branch 3 taken 2845809 times.
✗ Branch 4 not taken.
|
2845809 | if (m_iddObject.properties().extensible) { |
| 274 |
5/5✓ Branch 1 taken 2845809 times.
✓ Branch 4 taken 2845809 times.
✓ Branch 7 taken 2845809 times.
✓ Branch 9 taken 2845763 times.
✓ Branch 10 taken 46 times.
|
2845809 | if (m_iddObject.index(ExtensibleIndex(groupIndex, m_iddObject.properties().numExtensible - 1)) < n) { |
| 275 |
2/2✓ Branch 1 taken 2845763 times.
✓ Branch 4 taken 2845763 times.
|
2845763 | i = m_iddObject.index(ExtensibleIndex(groupIndex, 0)); |
| 276 |
2/2✓ Branch 1 taken 2845763 times.
✓ Branch 5 taken 2845763 times.
|
2845763 | eg = IdfExtensibleGroup(std::const_pointer_cast<IdfObject_Impl>(shared_from_this()), i); |
| 277 | } | ||
| 278 | } | ||
| 279 | 5691618 | return eg; | |
| 280 | 2845809 | } | |
| 281 | |||
| 282 | 323797 | std::vector<IdfExtensibleGroup> IdfObject_Impl::extensibleGroups() const { | |
| 283 | 323797 | IdfExtensibleGroupVector result; | |
| 284 |
3/3✓ Branch 1 taken 323797 times.
✓ Branch 3 taken 2086753 times.
✓ Branch 4 taken 323797 times.
|
2410550 | for (unsigned i = 0, n = numExtensibleGroups(); i < n; ++i) { |
| 285 |
2/2✓ Branch 1 taken 2086753 times.
✓ Branch 4 taken 2086753 times.
|
2086753 | result.push_back(getExtensibleGroup(i)); |
| 286 | } | ||
| 287 | 323797 | return result; | |
| 288 | ✗ | } | |
| 289 | |||
| 290 | // SETTERS | ||
| 291 | |||
| 292 | 73 | void IdfObject_Impl::setComment(const std::string& comment) { | |
| 293 | 73 | setComment(comment, true); | |
| 294 | 73 | this->emitChangeSignals(); | |
| 295 | 73 | } | |
| 296 | |||
| 297 | 73 | void IdfObject_Impl::setComment(const std::string& comment, bool /*checkValidity*/) { | |
| 298 |
1/1✓ Branch 1 taken 73 times.
|
73 | m_comment = makeComment(comment); |
| 299 |
2/2✓ Branch 4 taken 73 times.
✓ Branch 7 taken 73 times.
|
73 | m_diffs.push_back(IdfObjectDiff(boost::none, boost::none, boost::none)); |
| 300 | 73 | } | |
| 301 | |||
| 302 | 255 | bool IdfObject_Impl::setFieldComment(unsigned index, const std::string& cmnt) { | |
| 303 | 255 | bool result = setFieldComment(index, cmnt, true); | |
| 304 |
2/2✓ Branch 0 taken 251 times.
✓ Branch 1 taken 4 times.
|
255 | if (result) { |
| 305 | 251 | this->emitChangeSignals(); | |
| 306 | } | ||
| 307 | 255 | return result; | |
| 308 | } | ||
| 309 | |||
| 310 | 255 | bool IdfObject_Impl::setFieldComment(unsigned index, const std::string& cmnt, bool /*checkValidity*/) { | |
| 311 |
2/2✓ Branch 1 taken 251 times.
✓ Branch 2 taken 4 times.
|
255 | if (index < m_fields.size()) { |
| 312 |
1/2✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
|
251 | if (index >= m_fieldComments.size()) { |
| 313 | 251 | m_fieldComments.resize(index + 1); | |
| 314 | } | ||
| 315 | |||
| 316 |
1/1✓ Branch 1 taken 251 times.
|
251 | m_fieldComments[index] = makeComment(cmnt); |
| 317 | |||
| 318 |
5/5✓ Branch 2 taken 251 times.
✓ Branch 6 taken 251 times.
✓ Branch 9 taken 251 times.
✓ Branch 12 taken 251 times.
✓ Branch 15 taken 251 times.
|
251 | m_diffs.push_back(IdfObjectDiff(index, m_fields[index], m_fields[index])); |
| 319 | |||
| 320 | 251 | return true; | |
| 321 | } | ||
| 322 | 4 | return false; | |
| 323 | } | ||
| 324 | |||
| 325 | 33443 | boost::optional<std::string> IdfObject_Impl::setName(const std::string& newName) { | |
| 326 | 33443 | OptionalString result = IdfObject_Impl::setName(newName, true); | |
| 327 |
2/2✓ Branch 0 taken 33440 times.
✓ Branch 1 taken 3 times.
|
33443 | if (result) { |
| 328 |
1/1✓ Branch 1 taken 33440 times.
|
33440 | this->emitChangeSignals(); |
| 329 | } | ||
| 330 | 33443 | return result; | |
| 331 | ✗ | } | |
| 332 | |||
| 333 | 248595 | boost::optional<std::string> IdfObject_Impl::setName(const std::string& _newName, bool /*checkValidity*/) { | |
| 334 |
1/1✓ Branch 1 taken 248595 times.
|
248595 | std::string newName = encodeString(_newName); |
| 335 | |||
| 336 |
4/4✓ Branch 1 taken 248595 times.
✓ Branch 4 taken 248595 times.
✓ Branch 6 taken 1156 times.
✓ Branch 7 taken 247439 times.
|
248595 | switch (m_iddObject.type().value()) { |
| 337 | // get all EMS idd object types in both E+ and OS IDD | ||
| 338 | 1156 | case openstudio::IddObjectType::EnergyManagementSystem_Actuator:; // deliberate fall through | |
| 339 | case openstudio::IddObjectType::OS_EnergyManagementSystem_Actuator:; // deliberate fall through | ||
| 340 | case openstudio::IddObjectType::EnergyManagementSystem_ConstructionIndexVariable:; // TODO uncomment when wrapped | ||
| 341 | case openstudio::IddObjectType::OS_EnergyManagementSystem_ConstructionIndexVariable:; // deliberate fall through | ||
| 342 | case openstudio::IddObjectType::EnergyManagementSystem_CurveOrTableIndexVariable:; // TODO uncomment when wrapped | ||
| 343 | case openstudio::IddObjectType::OS_EnergyManagementSystem_CurveOrTableIndexVariable:; // deliberate fall through | ||
| 344 | case openstudio::IddObjectType::EnergyManagementSystem_GlobalVariable:; // deliberate fall through | ||
| 345 | case openstudio::IddObjectType::OS_EnergyManagementSystem_GlobalVariable:; // deliberate fall through | ||
| 346 | case openstudio::IddObjectType::EnergyManagementSystem_InternalVariable:; // deliberate fall through | ||
| 347 | case openstudio::IddObjectType::OS_EnergyManagementSystem_InternalVariable:; // deliberate fall through | ||
| 348 | case openstudio::IddObjectType::EnergyManagementSystem_Program:; // deliberate fall through | ||
| 349 | case openstudio::IddObjectType::OS_EnergyManagementSystem_Program:; // deliberate fall through | ||
| 350 | case openstudio::IddObjectType::EnergyManagementSystem_Sensor:; // deliberate fall through | ||
| 351 | case openstudio::IddObjectType::OS_EnergyManagementSystem_Sensor:; // deliberate fall through | ||
| 352 | case openstudio::IddObjectType::EnergyManagementSystem_Subroutine:; // deliberate fall through | ||
| 353 | case openstudio::IddObjectType::OS_EnergyManagementSystem_Subroutine:; // deliberate fall through | ||
| 354 | case openstudio::IddObjectType::EnergyManagementSystem_TrendVariable:; // deliberate fall through | ||
| 355 | case openstudio::IddObjectType::OS_EnergyManagementSystem_TrendVariable:; // deliberate fall through | ||
| 356 | // replace � � with �_� | ||
| 357 | 1156 | std::replace(newName.begin(), newName.end(), ' ', '_'); | |
| 358 | 1156 | break; | |
| 359 | //case openstudio::IddObjectType::EnergyManagementSystem_OutputVariable:; // deliberate fall through | ||
| 360 | //case openstudio::IddObjectType::OS_EnergyManagementSystem_OutputVariable:; // deliberate fall through | ||
| 361 | //TODO Enforce Title-Case | ||
| 362 | 247439 | default: | |
| 363 | // no-op | ||
| 364 | 247439 | break; | |
| 365 | } | ||
| 366 | |||
| 367 | // check Idd to see if this object has a name | ||
| 368 |
3/3✓ Branch 1 taken 248595 times.
✓ Branch 3 taken 248592 times.
✓ Branch 4 taken 3 times.
|
497190 | if (OptionalUnsigned index = m_iddObject.nameFieldIndex()) { |
| 369 | // if so, change the name, or create it | ||
| 370 |
1/1✓ Branch 1 taken 248592 times.
|
248592 | unsigned n = numFields(); |
| 371 |
1/1✓ Branch 1 taken 248592 times.
|
248592 | unsigned i = *index; |
| 372 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 248592 times.
✗ Branch 3 not taken.
|
248592 | OS_ASSERT(i < 2u); |
| 373 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 248590 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
248592 | if (n == 0 && i == 1) { |
| 374 | ✗ | OS_ASSERT(!m_handle.isNull()); | |
| 375 | ✗ | m_fields.push_back(toString(m_handle)); | |
| 376 | ✗ | m_diffs.push_back(IdfObjectDiff(0u, boost::none, m_fields.back())); | |
| 377 | } | ||
| 378 |
1/1✓ Branch 1 taken 248592 times.
|
248592 | n = numFields(); |
| 379 |
2/2✓ Branch 0 taken 244391 times.
✓ Branch 1 taken 4201 times.
|
248592 | if (i < n) { |
| 380 |
1/1✓ Branch 2 taken 244391 times.
|
244391 | std::string oldName = m_fields[i]; |
| 381 |
1/1✓ Branch 2 taken 244391 times.
|
244391 | m_fields[i] = newName; |
| 382 |
5/5✓ Branch 1 taken 244391 times.
✓ Branch 4 taken 244391 times.
✓ Branch 7 taken 244391 times.
✓ Branch 10 taken 244391 times.
✓ Branch 13 taken 244391 times.
|
244391 | m_diffs.push_back(IdfObjectDiff(i, oldName, newName)); |
| 383 | 244391 | } else { | |
| 384 |
1/1✓ Branch 1 taken 4201 times.
|
4201 | m_fields.push_back(newName); |
| 385 |
4/4✓ Branch 1 taken 4201 times.
✓ Branch 5 taken 4201 times.
✓ Branch 8 taken 4201 times.
✓ Branch 11 taken 4201 times.
|
4201 | m_diffs.push_back(IdfObjectDiff(i, boost::none, newName)); |
| 386 | } | ||
| 387 | //return decoded string since we might have made changes to it if its an EMS object. | ||
| 388 |
1/1✓ Branch 1 taken 248592 times.
|
248592 | newName = decodeString(newName); |
| 389 |
1/1✓ Branch 1 taken 248592 times.
|
248592 | return newName; // success! |
| 390 | } | ||
| 391 | 3 | return boost::none; // no name | |
| 392 | 248595 | } | |
| 393 | |||
| 394 | ✗ | boost::optional<std::string> IdfObject_Impl::createName() { | |
| 395 | ✗ | return IdfObject_Impl::createName(true); | |
| 396 | } | ||
| 397 | |||
| 398 | 2 | boost::optional<std::string> IdfObject_Impl::createName(bool overwrite) { | |
| 399 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
4 | if (OptionalUnsigned index = m_iddObject.nameFieldIndex()) { |
| 400 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalString oName = name(); |
| 401 |
7/9✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✓ Branch 12 taken 1 time.
|
2 | if (!oName || oName->empty() || overwrite) { |
| 402 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::string newName = createUniqueName(m_iddObject.name()); |
| 403 |
1/1✓ Branch 1 taken 1 time.
|
1 | return setName(newName); |
| 404 | 1 | } | |
| 405 | 2 | } | |
| 406 | 1 | return boost::none; | |
| 407 | } | ||
| 408 | |||
| 409 | 1084557 | bool IdfObject_Impl::setString(unsigned index, const std::string& value) { | |
| 410 | 1084557 | bool result = IdfObject_Impl::setString(index, value, true); | |
| 411 |
2/2✓ Branch 0 taken 1084555 times.
✓ Branch 1 taken 2 times.
|
1084557 | if (result) { |
| 412 | 1084555 | this->emitChangeSignals(); | |
| 413 | } | ||
| 414 | 1084557 | return result; | |
| 415 | } | ||
| 416 | |||
| 417 | 4643950 | bool IdfObject_Impl::setString(unsigned index, const std::string& _value, bool checkValidity) { | |
| 418 |
1/1✓ Branch 1 taken 4643950 times.
|
4643950 | std::string value = encodeString(_value); |
| 419 | |||
| 420 |
9/9✓ Branch 1 taken 4643950 times.
✓ Branch 3 taken 3905401 times.
✓ Branch 4 taken 738549 times.
✓ Branch 6 taken 3905401 times.
✓ Branch 9 taken 3905401 times.
✓ Branch 11 taken 14274 times.
✓ Branch 12 taken 3891127 times.
✓ Branch 13 taken 14274 times.
✓ Branch 14 taken 4629676 times.
|
4643950 | if (m_iddObject.hasNameField() && (index == m_iddObject.nameFieldIndex().get())) { |
| 421 |
1/1✓ Branch 1 taken 14274 times.
|
14274 | return IdfObject_Impl::setName(value, checkValidity).has_value(); |
| 422 | } | ||
| 423 | |||
| 424 | // push fields and groups if necessary and possible | ||
| 425 |
8/8✓ Branch 1 taken 4629676 times.
✓ Branch 3 taken 1676229 times.
✓ Branch 4 taken 2953447 times.
✓ Branch 6 taken 1676229 times.
✓ Branch 8 taken 1676226 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 4629673 times.
✓ Branch 11 taken 3 times.
|
4629676 | if (m_iddObject.isNonextensibleField(index) || m_iddObject.isExtensibleField(index)) { |
| 426 | 4629673 | bool result = true; | |
| 427 | 4629673 | boost::optional<std::string> oldValue; | |
| 428 | 4629673 | unsigned n = m_fields.size(); | |
| 429 | 4629673 | unsigned nn = n; | |
| 430 | 4629673 | unsigned diffSize = m_diffs.size(); | |
| 431 |
1/1✓ Branch 1 taken 4629673 times.
|
4629673 | unsigned iddn = m_iddObject.numFields(); |
| 432 | |||
| 433 |
2/2✓ Branch 1 taken 379600 times.
✓ Branch 2 taken 4250073 times.
|
4629673 | if (index >= m_fields.size()) { |
| 434 |
5/6✓ Branch 0 taken 689957 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 390922 times.
✓ Branch 3 taken 299035 times.
✓ Branch 4 taken 310357 times.
✓ Branch 5 taken 80565 times.
|
689957 | while (result && (index >= nn) && (nn < iddn)) { |
| 435 | // push regular fields | ||
| 436 |
3/5✓ Branch 0 taken 310357 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 310357 times.
✓ Branch 5 taken 310357 times.
✗ Branch 6 not taken.
|
310357 | result = result && this->pushString(checkValidity); |
| 437 | 310357 | nn = m_fields.size(); | |
| 438 | } | ||
| 439 |
3/4✓ Branch 0 taken 460165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80565 times.
✓ Branch 3 taken 379600 times.
|
460165 | while (result && (index >= nn)) { |
| 440 | // push extensible fields | ||
| 441 |
6/14✓ Branch 0 taken 80565 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 80565 times.
✓ Branch 7 taken 80565 times.
✓ Branch 9 taken 80565 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 80565 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 80565 times.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
80565 | result = result && !this->pushExtensibleGroup(StringVector(), checkValidity).empty(); |
| 442 | 80565 | nn = m_fields.size(); | |
| 443 | } | ||
| 444 | } else { | ||
| 445 |
1/1✓ Branch 2 taken 4250073 times.
|
4250073 | oldValue = m_fields[index]; |
| 446 | } | ||
| 447 | |||
| 448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4629673 times.
|
4629673 | if (!result) { |
| 449 | // remove diffs | ||
| 450 | ✗ | m_diffs.resize(diffSize); | |
| 451 | |||
| 452 | // resize fields | ||
| 453 | ✗ | m_fields.resize(n); | |
| 454 | ✗ | if (m_fieldComments.size() > n) { | |
| 455 | ✗ | m_fieldComments.resize(n); | |
| 456 | } | ||
| 457 | |||
| 458 | ✗ | return false; | |
| 459 | } | ||
| 460 | |||
| 461 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4629673 times.
✗ Branch 4 not taken.
|
4629673 | OS_ASSERT(index < m_fields.size()); |
| 462 | |||
| 463 |
1/1✓ Branch 2 taken 4629673 times.
|
4629673 | m_fields[index] = value; |
| 464 |
1/1✓ Branch 1 taken 4629673 times.
|
4629673 | m_diffs.emplace_back(index, oldValue, value); |
| 465 | 4629673 | return result; | |
| 466 | 4629673 | } | |
| 467 | 3 | return false; | |
| 468 | 4643950 | } | |
| 469 | |||
| 470 | 440679 | bool IdfObject_Impl::setDouble(unsigned index, double value) { | |
| 471 | 440679 | bool result = setDouble(index, value, true); | |
| 472 |
2/2✓ Branch 0 taken 440234 times.
✓ Branch 1 taken 445 times.
|
440679 | if (result) { |
| 473 | 440234 | this->emitChangeSignals(); | |
| 474 | } | ||
| 475 | 440679 | return result; | |
| 476 | } | ||
| 477 | |||
| 478 | 445160 | bool IdfObject_Impl::setDouble(unsigned index, double value, bool checkValidity) { | |
| 479 | try { | ||
| 480 |
2/2✓ Branch 1 taken 445160 times.
✓ Branch 4 taken 445160 times.
|
445160 | return setString(index, toString(value), checkValidity); |
| 481 | ✗ | } catch (...) { | |
| 482 | ✗ | return false; | |
| 483 | ✗ | } | |
| 484 | } | ||
| 485 | |||
| 486 | 1 | bool IdfObject_Impl::setQuantity(unsigned index, const Quantity& q) { | |
| 487 | 1 | bool result = setQuantity(index, q, true); | |
| 488 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (result) { |
| 489 | 1 | this->emitChangeSignals(); | |
| 490 | } | ||
| 491 | 1 | return result; | |
| 492 | } | ||
| 493 | |||
| 494 | 1 | bool IdfObject_Impl::setQuantity(unsigned index, const Quantity& q, bool checkValidity) { | |
| 495 |
1/1✓ Branch 1 taken 1 time.
|
1 | OptionalDouble value = getDoubleFromQuantity(index, q); |
| 496 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | if (!value) { |
| 497 | ✗ | return false; | |
| 498 | } | ||
| 499 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return setDouble(index, *value, checkValidity); |
| 500 | } | ||
| 501 | |||
| 502 | 51167 | bool IdfObject_Impl::setUnsigned(unsigned index, unsigned value) { | |
| 503 | 51167 | bool result = setUnsigned(index, value, true); | |
| 504 |
2/2✓ Branch 0 taken 51166 times.
✓ Branch 1 taken 1 time.
|
51167 | if (result) { |
| 505 | 51166 | this->emitChangeSignals(); | |
| 506 | } | ||
| 507 | 51167 | return result; | |
| 508 | } | ||
| 509 | |||
| 510 | 51167 | bool IdfObject_Impl::setUnsigned(unsigned index, unsigned value, bool checkValidity) { | |
| 511 | try { | ||
| 512 |
1/1✓ Branch 1 taken 51167 times.
|
51167 | auto str = boost::lexical_cast<std::string>(value); |
| 513 |
1/1✓ Branch 1 taken 51167 times.
|
51167 | return setString(index, str, checkValidity); |
| 514 | 51167 | } catch (...) { | |
| 515 | ✗ | return false; | |
| 516 | ✗ | } | |
| 517 | } | ||
| 518 | |||
| 519 | 36883 | bool IdfObject_Impl::setInt(unsigned index, int value) { | |
| 520 | 36883 | bool result = setInt(index, value, true); | |
| 521 |
2/2✓ Branch 0 taken 36830 times.
✓ Branch 1 taken 53 times.
|
36883 | if (result) { |
| 522 | 36830 | this->emitChangeSignals(); | |
| 523 | } | ||
| 524 | 36883 | return result; | |
| 525 | } | ||
| 526 | |||
| 527 | 43697 | bool IdfObject_Impl::setInt(unsigned index, int value, bool checkValidity) { | |
| 528 | try { | ||
| 529 |
1/1✓ Branch 1 taken 43697 times.
|
43697 | auto str = boost::lexical_cast<std::string>(value); |
| 530 |
1/1✓ Branch 1 taken 43697 times.
|
43697 | return setString(index, str, checkValidity); |
| 531 | 43697 | } catch (...) { | |
| 532 | ✗ | return false; | |
| 533 | ✗ | } | |
| 534 | } | ||
| 535 | |||
| 536 | ✗ | bool IdfObject_Impl::pushString() { | |
| 537 | ✗ | bool result = IdfObject_Impl::pushString(std::string(), true); | |
| 538 | ✗ | if (result) { | |
| 539 | ✗ | this->emitChangeSignals(); | |
| 540 | } | ||
| 541 | ✗ | return result; | |
| 542 | } | ||
| 543 | |||
| 544 | 342113 | bool IdfObject_Impl::pushString(bool checkValidity) { | |
| 545 |
1/1✓ Branch 2 taken 342113 times.
|
342113 | return IdfObject_Impl::pushString(std::string(), checkValidity); |
| 546 | } | ||
| 547 | |||
| 548 | ✗ | bool IdfObject_Impl::pushString(const std::string& value) { | |
| 549 | ✗ | bool result = IdfObject_Impl::pushString(value, true); | |
| 550 | ✗ | if (result) { | |
| 551 | ✗ | this->emitChangeSignals(); | |
| 552 | } | ||
| 553 | ✗ | return result; | |
| 554 | } | ||
| 555 | |||
| 556 | 477090 | bool IdfObject_Impl::pushString(const std::string& value, bool checkValidity) { | |
| 557 | // get new index | ||
| 558 | 477090 | unsigned index = m_fields.size(); | |
| 559 |
7/9✓ Branch 1 taken 477090 times.
✓ Branch 3 taken 342127 times.
✓ Branch 4 taken 134963 times.
✓ Branch 6 taken 342127 times.
✓ Branch 9 taken 342127 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 342127 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 477090 times.
|
477090 | if (m_iddObject.hasNameField() && (index == m_iddObject.nameFieldIndex().get())) { |
| 560 | ✗ | return IdfObject_Impl::setName(value, checkValidity).has_value(); | |
| 561 | } | ||
| 562 | |||
| 563 | // ok if nonextensible, or extensible w/ group size 1 | ||
| 564 |
10/11✓ Branch 1 taken 477090 times.
✓ Branch 3 taken 738 times.
✓ Branch 4 taken 476352 times.
✓ Branch 6 taken 738 times.
✓ Branch 8 taken 738 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 738 times.
✓ Branch 13 taken 735 times.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 477087 times.
✓ Branch 16 taken 3 times.
|
477090 | if (m_iddObject.isNonextensibleField(index) || (m_iddObject.isExtensibleField(index) && (m_iddObject.properties().numExtensible == 1))) { |
| 565 |
1/1✓ Branch 1 taken 477087 times.
|
477087 | m_fields.push_back(value); |
| 566 |
4/4✓ Branch 1 taken 477087 times.
✓ Branch 5 taken 477087 times.
✓ Branch 8 taken 477087 times.
✓ Branch 11 taken 477087 times.
|
477087 | m_diffs.push_back(IdfObjectDiff(index, boost::none, value)); |
| 567 | 477087 | return true; | |
| 568 | } | ||
| 569 | 3 | return false; | |
| 570 | } | ||
| 571 | |||
| 572 | 67377 | IdfExtensibleGroup IdfObject_Impl::pushExtensibleGroup(const std::vector<std::string>& values) { | |
| 573 | 67377 | IdfExtensibleGroup result = IdfObject_Impl::pushExtensibleGroup(values, true); | |
| 574 |
3/3✓ Branch 1 taken 67377 times.
✓ Branch 3 taken 67350 times.
✓ Branch 4 taken 27 times.
|
67377 | if (!result.empty()) { |
| 575 |
1/1✓ Branch 1 taken 67350 times.
|
67350 | this->emitChangeSignals(); |
| 576 | } | ||
| 577 | 67377 | return result; | |
| 578 | ✗ | } | |
| 579 | |||
| 580 | 512137 | IdfExtensibleGroup IdfObject_Impl::pushExtensibleGroup(const std::vector<std::string>& values, bool checkValidity) { | |
| 581 |
1/1✓ Branch 1 taken 512137 times.
|
512137 | unsigned groupSize = m_iddObject.properties().numExtensible; |
| 582 |
1/1✓ Branch 1 taken 512137 times.
|
512137 | unsigned n = numFields(); |
| 583 | 512137 | IdfObject_ImplPtr p = nullptr; | |
| 584 |
1/1✓ Branch 2 taken 512137 times.
|
512137 | IdfExtensibleGroup result(p, n); |
| 585 | |||
| 586 |
6/6✓ Branch 1 taken 383167 times.
✓ Branch 2 taken 128970 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 383165 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 512135 times.
|
512137 | if (!values.empty() && (values.size() != groupSize)) { |
| 587 | 2 | return result; | |
| 588 | } | ||
| 589 | |||
| 590 |
1/1✓ Branch 1 taken 512135 times.
|
512135 | StringVector wValues = values; // copy so can resize empty vector |
| 591 |
1/1✓ Branch 1 taken 512135 times.
|
512135 | OptionalUnsigned mf = maxFields(); |
| 592 | 512135 | unsigned diffSize = m_diffs.size(); | |
| 593 | |||
| 594 | // push fields as needed | ||
| 595 |
1/1✓ Branch 1 taken 512135 times.
|
512135 | unsigned iddn = m_iddObject.numFields(); |
| 596 |
2/2✓ Branch 0 taken 9073 times.
✓ Branch 1 taken 503062 times.
|
512135 | if (n < iddn) { |
| 597 |
2/2✓ Branch 1 taken 9073 times.
✓ Branch 4 taken 9073 times.
|
18146 | bool ok = this->setString(iddn - 1, "", checkValidity); |
| 598 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9073 times.
|
9073 | if (!ok) { |
| 599 | // remove the diffs | ||
| 600 | ✗ | m_diffs.resize(diffSize); | |
| 601 | |||
| 602 | // resize the fields | ||
| 603 | ✗ | m_fields.resize(n); | |
| 604 | ✗ | if (m_fieldComments.size() > n) { | |
| 605 | ✗ | m_fieldComments.resize(n); | |
| 606 | } | ||
| 607 | ✗ | return result; | |
| 608 | } | ||
| 609 | } | ||
| 610 | |||
| 611 |
1/1✓ Branch 1 taken 512135 times.
|
512135 | n = numFields(); |
| 612 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 512135 times.
✗ Branch 3 not taken.
|
512135 | OS_ASSERT(n >= iddn); |
| 613 | |||
| 614 | // needs to be extensible, have all non-extensible fields defined, and not violate maxFields. | ||
| 615 |
9/9✓ Branch 0 taken 512133 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 11304 times.
✓ Branch 4 taken 500829 times.
✓ Branch 6 taken 11304 times.
✓ Branch 8 taken 11284 times.
✓ Branch 9 taken 20 times.
✓ Branch 10 taken 512113 times.
✓ Branch 11 taken 22 times.
|
512135 | if ((groupSize > 0) && (!mf || (n + groupSize <= *mf))) { |
| 616 | |||
| 617 |
2/4✓ Branch 1 taken 512113 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 512113 times.
✗ Branch 6 not taken.
|
512113 | OS_ASSERT(m_iddObject.properties().extensible); |
| 618 | |||
| 619 |
2/2✓ Branch 1 taken 128948 times.
✓ Branch 2 taken 383165 times.
|
512113 | if (wValues.empty()) { |
| 620 |
1/1✓ Branch 1 taken 128948 times.
|
128948 | wValues.resize(groupSize); |
| 621 | } | ||
| 622 | |||
| 623 |
1/1✓ Branch 1 taken 512113 times.
|
512113 | m_fields.resize(n + groupSize); |
| 624 | |||
| 625 |
2/2✓ Branch 0 taken 1352144 times.
✓ Branch 1 taken 512109 times.
|
1864253 | for (unsigned i = 0; i < groupSize; ++i) { |
| 626 | |||
| 627 |
1/1✓ Branch 2 taken 1352144 times.
|
1352144 | bool ok = setString(n + i, wValues[i], checkValidity); |
| 628 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1352140 times.
|
1352144 | if (!ok) { |
| 629 | // remove the diffs | ||
| 630 |
1/1✓ Branch 1 taken 4 times.
|
4 | m_diffs.resize(diffSize); |
| 631 | |||
| 632 | // resize the fields | ||
| 633 |
1/1✓ Branch 1 taken 4 times.
|
4 | m_fields.resize(n); |
| 634 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (m_fieldComments.size() > n) { |
| 635 | ✗ | m_fieldComments.resize(n); | |
| 636 | } | ||
| 637 | 4 | return result; | |
| 638 | } | ||
| 639 | } | ||
| 640 | |||
| 641 |
2/2✓ Branch 1 taken 512109 times.
✓ Branch 4 taken 512109 times.
|
512109 | result = getExtensibleGroup(numExtensibleGroups() - 1); |
| 642 |
2/4✓ Branch 1 taken 512109 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 512109 times.
✗ Branch 6 not taken.
|
512109 | OS_ASSERT(!result.empty()); |
| 643 |
3/5✓ Branch 1 taken 512109 times.
✓ Branch 4 taken 512109 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 512109 times.
✗ Branch 9 not taken.
|
512109 | OS_ASSERT(result.groupIndex() == m_iddObject.extensibleIndex(n).group); |
| 644 | } | ||
| 645 | |||
| 646 | 512131 | return result; | |
| 647 | 512137 | } | |
| 648 | |||
| 649 | 35204 | IdfExtensibleGroup IdfObject_Impl::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values) { | |
| 650 | 35204 | IdfExtensibleGroup result = insertExtensibleGroup(groupIndex, values, true); | |
| 651 |
3/3✓ Branch 1 taken 35204 times.
✓ Branch 3 taken 35200 times.
✓ Branch 4 taken 4 times.
|
35204 | if (!result.empty()) { |
| 652 |
1/1✓ Branch 1 taken 35200 times.
|
35200 | this->emitChangeSignals(); |
| 653 | } | ||
| 654 | 35204 | return result; | |
| 655 | ✗ | } | |
| 656 | |||
| 657 | 35204 | IdfExtensibleGroup IdfObject_Impl::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values, bool checkValidity) { | |
| 658 | // if really a push request, send it there | ||
| 659 |
3/3✓ Branch 1 taken 35204 times.
✓ Branch 3 taken 12323 times.
✓ Branch 4 taken 22881 times.
|
35204 | if (groupIndex == numExtensibleGroups()) { |
| 660 |
1/1✓ Branch 1 taken 12323 times.
|
12323 | return pushExtensibleGroup(values, checkValidity); |
| 661 | } | ||
| 662 | |||
| 663 | // now have groupIndex != numExtensibleGroups() | ||
| 664 |
1/1✓ Branch 1 taken 22881 times.
|
22881 | unsigned groupSize = m_iddObject.properties().numExtensible; |
| 665 |
1/1✓ Branch 1 taken 22881 times.
|
22881 | unsigned n = numFields(); |
| 666 | 22881 | IdfObject_ImplPtr p; | |
| 667 |
1/1✓ Branch 2 taken 22881 times.
|
22881 | IdfExtensibleGroup result(p, n); |
| 668 | // nothing to do if not extensible, groupIndex invalid, or values invalid | ||
| 669 |
6/7✓ Branch 0 taken 22881 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 22881 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 22879 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 22879 times.
|
22881 | if ((groupSize == 0) || (groupIndex > numExtensibleGroups())) { |
| 670 | 2 | return result; | |
| 671 | } | ||
| 672 |
4/6✓ Branch 1 taken 22858 times.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 22858 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 22879 times.
|
22879 | if (!values.empty() && (values.size() != groupSize)) { |
| 673 | ✗ | return result; | |
| 674 | } | ||
| 675 | |||
| 676 | // record diffs at start | ||
| 677 | 22879 | unsigned diffSize = m_diffs.size(); | |
| 678 | |||
| 679 | // from now on, groupIndex < numExtensibleGroups(), and numExtensibleGroups() > 0 | ||
| 680 |
1/1✓ Branch 1 taken 22879 times.
|
22879 | OptionalUnsigned mf = maxFields(); |
| 681 | // needs to have all non-extensible fields defined, and not violate maxFields. | ||
| 682 |
7/10✓ Branch 1 taken 22879 times.
✓ Branch 3 taken 22879 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 26 times.
✓ Branch 7 taken 22853 times.
✓ Branch 9 taken 26 times.
✓ Branch 11 taken 26 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 22879 times.
✗ Branch 14 not taken.
|
22879 | if ((n >= m_iddObject.numFields()) && (!mf || (n + groupSize <= *mf))) { |
| 683 |
2/4✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
✗ Branch 6 not taken.
|
22879 | OS_ASSERT(m_iddObject.properties().extensible); |
| 684 | |||
| 685 |
1/1✓ Branch 1 taken 22879 times.
|
22879 | StringVector wValues = values; |
| 686 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 22858 times.
|
22879 | if (wValues.empty()) { |
| 687 |
1/1✓ Branch 1 taken 21 times.
|
21 | wValues.resize(groupSize); |
| 688 | } | ||
| 689 | |||
| 690 | // push a new group on the end | ||
| 691 |
1/1✓ Branch 1 taken 22879 times.
|
22879 | unsigned i = numExtensibleGroups() - 1; |
| 692 |
1/1✓ Branch 1 taken 22879 times.
|
22879 | IdfExtensibleGroup eg = getExtensibleGroup(i); |
| 693 |
2/4✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
✗ Branch 6 not taken.
|
22879 | OS_ASSERT(!eg.empty()); |
| 694 |
2/2✓ Branch 1 taken 22879 times.
✓ Branch 4 taken 22879 times.
|
22879 | IdfExtensibleGroup temp = pushExtensibleGroup(eg.fieldsWithHandles(), checkValidity); |
| 695 |
2/3✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
|
22879 | if (temp.empty()) { |
| 696 | ✗ | OS_ASSERT(numFields() == n); | |
| 697 | ✗ | OS_ASSERT(m_diffs.size() == diffSize); | |
| 698 | |||
| 699 | ✗ | return result; | |
| 700 | } | ||
| 701 | |||
| 702 | // copy values from group i to i+1 down to and including groupIndex | ||
| 703 | 22879 | bool ok = true; | |
| 704 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 22879 times.
|
22896 | while (i > groupIndex) { |
| 705 | 17 | --i; | |
| 706 |
1/1✓ Branch 1 taken 17 times.
|
17 | IdfExtensibleGroup peg = getExtensibleGroup(i); |
| 707 |
2/4✓ Branch 1 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 6 not taken.
|
17 | OS_ASSERT(!peg.empty()); |
| 708 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | ok = eg.setFields(peg.fieldsWithHandles(), false); |
| 709 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (!ok) { |
| 710 | // roll back | ||
| 711 | ✗ | i += 2; | |
| 712 | ✗ | while (i < numExtensibleGroups() - 1) { | |
| 713 | ✗ | peg = getExtensibleGroup(i); | |
| 714 | ✗ | OS_ASSERT(!peg.empty()); | |
| 715 | ✗ | eg = getExtensibleGroup(i + 1); | |
| 716 | ✗ | OS_ASSERT(!eg.empty()); | |
| 717 | ✗ | peg.setFields(eg.fieldsWithHandles(), false); | |
| 718 | ✗ | ++i; | |
| 719 | } | ||
| 720 | ✗ | popExtensibleGroup(false); | |
| 721 | |||
| 722 | // remove the diffs | ||
| 723 | ✗ | m_diffs.resize(diffSize); | |
| 724 | |||
| 725 | ✗ | return result; | |
| 726 | } | ||
| 727 | 17 | eg = peg; | |
| 728 | 17 | } | |
| 729 | |||
| 730 | // now set the values at this group index | ||
| 731 |
1/1✓ Branch 1 taken 22879 times.
|
22879 | ok = eg.setFields(wValues, checkValidity); |
| 732 | |||
| 733 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 22878 times.
|
22879 | if (!ok) { |
| 734 | 1 | i = groupIndex + 1; | |
| 735 |
1/1✓ Branch 1 taken 1 time.
|
1 | IdfExtensibleGroup peg = getExtensibleGroup(i); |
| 736 |
2/4✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
|
1 | OS_ASSERT(!peg.empty()); |
| 737 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | while (i < numExtensibleGroups() - 1) { |
| 738 | 1 | ++i; | |
| 739 |
1/1✓ Branch 1 taken 1 time.
|
1 | eg = getExtensibleGroup(i); |
| 740 |
2/4✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
|
1 | OS_ASSERT(!eg.empty()); |
| 741 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | peg.setFields(eg.fieldsWithHandles(), false); |
| 742 | 1 | peg = eg; | |
| 743 | } | ||
| 744 |
1/1✓ Branch 1 taken 1 time.
|
1 | popExtensibleGroup(false); |
| 745 | |||
| 746 | // remove the diffs | ||
| 747 |
1/1✓ Branch 1 taken 1 time.
|
1 | m_diffs.resize(diffSize); |
| 748 | |||
| 749 | 1 | return result; | |
| 750 | 1 | } | |
| 751 | |||
| 752 | 22878 | result = eg; | |
| 753 |
2/4✓ Branch 1 taken 22878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22878 times.
✗ Branch 6 not taken.
|
22878 | OS_ASSERT(!result.empty()); |
| 754 |
2/4✓ Branch 1 taken 22878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22878 times.
✗ Branch 6 not taken.
|
22878 | OS_ASSERT(numFields() == n + groupSize); |
| 755 | 22881 | } | |
| 756 | |||
| 757 | 22878 | return result; | |
| 758 | 22881 | } | |
| 759 | |||
| 760 | 4 | std::vector<std::string> IdfObject_Impl::popExtensibleGroup() { | |
| 761 | 4 | StringVector result = IdfObject_Impl::popExtensibleGroup(true); | |
| 762 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
|
4 | if (!result.empty()) { |
| 763 |
1/1✓ Branch 1 taken 3 times.
|
3 | this->emitChangeSignals(); |
| 764 | } | ||
| 765 | 4 | return result; | |
| 766 | ✗ | } | |
| 767 | |||
| 768 | /** Pops the final extensible group from the object, if possible. Returns the popped data if | ||
| 769 | * successful. Otherwise, the returned vector will be empty. */ | ||
| 770 | 107753 | std::vector<std::string> IdfObject_Impl::popExtensibleGroup(bool /*checkValidity*/) { | |
| 771 | |||
| 772 | 107753 | unsigned groupSize = m_iddObject.properties().numExtensible; | |
| 773 | 107753 | unsigned numBeforePop = numFields(); | |
| 774 | 107753 | unsigned numAfterPop = numBeforePop - groupSize; | |
| 775 | 107753 | StringVector result; | |
| 776 | // must be extensible object, with some extensible fields | ||
| 777 |
7/7✓ Branch 0 taken 107739 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 107739 times.
✓ Branch 5 taken 107043 times.
✓ Branch 6 taken 696 times.
✓ Branch 7 taken 107043 times.
✓ Branch 8 taken 710 times.
|
107753 | if ((groupSize > 0) && (numAfterPop >= m_iddObject.numFields())) { |
| 778 |
2/2✓ Branch 1 taken 107043 times.
✓ Branch 4 taken 107043 times.
|
107043 | IdfExtensibleGroup egToPop = getExtensibleGroup(numExtensibleGroups() - 1); |
| 779 |
2/4✓ Branch 1 taken 107043 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 107043 times.
✗ Branch 6 not taken.
|
107043 | OS_ASSERT(!egToPop.empty()); |
| 780 |
1/1✓ Branch 1 taken 107043 times.
|
107043 | UnsignedVector indices = egToPop.mf_indices(); |
| 781 |
1/1✓ Branch 1 taken 107043 times.
|
107043 | result = egToPop.fieldsWithHandles(); |
| 782 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 107043 times.
✗ Branch 4 not taken.
|
107043 | OS_ASSERT(result.size() == groupSize); |
| 783 | |||
| 784 | // record diffs for each field going backwards | ||
| 785 |
2/2✓ Branch 0 taken 318958 times.
✓ Branch 1 taken 107043 times.
|
426001 | for (unsigned i = 0; i < groupSize; ++i) { |
| 786 |
4/4✓ Branch 3 taken 318958 times.
✓ Branch 6 taken 318958 times.
✓ Branch 9 taken 318958 times.
✓ Branch 12 taken 318958 times.
|
318958 | m_diffs.push_back(IdfObjectDiff(numBeforePop - 1 - i, result[i], boost::none)); |
| 787 | } | ||
| 788 | |||
| 789 |
1/1✓ Branch 1 taken 107043 times.
|
107043 | m_fields.resize(numAfterPop); |
| 790 |
2/2✓ Branch 2 taken 10 times.
✓ Branch 3 taken 107033 times.
|
107043 | if (m_fieldComments.size() > m_fields.size()) { |
| 791 |
1/1✓ Branch 1 taken 10 times.
|
10 | m_fieldComments.resize(numAfterPop); |
| 792 | } | ||
| 793 |
2/4✓ Branch 1 taken 107043 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 107043 times.
✗ Branch 6 not taken.
|
107043 | OS_ASSERT(egToPop.empty()); |
| 794 | 107043 | } | |
| 795 | |||
| 796 | 107753 | return result; | |
| 797 | ✗ | } | |
| 798 | |||
| 799 | /** Erases the extensible group at groupIndex, if possible. Returns the erased data, and | ||
| 800 | * preserves the relative order of the remaining data if successful. Otherwise, the returned | ||
| 801 | * vector will be empty. */ | ||
| 802 | 415 | std::vector<std::string> IdfObject_Impl::eraseExtensibleGroup(unsigned groupIndex) { | |
| 803 | 415 | StringVector result = eraseExtensibleGroup(groupIndex, true); | |
| 804 |
2/2✓ Branch 1 taken 414 times.
✓ Branch 2 taken 1 time.
|
415 | if (!result.empty()) { |
| 805 |
1/1✓ Branch 1 taken 414 times.
|
414 | this->emitChangeSignals(); |
| 806 | } | ||
| 807 | 415 | return result; | |
| 808 | ✗ | } | |
| 809 | |||
| 810 | 415 | std::vector<std::string> IdfObject_Impl::eraseExtensibleGroup(unsigned groupIndex, bool checkValidity) { | |
| 811 | 415 | StringVector result; | |
| 812 |
3/3✓ Branch 1 taken 415 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 414 times.
|
415 | if (groupIndex >= numExtensibleGroups()) { |
| 813 | 1 | return result; | |
| 814 | } | ||
| 815 |
2/2✓ Branch 1 taken 414 times.
✓ Branch 4 taken 414 times.
|
414 | UnsignedVector indices = getExtensibleGroup(groupIndex).mf_indices(); |
| 816 | |||
| 817 | // start at bottom | ||
| 818 |
1/1✓ Branch 1 taken 414 times.
|
414 | result = popExtensibleGroup(false); |
| 819 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
|
414 | if (result.empty()) { |
| 820 | ✗ | return result; | |
| 821 | } | ||
| 822 | |||
| 823 | // record diffs at start | ||
| 824 | 414 | unsigned diffSize = m_diffs.size(); | |
| 825 | |||
| 826 | 414 | bool ok = true; | |
| 827 | // pop was successful. roll up until overwrite groupIndex | ||
| 828 |
3/3✓ Branch 1 taken 414 times.
✓ Branch 3 taken 183 times.
✓ Branch 4 taken 414 times.
|
597 | for (int i = numExtensibleGroups() - 1; i >= static_cast<int>(groupIndex); --i) { |
| 829 |
1/1✓ Branch 1 taken 183 times.
|
183 | StringVector temp = result; |
| 830 |
1/1✓ Branch 1 taken 183 times.
|
183 | IdfExtensibleGroup eg = getExtensibleGroup(i); |
| 831 |
2/4✓ Branch 1 taken 183 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 183 times.
✗ Branch 6 not taken.
|
183 | OS_ASSERT(!eg.empty()); |
| 832 |
1/1✓ Branch 1 taken 183 times.
|
183 | result = eg.fieldsWithHandles(); |
| 833 |
1/1✓ Branch 1 taken 183 times.
|
183 | ok = eg.setFields(temp, checkValidity); |
| 834 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
|
183 | if (!ok) { |
| 835 | // roll back changes and return | ||
| 836 | ✗ | for (unsigned j = i + 1, n = numExtensibleGroups(); j < n; ++j) { | |
| 837 | ✗ | eg = getExtensibleGroup(j); | |
| 838 | ✗ | OS_ASSERT(!eg.empty()); | |
| 839 | ✗ | result = eg.fieldsWithHandles(); | |
| 840 | ✗ | OS_ASSERT(result.size() == temp.size()); | |
| 841 | ✗ | eg.setFields(temp, false); | |
| 842 | ✗ | temp = result; | |
| 843 | } | ||
| 844 | ✗ | eg = pushExtensibleGroup(temp, false); | |
| 845 | ✗ | OS_ASSERT(!eg.empty()); | |
| 846 | |||
| 847 | // remove the diffs | ||
| 848 | ✗ | m_diffs.resize(diffSize); | |
| 849 | |||
| 850 | ✗ | return {}; | |
| 851 | } | ||
| 852 | 183 | } | |
| 853 | |||
| 854 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
✗ Branch 3 not taken.
|
414 | OS_ASSERT(ok); |
| 855 | 414 | return result; | |
| 856 | 415 | } | |
| 857 | |||
| 858 | /** Pops all \link IdfExtensibleGroup IdfExtensibleGroups\endlink from the object, if possible. | ||
| 859 | * Returns popped data if successful. Otherwise, the returned vector will be empty. */ | ||
| 860 | 17986 | std::vector<std::vector<std::string>> IdfObject_Impl::clearExtensibleGroups() { | |
| 861 | 17986 | std::vector<StringVector> result = clearExtensibleGroups(true); | |
| 862 |
2/2✓ Branch 1 taken 5244 times.
✓ Branch 2 taken 12742 times.
|
17986 | if (!result.empty()) { |
| 863 |
1/1✓ Branch 1 taken 5244 times.
|
5244 | this->emitChangeSignals(); |
| 864 | } | ||
| 865 | 17986 | return result; | |
| 866 | ✗ | } | |
| 867 | |||
| 868 | 71429 | std::vector<std::vector<std::string>> IdfObject_Impl::clearExtensibleGroups(bool checkValidity) { | |
| 869 | |||
| 870 | // data to restore if cannot delete all groups | ||
| 871 | 71429 | std::vector<StringVector> rollbackValues; | |
| 872 | 71429 | std::vector<StringVector> rollbackComments; | |
| 873 | |||
| 874 |
1/1✓ Branch 1 taken 71429 times.
|
71429 | unsigned gn = numExtensibleGroups(); |
| 875 |
2/2✓ Branch 0 taken 45095 times.
✓ Branch 1 taken 26334 times.
|
71429 | if (gn == 0) { |
| 876 | 45095 | return rollbackValues; | |
| 877 | } | ||
| 878 | |||
| 879 | // record diffs at start | ||
| 880 | 26334 | unsigned diffSize = m_diffs.size(); | |
| 881 | |||
| 882 | // loop through groups | ||
| 883 | 26334 | UnsignedVector indices; | |
| 884 |
2/2✓ Branch 0 taken 104215 times.
✓ Branch 1 taken 26333 times.
|
130548 | while (gn > 0) { |
| 885 | // get this group's data | ||
| 886 |
1/1✓ Branch 1 taken 104215 times.
|
104215 | IdfExtensibleGroup eg = getExtensibleGroup(gn - 1); |
| 887 |
2/4✓ Branch 1 taken 104215 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104215 times.
✗ Branch 6 not taken.
|
104215 | OS_ASSERT(!eg.empty()); |
| 888 |
2/2✓ Branch 1 taken 26334 times.
✓ Branch 2 taken 77881 times.
|
104215 | if (indices.empty()) { |
| 889 |
1/1✓ Branch 1 taken 26334 times.
|
26334 | indices = eg.mf_indices(); |
| 890 | } | ||
| 891 |
2/2✓ Branch 1 taken 104215 times.
✓ Branch 4 taken 104215 times.
|
104215 | rollbackValues.push_back(eg.fieldsWithHandles()); |
| 892 |
2/2✓ Branch 1 taken 104215 times.
✓ Branch 4 taken 104215 times.
|
104215 | rollbackComments.push_back(eg.fieldComments()); |
| 893 | // try to pop | ||
| 894 |
1/1✓ Branch 1 taken 104215 times.
|
104215 | StringVector result = popExtensibleGroup(checkValidity); |
| 895 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 104214 times.
|
104215 | if (result.empty()) { |
| 896 | // unsuccessful--restore cleared data | ||
| 897 | 1 | rollbackValues.pop_back(); | |
| 898 | 1 | rollbackComments.pop_back(); | |
| 899 |
2/4✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
|
1 | OS_ASSERT(gn == numExtensibleGroups()); |
| 900 | // add back groups already popped | ||
| 901 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | while (!rollbackValues.empty()) { |
| 902 |
1/1✓ Branch 2 taken 1 time.
|
1 | IdfExtensibleGroup pushed = pushExtensibleGroup(rollbackValues.back(), false); |
| 903 | 1 | unsigned fieldIndex = 0; | |
| 904 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for (const std::string& cmnt : rollbackComments.back()) { |
| 905 |
1/1✓ Branch 1 taken 3 times.
|
3 | pushed.setFieldComment(fieldIndex, cmnt); |
| 906 | 3 | ++fieldIndex; | |
| 907 | } | ||
| 908 | 1 | rollbackValues.pop_back(); | |
| 909 | 1 | rollbackComments.pop_back(); | |
| 910 | 1 | } | |
| 911 | |||
| 912 | // remove the diffs | ||
| 913 |
1/1✓ Branch 1 taken 1 time.
|
1 | m_diffs.resize(diffSize); |
| 914 | |||
| 915 | 1 | return rollbackValues; | |
| 916 | } | ||
| 917 | 104214 | --gn; | |
| 918 |
2/4✓ Branch 1 taken 104214 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104214 times.
✗ Branch 6 not taken.
|
104214 | OS_ASSERT(gn == numExtensibleGroups()); |
| 919 | 104216 | } | |
| 920 | |||
| 921 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 26333 times.
✗ Branch 4 not taken.
|
26333 | OS_ASSERT(!rollbackValues.empty()); |
| 922 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 26333 times.
✗ Branch 4 not taken.
|
26333 | OS_ASSERT(!indices.empty()); |
| 923 | |||
| 924 | 26333 | return rollbackValues; | |
| 925 | 71429 | } | |
| 926 | |||
| 927 | 5 | void IdfObject_Impl::initializeFields(bool fill_default) { | |
| 928 |
1/1✓ Branch 1 taken 5 times.
|
5 | const unsigned n = numFields(); |
| 929 |
1/1✓ Branch 1 taken 5 times.
|
5 | const unsigned iddN = m_iddObject.numFields(); |
| 930 | 5 | bool resized = false; | |
| 931 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
|
5 | if (n < iddN) { |
| 932 | 2 | resized = true; | |
| 933 |
1/1✓ Branch 1 taken 2 times.
|
2 | m_fields.resize(iddN); |
| 934 | } | ||
| 935 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
|
5 | if (!fill_default) { |
| 936 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (resized) { |
| 937 |
1/1✓ Branch 1 taken 1 time.
|
1 | this->onChange.nano_emit(); |
| 938 | } | ||
| 939 | 1 | return; | |
| 940 | } | ||
| 941 | |||
| 942 | // Instead of allocating m_diffs, then calling emitChangeSignals which will try to see if there's a name change, | ||
| 943 | // I know there isn't going to be **any** name changes here, so let's be quicker | ||
| 944 | 4 | bool dataChange = false; | |
| 945 | |||
| 946 |
2/2✓ Branch 1 taken 32 times.
✓ Branch 2 taken 4 times.
|
36 | for (unsigned int index = 0; index < std::max(n, iddN); ++index) { |
| 947 |
2/2✓ Branch 2 taken 30 times.
✓ Branch 3 taken 2 times.
|
32 | if (m_fields[index].empty()) { |
| 948 |
1/1✓ Branch 1 taken 30 times.
|
30 | OptionalIddField iddField = m_iddObject.getField(index); |
| 949 |
7/8✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 30 times.
✓ Branch 6 taken 30 times.
✓ Branch 9 taken 20 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 20 times.
✓ Branch 12 taken 10 times.
|
60 | if (iddField && iddField->properties().stringDefault) { |
| 950 |
4/4✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 11 taken 20 times.
|
20 | m_fields[index] = *(iddField->properties().stringDefault); |
| 951 | 20 | dataChange = true; | |
| 952 | // m_diffs.push_back(IdfObjectDiff(index, boost::none, m_fields[index] )); | ||
| 953 | } | ||
| 954 | 30 | } | |
| 955 | } | ||
| 956 | |||
| 957 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
|
4 | if (dataChange) { |
| 958 |
1/1✓ Branch 1 taken 3 times.
|
3 | this->onDataChange.nano_emit(); |
| 959 |
1/1✓ Branch 1 taken 3 times.
|
3 | this->onChange.nano_emit(); |
| 960 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | } else if (resized) { |
| 961 | ✗ | this->onChange.nano_emit(); | |
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | // QUERIES | ||
| 966 | |||
| 967 | 64228593 | unsigned IdfObject_Impl::numFields() const { | |
| 968 | 64228593 | return m_fields.size(); | |
| 969 | } | ||
| 970 | |||
| 971 | 1417663 | unsigned IdfObject_Impl::numNonextensibleFields() const { | |
| 972 | 1417663 | unsigned n = numFields(); | |
| 973 | 1417663 | unsigned iddN = m_iddObject.numFields(); | |
| 974 |
2/2✓ Branch 0 taken 1235902 times.
✓ Branch 1 taken 181761 times.
|
1417663 | if (iddN < n) { |
| 975 | 1235902 | return iddN; | |
| 976 | } | ||
| 977 | 181761 | return n; | |
| 978 | } | ||
| 979 | |||
| 980 | 3488 | unsigned IdfObject_Impl::minFields() const { | |
| 981 | 3488 | return m_iddObject.properties().minFields; | |
| 982 | } | ||
| 983 | |||
| 984 | 540822 | OptionalUnsigned IdfObject_Impl::maxFields() const { | |
| 985 | 540822 | OptionalUnsigned result; | |
| 986 |
3/3✓ Branch 1 taken 540822 times.
✓ Branch 3 taken 4188 times.
✓ Branch 4 taken 536634 times.
|
540822 | if (!m_iddObject.properties().extensible) { |
| 987 |
2/2✓ Branch 1 taken 4188 times.
✓ Branch 5 taken 4188 times.
|
4188 | result = m_iddObject.nonextensibleFields().size(); |
| 988 | } else { | ||
| 989 |
1/1✓ Branch 1 taken 536634 times.
|
536634 | result = m_iddObject.properties().maxFields; |
| 990 | } | ||
| 991 | 540822 | return result; | |
| 992 | } | ||
| 993 | |||
| 994 | 1253713 | unsigned IdfObject_Impl::numExtensibleGroups() const { | |
| 995 | 1253713 | unsigned nExtFields = numFields() - numNonextensibleFields(); | |
| 996 |
2/2✓ Branch 0 taken 150529 times.
✓ Branch 1 taken 1103184 times.
|
1253713 | if (nExtFields == 0) { |
| 997 | 150529 | return 0; | |
| 998 | } | ||
| 999 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1103184 times.
|
1103184 | OS_ASSERT(m_iddObject.properties().extensible); |
| 1000 | 1103184 | unsigned groupSize = m_iddObject.properties().numExtensible; | |
| 1001 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1103184 times.
|
1103184 | OS_ASSERT(nExtFields % groupSize == 0); |
| 1002 | 1103184 | return nExtFields / groupSize; | |
| 1003 | } | ||
| 1004 | |||
| 1005 | ✗ | unsigned IdfObject_Impl::minExtensibleGroups() const { | |
| 1006 | ✗ | return m_iddObject.properties().numExtensibleGroupsRequired; | |
| 1007 | } | ||
| 1008 | |||
| 1009 | ✗ | boost::optional<unsigned> IdfObject_Impl::maxExtensibleGroups() const { | |
| 1010 | ✗ | OptionalUnsigned result = static_cast<unsigned>(0); | |
| 1011 | ✗ | if (!m_iddObject.properties().extensible) { | |
| 1012 | ✗ | return result; | |
| 1013 | } | ||
| 1014 | ✗ | OptionalUnsigned mf = maxFields(); | |
| 1015 | ✗ | if (!mf) { | |
| 1016 | ✗ | return boost::none; | |
| 1017 | } | ||
| 1018 | ✗ | unsigned groupSize = m_iddObject.properties().numExtensible; | |
| 1019 | ✗ | unsigned maxExtFields = *mf - m_iddObject.numFields(); | |
| 1020 | ✗ | OS_ASSERT(maxExtFields % groupSize == 0); | |
| 1021 | ✗ | OS_ASSERT(groupSize > 0); | |
| 1022 | ✗ | result = maxExtFields / groupSize; | |
| 1023 | ✗ | return result; | |
| 1024 | } | ||
| 1025 | |||
| 1026 | 36263 | bool IdfObject_Impl::isObjectListField(unsigned index) const { | |
| 1027 |
2/3✓ Branch 1 taken 36263 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36263 times.
|
36263 | if (index >= numFields()) { |
| 1028 | ✗ | return false; | |
| 1029 | } | ||
| 1030 |
1/1✓ Branch 1 taken 36263 times.
|
36263 | OptionalIddField oIddField = m_iddObject.getField(index); |
| 1031 |
1/2✓ Branch 0 taken 36263 times.
✗ Branch 1 not taken.
|
36263 | if (oIddField) { |
| 1032 |
2/2✓ Branch 1 taken 36263 times.
✓ Branch 4 taken 36263 times.
|
36263 | return oIddField->isObjectListField(); |
| 1033 | } | ||
| 1034 | ✗ | return false; | |
| 1035 | 36263 | } | |
| 1036 | |||
| 1037 | 406488 | std::vector<unsigned> IdfObject_Impl::objectListFields() const { | |
| 1038 | 406488 | UnsignedVector result = m_iddObject.objectListFields(); | |
| 1039 |
1/1✓ Branch 1 taken 406488 times.
|
406488 | result = trimFieldIndices(result); |
| 1040 |
1/1✓ Branch 1 taken 406488 times.
|
406488 | result = repeatExtensibleIndices(result); |
| 1041 | 406488 | return result; | |
| 1042 | ✗ | } | |
| 1043 | |||
| 1044 | 36263 | bool IdfObject_Impl::isDataField(unsigned index) const { | |
| 1045 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 36263 times.
|
36263 | if (index >= numFields()) { |
| 1046 | ✗ | return false; | |
| 1047 | } | ||
| 1048 |
6/6✓ Branch 1 taken 33348 times.
✓ Branch 2 taken 2915 times.
✓ Branch 3 taken 4642 times.
✓ Branch 4 taken 28706 times.
✓ Branch 6 taken 376 times.
✓ Branch 7 taken 4266 times.
|
36263 | return (!isObjectListField(index) && (index > 0 || !m_iddObject.hasHandleField())); |
| 1049 | } | ||
| 1050 | |||
| 1051 | 4642 | std::vector<unsigned> IdfObject_Impl::dataFields() const { | |
| 1052 | 4642 | UnsignedVector result; | |
| 1053 |
3/3✓ Branch 1 taken 4642 times.
✓ Branch 3 taken 36263 times.
✓ Branch 4 taken 4642 times.
|
40905 | for (unsigned i = 0, n = numFields(); i < n; ++i) { |
| 1054 |
3/3✓ Branch 1 taken 36263 times.
✓ Branch 3 taken 29082 times.
✓ Branch 4 taken 7181 times.
|
36263 | if (isDataField(i)) { |
| 1055 |
1/1✓ Branch 1 taken 29082 times.
|
29082 | result.push_back(i); |
| 1056 | } | ||
| 1057 | } | ||
| 1058 | 4642 | return result; | |
| 1059 | ✗ | } | |
| 1060 | |||
| 1061 | ✗ | UnsignedVector IdfObject_Impl::requiredFields() const { | |
| 1062 | ✗ | UnsignedVector result; | |
| 1063 | ✗ | for (unsigned index = 0; index < m_fields.size(); ++index) { | |
| 1064 | ✗ | OptionalIddField field = m_iddObject.getField(index); | |
| 1065 | ✗ | if (field && field->properties().required) { | |
| 1066 | ✗ | result.push_back(index); | |
| 1067 | } | ||
| 1068 | ✗ | } | |
| 1069 | ✗ | return result; | |
| 1070 | ✗ | } | |
| 1071 | |||
| 1072 | 92479 | bool IdfObject_Impl::isValid(StrictnessLevel level) const { | |
| 1073 | 92479 | return isValid(level, false); | |
| 1074 | } | ||
| 1075 | |||
| 1076 | 598825 | bool IdfObject_Impl::isValid(StrictnessLevel level, bool checkNames) const { | |
| 1077 |
2/2✓ Branch 1 taken 598825 times.
✓ Branch 4 taken 598825 times.
|
598825 | return (validityReport(level, checkNames).numErrors() == 0); |
| 1078 | } | ||
| 1079 | |||
| 1080 | 996670 | ValidityReport IdfObject_Impl::validityReport(StrictnessLevel level, bool checkNames) const { | |
| 1081 |
2/2✓ Branch 1 taken 996670 times.
✓ Branch 4 taken 996670 times.
|
996670 | ValidityReport report(level, getObject<IdfObject>()); |
| 1082 |
1/1✓ Branch 1 taken 996670 times.
|
996670 | this->populateValidityReport(report, checkNames); |
| 1083 | 996670 | return report; | |
| 1084 | ✗ | } | |
| 1085 | |||
| 1086 | 2321 | bool IdfObject_Impl::dataFieldsEqual(const IdfObject& other) const { | |
| 1087 |
3/4✓ Branch 1 taken 2321 times.
✓ Branch 4 taken 2321 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2321 times.
|
2321 | if (m_iddObject != other.iddObject()) { |
| 1088 | ✗ | return false; | |
| 1089 | } | ||
| 1090 |
1/1✓ Branch 1 taken 2321 times.
|
2321 | UnsignedVector myFields = dataFields(); |
| 1091 |
1/1✓ Branch 1 taken 2321 times.
|
2321 | UnsignedVector otherFields = other.dataFields(); |
| 1092 |
3/3✓ Branch 1 taken 2321 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 2217 times.
|
2321 | if (myFields != otherFields) { |
| 1093 | 104 | return false; | |
| 1094 | } | ||
| 1095 | |||
| 1096 |
1/1✓ Branch 1 taken 2217 times.
|
2217 | OptionalUnsigned iName = m_iddObject.nameFieldIndex(); |
| 1097 | |||
| 1098 | // iddObject() same, field indices same--compare data | ||
| 1099 |
2/2✓ Branch 5 taken 11589 times.
✓ Branch 6 taken 2155 times.
|
13744 | for (unsigned i : myFields) { |
| 1100 | 11589 | bool compareStrings = true; | |
| 1101 |
1/1✓ Branch 1 taken 11589 times.
|
11589 | OptionalIddField oIddField = m_iddObject.getField(i); |
| 1102 | |||
| 1103 | // integers | ||
| 1104 |
8/9✓ Branch 0 taken 11589 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 11589 times.
✓ Branch 6 taken 11589 times.
✓ Branch 9 taken 11589 times.
✓ Branch 12 taken 1045 times.
✓ Branch 13 taken 10544 times.
✓ Branch 14 taken 1045 times.
✓ Branch 15 taken 10544 times.
|
11589 | if (oIddField && (oIddField->properties().type == IddFieldType::IntegerType)) { |
| 1105 |
1/1✓ Branch 1 taken 1045 times.
|
1045 | OptionalInt oMyIntValue = getInt(i); |
| 1106 |
1/1✓ Branch 1 taken 1045 times.
|
1045 | OptionalInt oOtherIntValue = other.getInt(i); |
| 1107 |
5/6✓ Branch 0 taken 27 times.
✓ Branch 1 taken 1018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 1018 times.
✓ Branch 5 taken 27 times.
|
1072 | if (oMyIntValue || oOtherIntValue) { |
| 1108 |
3/6✓ Branch 0 taken 1018 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1018 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1018 times.
|
2036 | if (!(oMyIntValue && oOtherIntValue)) { |
| 1109 | ✗ | return false; | |
| 1110 | } | ||
| 1111 |
3/4✓ Branch 1 taken 1018 times.
✓ Branch 4 taken 1018 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1018 times.
|
1018 | if (oMyIntValue.get() != oOtherIntValue.get()) { |
| 1112 | ✗ | return false; | |
| 1113 | } | ||
| 1114 | 1018 | compareStrings = false; | |
| 1115 | } | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | // doubles | ||
| 1119 |
8/9✓ Branch 0 taken 11589 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 11589 times.
✓ Branch 6 taken 11589 times.
✓ Branch 9 taken 11589 times.
✓ Branch 12 taken 6102 times.
✓ Branch 13 taken 5487 times.
✓ Branch 14 taken 6102 times.
✓ Branch 15 taken 5487 times.
|
11589 | if (oIddField && (oIddField->properties().type == IddFieldType::RealType)) { |
| 1120 |
1/1✓ Branch 1 taken 6102 times.
|
6102 | OptionalDouble oMyDoubleValue = getDouble(i); |
| 1121 |
1/1✓ Branch 1 taken 6102 times.
|
6102 | OptionalDouble oOtherDoubleValue = other.getDouble(i); |
| 1122 |
5/6✓ Branch 0 taken 540 times.
✓ Branch 1 taken 5562 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 540 times.
✓ Branch 4 taken 5562 times.
✓ Branch 5 taken 540 times.
|
6642 | if (oMyDoubleValue || oOtherDoubleValue) { |
| 1123 |
3/6✓ Branch 0 taken 5562 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5562 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5562 times.
|
11124 | if (!(oMyDoubleValue && oOtherDoubleValue)) { |
| 1124 | ✗ | return false; | |
| 1125 | } | ||
| 1126 |
3/4✓ Branch 2 taken 5562 times.
✓ Branch 5 taken 5562 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5562 times.
|
5562 | if (!equal(oMyDoubleValue.get(), oOtherDoubleValue.get())) { |
| 1127 | ✗ | return false; | |
| 1128 | } | ||
| 1129 | 5562 | compareStrings = false; | |
| 1130 | } | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | // urls | ||
| 1134 | // DLM: just treat these as strings | ||
| 1135 | // if (oIddField && (oIddField->properties().type == IddFieldType::URLType)) { | ||
| 1136 | // OptionalUrl oMyUrlValue = getURL(i); | ||
| 1137 | // OptionalUrl oOtherUrlValue = other.getURL(i); | ||
| 1138 | // if (oMyUrlValue || oOtherUrlValue) { | ||
| 1139 | // if (!(oMyUrlValue && oOtherUrlValue)) { return false; } | ||
| 1140 | // if (oMyUrlValue.get() != oOtherUrlValue.get()) { return false; } | ||
| 1141 | // compareStrings = false; | ||
| 1142 | // } | ||
| 1143 | // } | ||
| 1144 | |||
| 1145 | // strings (case-insensitive) | ||
| 1146 |
2/2✓ Branch 0 taken 5009 times.
✓ Branch 1 taken 6580 times.
|
11589 | if (compareStrings) { |
| 1147 |
1/1✓ Branch 1 taken 5009 times.
|
5009 | OptionalString oMyStringValue = getString(i); |
| 1148 |
1/1✓ Branch 1 taken 5009 times.
|
5009 | OptionalString oOtherStringValue = other.getString(i); |
| 1149 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5009 times.
✗ Branch 4 not taken.
|
5009 | OS_ASSERT(oMyStringValue); |
| 1150 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5009 times.
✗ Branch 4 not taken.
|
5009 | OS_ASSERT(oOtherStringValue); |
| 1151 |
5/5✓ Branch 1 taken 5009 times.
✓ Branch 4 taken 5009 times.
✓ Branch 7 taken 5009 times.
✓ Branch 9 taken 62 times.
✓ Branch 10 taken 4947 times.
|
5009 | if (!istringEqual(*oMyStringValue, *oOtherStringValue)) { |
| 1152 |
9/12✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45 times.
✓ Branch 3 taken 17 times.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 17 times.
✓ Branch 11 taken 17 times.
✓ Branch 14 taken 17 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 17 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 62 times.
|
62 | if (iName && (i == iName.get()) && (handle() == other.handle())) { |
| 1153 | ✗ | continue; | |
| 1154 | } | ||
| 1155 | 62 | return false; | |
| 1156 | } | ||
| 1157 | 5071 | } | |
| 1158 | 11589 | } | |
| 1159 | |||
| 1160 | 2155 | return true; | |
| 1161 | 2321 | } | |
| 1162 | |||
| 1163 | ✗ | bool IdfObject_Impl::objectListFieldsEqual(const IdfObject& other) const { | |
| 1164 | ✗ | if (m_iddObject != other.iddObject()) { | |
| 1165 | ✗ | return false; | |
| 1166 | } | ||
| 1167 | ✗ | UnsignedVector myFields = objectListFields(); | |
| 1168 | ✗ | UnsignedVector otherFields = other.objectListFields(); | |
| 1169 | ✗ | if (myFields != otherFields) { | |
| 1170 | ✗ | return false; | |
| 1171 | } | ||
| 1172 | |||
| 1173 | // iddObject() same, field indices same--compare data | ||
| 1174 | ✗ | for (unsigned i : myFields) { | |
| 1175 | // in idf, just comparing strings | ||
| 1176 | ✗ | OptionalString oMyStringValue = getString(i); | |
| 1177 | ✗ | OptionalString oOtherStringValue = other.getString(i); | |
| 1178 | ✗ | OS_ASSERT(oMyStringValue); | |
| 1179 | ✗ | OS_ASSERT(oOtherStringValue); | |
| 1180 | ✗ | if (!istringEqual(*oMyStringValue, *oOtherStringValue)) { | |
| 1181 | ✗ | return false; | |
| 1182 | } | ||
| 1183 | ✗ | } | |
| 1184 | |||
| 1185 | ✗ | return true; | |
| 1186 | ✗ | } | |
| 1187 | |||
| 1188 | 12 | bool IdfObject_Impl::objectListFieldsNonConflicting(const IdfObject& other) const { | |
| 1189 |
3/4✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
|
12 | if (m_iddObject != other.iddObject()) { |
| 1190 | ✗ | return false; | |
| 1191 | } | ||
| 1192 |
1/1✓ Branch 1 taken 12 times.
|
12 | UnsignedVector myFields = objectListFields(); |
| 1193 |
1/1✓ Branch 1 taken 12 times.
|
12 | UnsignedVector otherFields = other.objectListFields(); |
| 1194 | // require same managedObjectLists fields to at least exist | ||
| 1195 |
3/3✓ Branch 1 taken 12 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 11 times.
|
12 | if (myFields != otherFields) { |
| 1196 | 1 | return false; | |
| 1197 | } | ||
| 1198 | |||
| 1199 | // iddObject() same--compare data | ||
| 1200 |
2/2✓ Branch 5 taken 8 times.
✓ Branch 6 taken 7 times.
|
15 | for (unsigned i : myFields) { |
| 1201 | // in idf, just comparing strings | ||
| 1202 |
1/1✓ Branch 1 taken 8 times.
|
8 | OptionalString oMyStringValue = getString(i); |
| 1203 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 4 not taken.
|
8 | OS_ASSERT(oMyStringValue); |
| 1204 | // empty() == null pointer == ok | ||
| 1205 |
2/3✓ Branch 1 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
|
8 | if (oMyStringValue->empty()) { |
| 1206 | ✗ | continue; | |
| 1207 | } | ||
| 1208 | |||
| 1209 |
1/1✓ Branch 1 taken 8 times.
|
8 | OptionalString oOtherStringValue = other.getString(i); |
| 1210 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 4 not taken.
|
8 | OS_ASSERT(oOtherStringValue); |
| 1211 | // empty() == null pointer == ok | ||
| 1212 |
2/3✓ Branch 1 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
|
8 | if (oOtherStringValue->empty()) { |
| 1213 | ✗ | continue; | |
| 1214 | } | ||
| 1215 |
5/5✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 4 times.
|
8 | if (!istringEqual(*oMyStringValue, *oOtherStringValue)) { |
| 1216 | 4 | return false; | |
| 1217 | } | ||
| 1218 | 12 | } | |
| 1219 | |||
| 1220 | 7 | return true; | |
| 1221 | 12 | } | |
| 1222 | |||
| 1223 | // SERIALIZATION | ||
| 1224 | |||
| 1225 | 302 | std::shared_ptr<IdfObject_Impl> IdfObject_Impl::load(const std::string& text) { | |
| 1226 | 302 | std::shared_ptr<IdfObject_Impl> result; | |
| 1227 |
1/1✓ Branch 1 taken 302 times.
|
302 | IdfObject_Impl idfObjectImpl; |
| 1228 | |||
| 1229 | try { | ||
| 1230 |
1/1✓ Branch 1 taken 302 times.
|
302 | idfObjectImpl.parse(text, true); |
| 1231 |
1/1✓ Branch 1 taken 302 times.
|
302 | idfObjectImpl.resizeToMinFields(); |
| 1232 | ✗ | } catch (...) { | |
| 1233 | ✗ | return result; | |
| 1234 | ✗ | } | |
| 1235 | |||
| 1236 |
2/2✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
|
302 | bool keepHandle = idfObjectImpl.iddObject().hasHandleField(); |
| 1237 |
3/5✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
✓ Branch 7 taken 302 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
302 | result = std::shared_ptr<IdfObject_Impl>(new IdfObject_Impl(idfObjectImpl, keepHandle)); |
| 1238 | 302 | return result; | |
| 1239 | 302 | } | |
| 1240 | |||
| 1241 | 1250333 | std::shared_ptr<IdfObject_Impl> IdfObject_Impl::load(const std::string& text, const IddObject& iddObject) { | |
| 1242 | 1250333 | std::shared_ptr<IdfObject_Impl> result; | |
| 1243 |
1/1✓ Branch 1 taken 1250333 times.
|
1250333 | IdfObject_Impl idfObjectImpl(iddObject, false, true); |
| 1244 | |||
| 1245 | try { | ||
| 1246 |
1/1✓ Branch 1 taken 1250333 times.
|
1250333 | idfObjectImpl.parse(text, false); |
| 1247 |
1/1✓ Branch 1 taken 1250333 times.
|
1250333 | idfObjectImpl.resizeToMinFields(); |
| 1248 | ✗ | } catch (...) { | |
| 1249 | ✗ | return result; | |
| 1250 | ✗ | } | |
| 1251 | |||
| 1252 |
2/2✓ Branch 1 taken 1250333 times.
✓ Branch 4 taken 1250333 times.
|
1250333 | bool keepHandle = idfObjectImpl.iddObject().hasHandleField(); |
| 1253 |
3/5✓ Branch 1 taken 1250333 times.
✓ Branch 4 taken 1250333 times.
✓ Branch 7 taken 1250333 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
1250333 | result = std::shared_ptr<IdfObject_Impl>(new IdfObject_Impl(idfObjectImpl, keepHandle)); |
| 1254 | 1250333 | return result; | |
| 1255 | 1250333 | } | |
| 1256 | |||
| 1257 | 959824 | std::ostream& IdfObject_Impl::print(std::ostream& os) const { | |
| 1258 | 959824 | unsigned n = numFields(); | |
| 1259 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 959749 times.
|
959824 | if (n == 0) { |
| 1260 | 75 | printName(os, false); | |
| 1261 | } else { | ||
| 1262 | 959749 | printName(os, true); | |
| 1263 | } | ||
| 1264 | |||
| 1265 |
2/2✓ Branch 0 taken 13435327 times.
✓ Branch 1 taken 959824 times.
|
14395151 | for (unsigned i = 0; i < n; ++i) { |
| 1266 |
2/2✓ Branch 0 taken 12475578 times.
✓ Branch 1 taken 959749 times.
|
13435327 | if (i < n - 1) { |
| 1267 | 12475578 | printField(os, i); | |
| 1268 | } else { | ||
| 1269 | 959749 | printField(os, i, true); | |
| 1270 | } | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | 959824 | os << '\n'; | |
| 1274 | |||
| 1275 | 959824 | return os; | |
| 1276 | } | ||
| 1277 | |||
| 1278 | 959829 | std::ostream& IdfObject_Impl::printName(std::ostream& os, bool hasFields) const { | |
| 1279 | // print comment, if any | ||
| 1280 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 959803 times.
|
959829 | if (!m_comment.empty()) { |
| 1281 | 26 | os << m_comment << '\n'; | |
| 1282 | } | ||
| 1283 | |||
| 1284 | // if this is a comment only object, return | ||
| 1285 | // todo, tighten up handling of comments with comment only object type | ||
| 1286 |
5/5✓ Branch 2 taken 959829 times.
✓ Branch 5 taken 959829 times.
✓ Branch 8 taken 959829 times.
✓ Branch 12 taken 9 times.
✓ Branch 13 taken 959820 times.
|
959829 | if (boost::iequals(m_iddObject.name(), iddRegex::commentOnlyObjectName())) { |
| 1287 | 9 | return os; | |
| 1288 | } | ||
| 1289 | |||
| 1290 |
2/2✓ Branch 1 taken 959820 times.
✓ Branch 4 taken 959820 times.
|
959820 | os << m_iddObject.name(); |
| 1291 | |||
| 1292 |
2/2✓ Branch 0 taken 959754 times.
✓ Branch 1 taken 66 times.
|
959820 | if (hasFields) { |
| 1293 | 959754 | os << "," << '\n'; | |
| 1294 | } else { | ||
| 1295 | 66 | os << ";" << '\n'; | |
| 1296 | } | ||
| 1297 | |||
| 1298 | 959820 | return os; | |
| 1299 | } | ||
| 1300 | |||
| 1301 | 13435360 | std::ostream& IdfObject_Impl::printField(std::ostream& os, unsigned index, bool isLastField) const { | |
| 1302 |
1/2✓ Branch 1 taken 13435360 times.
✗ Branch 2 not taken.
|
13435360 | if (index < numFields()) { |
| 1303 | // different formatting for vertices | ||
| 1304 |
6/6✓ Branch 2 taken 7843332 times.
✓ Branch 3 taken 5592028 times.
✓ Branch 5 taken 4223223 times.
✓ Branch 6 taken 3620109 times.
✓ Branch 7 taken 4223223 times.
✓ Branch 8 taken 9212137 times.
|
13435360 | if ((m_iddObject.properties().format == "vertices") && (m_iddObject.isExtensibleField(index))) { |
| 1305 |
1/1✓ Branch 1 taken 4223223 times.
|
4223223 | ExtensibleIndex eIndex = m_iddObject.extensibleIndex(index); |
| 1306 | // making this static is a bad idea, | ||
| 1307 | // it makes no sense in a threaded environment | ||
| 1308 | static int textWidth(0); | ||
| 1309 |
2/2✓ Branch 0 taken 1407741 times.
✓ Branch 1 taken 2815482 times.
|
4223223 | if (eIndex.field == 0) { |
| 1310 |
1/1✓ Branch 1 taken 1407741 times.
|
1407741 | os << " "; |
| 1311 | 1407741 | textWidth = 0; | |
| 1312 | } else { | ||
| 1313 |
1/1✓ Branch 1 taken 2815482 times.
|
2815482 | os << " "; |
| 1314 | } | ||
| 1315 | // field value | ||
| 1316 |
1/1✓ Branch 2 taken 4223223 times.
|
4223223 | os << m_fields[index]; |
| 1317 | // delimiter | ||
| 1318 |
2/2✓ Branch 0 taken 335329 times.
✓ Branch 1 taken 3887894 times.
|
4223223 | if (isLastField) { |
| 1319 |
1/1✓ Branch 1 taken 335329 times.
|
335329 | os << ";"; |
| 1320 | } else { | ||
| 1321 |
1/1✓ Branch 1 taken 3887894 times.
|
3887894 | os << ","; |
| 1322 | } | ||
| 1323 | 4223223 | textWidth += m_fields[index].size(); | |
| 1324 | // comment | ||
| 1325 |
3/3✓ Branch 1 taken 4223223 times.
✓ Branch 3 taken 1407741 times.
✓ Branch 4 taken 2815482 times.
|
4223223 | if (eIndex.field == m_iddObject.properties().numExtensible - 1) { |
| 1326 |
1/1✓ Branch 1 taken 1407741 times.
|
1407741 | int numSpaces = IdfObject::printedFieldSpace() - textWidth - 4; |
| 1327 |
2/2✓ Branch 0 taken 905641 times.
✓ Branch 1 taken 502100 times.
|
1407741 | if (numSpaces > 0) { |
| 1328 |
1/1✓ Branch 3 taken 905641 times.
|
905641 | os << std::setw(numSpaces) << " "; |
| 1329 | } | ||
| 1330 |
2/2✓ Branch 1 taken 1407741 times.
✓ Branch 4 taken 1407741 times.
|
1407741 | os << " !- X,Y,Z Vertex " << eIndex.group + 1; |
| 1331 |
2/2✓ Branch 1 taken 1407741 times.
✓ Branch 4 taken 1407741 times.
|
1407741 | IddField iddField = m_iddObject.getField(index).get(); |
| 1332 |
3/4✓ Branch 1 taken 1407741 times.
✓ Branch 4 taken 1407741 times.
✓ Branch 6 taken 1407741 times.
✗ Branch 7 not taken.
|
2815482 | if (OptionalString units = iddField.properties().units) { |
| 1333 |
4/4✓ Branch 1 taken 1407741 times.
✓ Branch 4 taken 1407741 times.
✓ Branch 7 taken 1407741 times.
✓ Branch 10 taken 1407741 times.
|
1407741 | os << " {" << *units << "}"; |
| 1334 | 1407741 | } | |
| 1335 |
1/1✓ Branch 1 taken 1407741 times.
|
1407741 | os << '\n'; |
| 1336 | 1407741 | } | |
| 1337 | } else { | ||
| 1338 | // field value | ||
| 1339 | 9212137 | os << " " << m_fields[index]; | |
| 1340 | // delimiter | ||
| 1341 |
2/2✓ Branch 0 taken 624425 times.
✓ Branch 1 taken 8587712 times.
|
9212137 | if (isLastField) { |
| 1342 | 624425 | os << ";"; | |
| 1343 | } else { | ||
| 1344 | 8587712 | os << ","; | |
| 1345 | } | ||
| 1346 | // field comment | ||
| 1347 | 9212137 | int numSpaces = IdfObject::printedFieldSpace() - int(m_fields[index].size()); | |
| 1348 |
2/2✓ Branch 0 taken 6649555 times.
✓ Branch 1 taken 2562582 times.
|
9212137 | if (numSpaces > 0) { |
| 1349 | 6649555 | os << std::setw(numSpaces) << " "; | |
| 1350 | } | ||
| 1351 |
3/3✓ Branch 2 taken 9212137 times.
✓ Branch 5 taken 9212137 times.
✓ Branch 8 taken 9212137 times.
|
9212137 | os << " " << fieldComment(index, true) << '\n'; |
| 1352 | } | ||
| 1353 | } // if index < numFields() | ||
| 1354 | 13435360 | return os; | |
| 1355 | } | ||
| 1356 | |||
| 1357 | 1351507 | void IdfObject_Impl::emitChangeSignals() { | |
| 1358 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1351507 times.
|
1351507 | if (m_diffs.empty()) { |
| 1359 | ✗ | return; | |
| 1360 | } | ||
| 1361 | |||
| 1362 | 1351507 | bool nameChange = false; | |
| 1363 | 1351507 | bool dataChange = false; | |
| 1364 | |||
| 1365 |
2/2✓ Branch 5 taken 1797111 times.
✓ Branch 6 taken 1351507 times.
|
3148618 | for (const IdfObjectDiff& diff : m_diffs) { |
| 1366 | |||
| 1367 |
3/3✓ Branch 1 taken 1797111 times.
✓ Branch 3 taken 239219 times.
✓ Branch 4 taken 1557892 times.
|
1797111 | if (diff.isNull()) { |
| 1368 | 239219 | continue; | |
| 1369 | } | ||
| 1370 | |||
| 1371 |
1/1✓ Branch 1 taken 1557892 times.
|
1557892 | boost::optional<unsigned> index = diff.index(); |
| 1372 |
1/2✓ Branch 0 taken 1557892 times.
✗ Branch 1 not taken.
|
1557892 | if (index) { |
| 1373 | |||
| 1374 |
2/2✓ Branch 1 taken 1557892 times.
✓ Branch 4 taken 1557892 times.
|
1557892 | OptionalIddField oIddField = m_iddObject.getField(*index); |
| 1375 | |||
| 1376 |
7/8✓ Branch 0 taken 1557892 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1557892 times.
✓ Branch 6 taken 1557892 times.
✓ Branch 8 taken 45203 times.
✓ Branch 9 taken 1512689 times.
✓ Branch 10 taken 45203 times.
✓ Branch 11 taken 1512689 times.
|
1557892 | if (oIddField && oIddField->isNameField()) { |
| 1377 | 45203 | nameChange = true; | |
| 1378 | } else { | ||
| 1379 | 1512689 | dataChange = true; | |
| 1380 | } | ||
| 1381 | 1557892 | } | |
| 1382 | } | ||
| 1383 | |||
| 1384 |
2/2✓ Branch 0 taken 45203 times.
✓ Branch 1 taken 1306304 times.
|
1351507 | if (nameChange) { |
| 1385 | 45203 | this->onNameChange.nano_emit(); | |
| 1386 | } | ||
| 1387 | |||
| 1388 |
2/2✓ Branch 0 taken 1223750 times.
✓ Branch 1 taken 127757 times.
|
1351507 | if (dataChange) { |
| 1389 | 1223750 | this->onDataChange.nano_emit(); | |
| 1390 | } | ||
| 1391 | |||
| 1392 | 1351507 | this->onChange.nano_emit(); | |
| 1393 | |||
| 1394 | 1351507 | m_diffs.clear(); | |
| 1395 | } | ||
| 1396 | |||
| 1397 | // PRIVATE | ||
| 1398 | |||
| 1399 | 1678999 | void IdfObject_Impl::resizeToMinFields() { | |
| 1400 | 1678999 | unsigned min_n = m_iddObject.numFieldsInDefaultObject(); | |
| 1401 | 1678999 | unsigned n = numFields(); | |
| 1402 |
2/2✓ Branch 0 taken 215697 times.
✓ Branch 1 taken 1463302 times.
|
1678999 | if (n < min_n) { |
| 1403 | 215697 | m_fields.resize(min_n); | |
| 1404 | 215697 | n = min_n; | |
| 1405 | } | ||
| 1406 | // also make sure extensible groups are whole | ||
| 1407 |
2/2✓ Branch 1 taken 917320 times.
✓ Branch 2 taken 761679 times.
|
1678999 | if (m_iddObject.properties().extensible) { |
| 1408 | 917320 | int nExtFields = n - m_iddObject.numFields(); | |
| 1409 |
2/2✓ Branch 0 taken 731458 times.
✓ Branch 1 taken 185862 times.
|
917320 | if (nExtFields > 0) { |
| 1410 | 731458 | int groupSize = m_iddObject.properties().numExtensible; | |
| 1411 | 731458 | int modulo = nExtFields % groupSize; | |
| 1412 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 731287 times.
|
731458 | if (modulo > 0) { |
| 1413 | 171 | m_fields.resize(n + (groupSize - modulo)); | |
| 1414 | } | ||
| 1415 | } | ||
| 1416 | } | ||
| 1417 | 1678999 | } | |
| 1418 | |||
| 1419 | 1250635 | void IdfObject_Impl::parse(const std::string& text, bool getIddFromFactory) { | |
| 1420 | 1250635 | std::string objectType; | |
| 1421 | |||
| 1422 | // cut down on this text as we parse | ||
| 1423 |
1/1✓ Branch 1 taken 1250635 times.
|
1250635 | std::string parsedText(text); |
| 1424 | |||
| 1425 | // get preceding comments | ||
| 1426 |
1/1✓ Branch 1 taken 1250635 times.
|
1250635 | boost::smatch matches; |
| 1427 |
9/10✓ Branch 1 taken 1250639 times.
✓ Branch 4 taken 1250639 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1250635 times.
✓ Branch 9 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 1250635 times.
|
1250639 | while (boost::regex_match(parsedText, idfRegex::commentOnlyLine()) && boost::regex_search(parsedText, matches, idfRegex::commentOnlyLine())) { |
| 1428 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
8 | std::string comment(matches[1].first, matches[1].second); |
| 1429 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | std::string otherText(matches[2].first, matches[2].second); |
| 1430 |
1/1✓ Branch 2 taken 4 times.
|
4 | boost::trim_left(otherText); |
| 1431 | |||
| 1432 | // append the comment | ||
| 1433 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | if (!comment.empty()) { |
| 1434 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
|
4 | m_comment += "!" + comment + idfRegex::newLinestring(); |
| 1435 | } | ||
| 1436 | |||
| 1437 | // reduce the parsed text | ||
| 1438 |
1/1✓ Branch 1 taken 4 times.
|
4 | parsedText = otherText; |
| 1439 | 4 | } | |
| 1440 | |||
| 1441 | // the first entry will be the object type | ||
| 1442 |
3/4✓ Branch 1 taken 1250635 times.
✓ Branch 4 taken 1250635 times.
✓ Branch 6 taken 1250635 times.
✗ Branch 7 not taken.
|
1250635 | if (boost::regex_search(parsedText, matches, idfRegex::line())) { |
| 1443 |
3/3✓ Branch 1 taken 1250635 times.
✓ Branch 4 taken 1250635 times.
✓ Branch 7 taken 1250635 times.
|
1250635 | objectType = std::string(matches[1].first, matches[1].second); |
| 1444 |
1/1✓ Branch 2 taken 1250635 times.
|
1250635 | boost::trim(objectType); |
| 1445 |
3/3✓ Branch 1 taken 1250635 times.
✓ Branch 4 taken 1250635 times.
✓ Branch 7 taken 1250635 times.
|
1250635 | std::string commentOrOtherText(matches[2].first, matches[2].second); |
| 1446 |
1/1✓ Branch 2 taken 1250635 times.
|
1250635 | boost::trim_left(commentOrOtherText); |
| 1447 |
3/3✓ Branch 1 taken 1250635 times.
✓ Branch 4 taken 1250635 times.
✓ Branch 7 taken 1250635 times.
|
1250635 | std::string otherText(matches[3].first, matches[3].second); |
| 1448 | |||
| 1449 |
2/2✓ Branch 0 taken 302 times.
✓ Branch 1 taken 1250333 times.
|
1250635 | if (getIddFromFactory) { |
| 1450 | // find appropriate IddObject in IddFactory | ||
| 1451 |
2/2✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
|
302 | OptionalIddObject candidate = IddFactory::instance().getObject(objectType); |
| 1452 |
1/2✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
|
302 | if (candidate) { |
| 1453 |
1/1✓ Branch 1 taken 302 times.
|
302 | m_iddObject = *candidate; |
| 1454 | } else { | ||
| 1455 | ✗ | LOG(Warn, "IddObject type '" << objectType << "' not found in IddFactory. " << "Reverting to default Catchall object."); | |
| 1456 | ✗ | OS_ASSERT(m_iddObject.name() == "Catchall"); | |
| 1457 | ✗ | m_fields.push_back(objectType); | |
| 1458 | ✗ | objectType = "Catchall"; | |
| 1459 | } | ||
| 1460 | 302 | } else { | |
| 1461 |
4/4✓ Branch 2 taken 1250333 times.
✓ Branch 5 taken 1250333 times.
✓ Branch 9 taken 182 times.
✓ Branch 10 taken 1250151 times.
|
1250333 | if (!boost::iequals(objectType, m_iddObject.name())) { |
| 1462 |
3/4✓ Branch 1 taken 182 times.
✓ Branch 4 taken 182 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 182 times.
|
182 | if (m_iddObject.type() != IddObjectType::Catchall) { |
| 1463 | ✗ | LOG(Error, "IdfObject type '" << objectType << "', does not equal its IddObject name '" << m_iddObject.name() | |
| 1464 | << "'. Reverting to default Catchall IddObject."); | ||
| 1465 | } | ||
| 1466 |
1/1✓ Branch 1 taken 182 times.
|
182 | m_iddObject = IddObject(); |
| 1467 |
1/1✓ Branch 1 taken 182 times.
|
182 | m_fields.push_back(objectType); |
| 1468 |
1/1✓ Branch 1 taken 182 times.
|
182 | objectType = "Catchall"; |
| 1469 | } | ||
| 1470 | } | ||
| 1471 | |||
| 1472 |
2/2✓ Branch 1 taken 1250635 times.
✓ Branch 4 taken 1250635 times.
|
1250635 | if (boost::regex_match(commentOrOtherText, idfRegex::commentOnlyLine()) |
| 1473 |
8/8✓ Branch 0 taken 1219208 times.
✓ Branch 1 taken 31427 times.
✓ Branch 3 taken 1219208 times.
✓ Branch 6 taken 1219208 times.
✓ Branch 8 taken 1207738 times.
✓ Branch 9 taken 11470 times.
✓ Branch 10 taken 1239165 times.
✓ Branch 11 taken 11470 times.
|
1250635 | || boost::regex_match(commentOrOtherText, commentRegex::whitespaceOnlyBlock())) { |
| 1474 | |||
| 1475 | // set comment | ||
| 1476 |
1/1✓ Branch 1 taken 1239165 times.
|
1239165 | m_comment += commentOrOtherText; |
| 1477 | |||
| 1478 | // reduce the parsed text | ||
| 1479 |
1/1✓ Branch 1 taken 1239165 times.
|
1239165 | parsedText = otherText; |
| 1480 | } else { | ||
| 1481 | // reduce the parsed text | ||
| 1482 |
1/1✓ Branch 1 taken 11470 times.
|
11470 | parsedText = commentOrOtherText + otherText; |
| 1483 | } | ||
| 1484 | |||
| 1485 | 1250635 | } else { | |
| 1486 | ✗ | LOG_AND_THROW("Cannot extract an IdfObject type from text '" << parsedText << "'"); | |
| 1487 | } | ||
| 1488 | |||
| 1489 | // get trailing comments | ||
| 1490 |
9/10✓ Branch 1 taken 1274696 times.
✓ Branch 4 taken 1274696 times.
✓ Branch 6 taken 24061 times.
✓ Branch 7 taken 1250635 times.
✓ Branch 9 taken 24061 times.
✓ Branch 12 taken 24061 times.
✓ Branch 14 taken 24061 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 24061 times.
✓ Branch 17 taken 1250635 times.
|
1274696 | while (boost::regex_match(parsedText, idfRegex::commentOnlyLine()) && boost::regex_search(parsedText, matches, idfRegex::commentOnlyLine())) { |
| 1491 |
3/3✓ Branch 1 taken 24061 times.
✓ Branch 4 taken 24061 times.
✓ Branch 7 taken 24061 times.
|
48122 | std::string comment(matches[1].first, matches[1].second); |
| 1492 |
3/3✓ Branch 1 taken 24061 times.
✓ Branch 4 taken 24061 times.
✓ Branch 7 taken 24061 times.
|
24061 | std::string otherText(matches[2].first, matches[2].second); |
| 1493 |
1/1✓ Branch 2 taken 24061 times.
|
24061 | boost::trim_left(otherText); |
| 1494 | |||
| 1495 | // append the comment | ||
| 1496 |
2/2✓ Branch 1 taken 23657 times.
✓ Branch 2 taken 404 times.
|
24061 | if (!comment.empty()) { |
| 1497 |
4/4✓ Branch 1 taken 23657 times.
✓ Branch 4 taken 23657 times.
✓ Branch 7 taken 23657 times.
✓ Branch 10 taken 23657 times.
|
23657 | m_comment += "!" + comment + idfRegex::newLinestring(); |
| 1498 | } | ||
| 1499 | |||
| 1500 | // reduce the parsed text | ||
| 1501 |
1/1✓ Branch 1 taken 24061 times.
|
24061 | parsedText = otherText; |
| 1502 | 24061 | } | |
| 1503 | |||
| 1504 | // remove trailing whitespace and new lines | ||
| 1505 |
1/1✓ Branch 2 taken 1250635 times.
|
1250635 | boost::trim_right(m_comment); |
| 1506 | |||
| 1507 | // parse the fields | ||
| 1508 |
1/1✓ Branch 1 taken 1250635 times.
|
1250635 | parseFields(parsedText); |
| 1509 | 1250635 | } | |
| 1510 | |||
| 1511 | 1250635 | void IdfObject_Impl::parseFields(const std::string& text) { | |
| 1512 | // match variables | ||
| 1513 |
1/1✓ Branch 1 taken 1250635 times.
|
1250635 | boost::match_results<std::string::const_iterator> matches; |
| 1514 | |||
| 1515 | // cut down on this text as we parse | ||
| 1516 | 1250635 | std::string::const_iterator start = text.begin(); | |
| 1517 | 1250635 | std::string::const_iterator stop = text.end(); | |
| 1518 | |||
| 1519 | // current idd field index | ||
| 1520 | 1250635 | unsigned iddFieldIndex = 0; | |
| 1521 | |||
| 1522 | // parse all the fields | ||
| 1523 |
4/4✓ Branch 1 taken 20371562 times.
✓ Branch 4 taken 20371562 times.
✓ Branch 6 taken 19120929 times.
✓ Branch 7 taken 1250633 times.
|
20371562 | while (boost::regex_search(start, stop, matches, idfRegex::line())) { |
| 1524 |
3/3✓ Branch 1 taken 19120929 times.
✓ Branch 4 taken 19120929 times.
✓ Branch 7 taken 19120929 times.
|
19120929 | std::string fieldText(matches[1].first, matches[1].second); |
| 1525 |
1/1✓ Branch 2 taken 19120929 times.
|
19120929 | boost::trim(fieldText); |
| 1526 |
3/3✓ Branch 1 taken 19120929 times.
✓ Branch 4 taken 19120929 times.
✓ Branch 7 taken 19120929 times.
|
19120929 | std::string commentOrOtherText(matches[2].first, matches[2].second); |
| 1527 |
1/1✓ Branch 2 taken 19120929 times.
|
19120929 | boost::trim(commentOrOtherText); |
| 1528 | |||
| 1529 |
8/8✓ Branch 1 taken 19011604 times.
✓ Branch 2 taken 109325 times.
✓ Branch 4 taken 19011604 times.
✓ Branch 7 taken 19011604 times.
✓ Branch 9 taken 15948868 times.
✓ Branch 10 taken 3062736 times.
✓ Branch 11 taken 16058193 times.
✓ Branch 12 taken 3062736 times.
|
19120929 | if (commentOrOtherText.empty() || boost::regex_match(commentOrOtherText, idfRegex::commentOnlyLine())) { |
| 1530 | // reduce the text | ||
| 1531 |
1/1✓ Branch 1 taken 16058193 times.
|
16058193 | start = matches[3].first; |
| 1532 |
1/1✓ Branch 1 taken 16058193 times.
|
16058193 | stop = matches[3].second; |
| 1533 | } else { | ||
| 1534 | // reduce the text; there may be multiple fields on this line | ||
| 1535 |
1/1✓ Branch 1 taken 3062736 times.
|
3062736 | start = matches[2].first; |
| 1536 |
1/1✓ Branch 1 taken 3062736 times.
|
3062736 | stop = matches[3].second; |
| 1537 | |||
| 1538 | // matches[2] is not a comment | ||
| 1539 | 3062736 | commentOrOtherText.clear(); | |
| 1540 | } | ||
| 1541 | |||
| 1542 | // get the idd field | ||
| 1543 |
1/1✓ Branch 1 taken 19120929 times.
|
19120929 | OptionalIddField iddField = m_iddObject.getField(iddFieldIndex); |
| 1544 | |||
| 1545 |
2/2✓ Branch 0 taken 19120927 times.
✓ Branch 1 taken 2 times.
|
19120929 | if (iddField) { |
| 1546 | |||
| 1547 | // add this to our fields | ||
| 1548 |
1/1✓ Branch 1 taken 19120927 times.
|
19120927 | m_fields.push_back(fieldText); |
| 1549 | |||
| 1550 |
2/2✓ Branch 1 taken 15948866 times.
✓ Branch 2 taken 3172061 times.
|
19120927 | if (!commentOrOtherText.empty()) { |
| 1551 | // drop default comments | ||
| 1552 |
4/4✓ Branch 1 taken 15948866 times.
✓ Branch 4 taken 15948866 times.
✓ Branch 6 taken 607309 times.
✓ Branch 7 taken 15341557 times.
|
15948866 | if (!boost::regex_match(commentOrOtherText, commentRegex::editorCommentWhitespaceOnlyLine())) { |
| 1553 |
1/1✓ Branch 2 taken 607309 times.
|
607309 | m_fieldComments.resize(m_fields.size()); |
| 1554 |
1/1✓ Branch 2 taken 607309 times.
|
607309 | m_fieldComments.back() = commentOrOtherText; |
| 1555 | } | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | // keep handle if this is a handle field | ||
| 1559 |
5/5✓ Branch 1 taken 19120927 times.
✓ Branch 4 taken 19120927 times.
✓ Branch 7 taken 19120927 times.
✓ Branch 10 taken 929979 times.
✓ Branch 11 taken 18190948 times.
|
19120927 | if (iddField->properties().type == IddFieldType::HandleType) { |
| 1560 |
1/1✓ Branch 1 taken 929979 times.
|
929979 | Handle candidate = toUUID(fieldText); |
| 1561 |
1/2✓ Branch 1 taken 929979 times.
✗ Branch 2 not taken.
|
929979 | if (!candidate.isNull()) { |
| 1562 | 929979 | m_handle = candidate; | |
| 1563 | } | ||
| 1564 | } | ||
| 1565 | |||
| 1566 | } else { | ||
| 1567 |
18/18✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 31 taken 2 times.
✓ Branch 34 taken 2 times.
✓ Branch 37 taken 2 times.
✓ Branch 40 taken 2 times.
✓ Branch 43 taken 2 times.
✓ Branch 48 taken 2 times.
✓ Branch 51 taken 2 times.
✓ Branch 54 taken 2 times.
|
6 | LOG(Error, "IdfObject of type '" << m_iddObject.name() << "' " << "cannot have field index of " << iddFieldIndex << ". " |
| 1568 | << "Cutting off IdfObject field parsing here, with the following text " << "remaining: " << '\n' | ||
| 1569 | << fieldText << '\n' | ||
| 1570 | << std::string(start, stop)); | ||
| 1571 | 2 | return; | |
| 1572 | } | ||
| 1573 | |||
| 1574 | // increment current idd field index | ||
| 1575 | 19120927 | ++iddFieldIndex; | |
| 1576 | 19120933 | } // while line matches | |
| 1577 | |||
| 1578 |
1/1✓ Branch 1 taken 1250633 times.
|
1250633 | std::string unparsedText(start, stop); |
| 1579 |
1/1✓ Branch 2 taken 1250633 times.
|
1250633 | boost::trim(unparsedText); |
| 1580 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1250633 times.
|
1250633 | if (!unparsedText.empty()) { |
| 1581 | ✗ | LOG(Warn, "After parsing IdfObject fields, the following text remains unprocessed: " << '\n' << unparsedText); | |
| 1582 | } | ||
| 1583 | 1250635 | } | |
| 1584 | |||
| 1585 | // GETTER AND SETTER HELPERS | ||
| 1586 | |||
| 1587 | ✗ | bool IdfObject_Impl::setIddObject(const IddObject& iddObject) { | |
| 1588 | ✗ | m_iddObject = iddObject; | |
| 1589 | ✗ | if (m_fields.size() < minFields()) { | |
| 1590 | ✗ | m_fields.resize(minFields()); | |
| 1591 | } else { | ||
| 1592 | // pop any fields that the IddObject does not recognize | ||
| 1593 | ✗ | for (unsigned i = 0, n = numFields(); i < n; ++i) { | |
| 1594 | ✗ | if (!(m_iddObject.isNonextensibleField(i) || m_iddObject.isExtensibleField(i))) { | |
| 1595 | ✗ | m_fields.resize(i); | |
| 1596 | ✗ | if (m_fieldComments.size() > m_fields.size()) { | |
| 1597 | ✗ | m_fieldComments.resize(i); | |
| 1598 | } | ||
| 1599 | ✗ | break; | |
| 1600 | } | ||
| 1601 | } | ||
| 1602 | } | ||
| 1603 | ✗ | return true; | |
| 1604 | } | ||
| 1605 | |||
| 1606 | 406488 | UnsignedVector IdfObject_Impl::trimFieldIndices(const UnsignedVector& indices) const { | |
| 1607 | 406488 | unsigned n = m_fields.size(); // number of fields | |
| 1608 | 406488 | UnsignedVector result = indices; | |
| 1609 | // quick check to see if action is necessary | ||
| 1610 |
6/6✓ Branch 1 taken 311891 times.
✓ Branch 2 taken 94597 times.
✓ Branch 4 taken 76644 times.
✓ Branch 5 taken 235247 times.
✓ Branch 6 taken 76644 times.
✓ Branch 7 taken 329844 times.
|
406488 | if (!result.empty() && (result.back() >= n)) { |
| 1611 | // assume indices are in order and find first that is out of range | ||
| 1612 |
1/2✓ Branch 4 taken 214969 times.
✗ Branch 5 not taken.
|
214969 | for (auto it = result.begin(), itEnd = result.end(); it != itEnd; ++it) { |
| 1613 |
2/2✓ Branch 1 taken 76644 times.
✓ Branch 2 taken 138325 times.
|
214969 | if (*it >= n) { |
| 1614 |
1/1✓ Branch 4 taken 76644 times.
|
76644 | result.erase(it, result.end()); |
| 1615 | 76644 | break; | |
| 1616 | } | ||
| 1617 | } | ||
| 1618 | } | ||
| 1619 | 406488 | return result; | |
| 1620 | ✗ | } | |
| 1621 | |||
| 1622 | 406488 | UnsignedVector IdfObject_Impl::repeatExtensibleIndices(const UnsignedVector& indices) const { | |
| 1623 | |||
| 1624 | // assume indices is in order, and any extensible field indices are from the first | ||
| 1625 | // extensible group | ||
| 1626 |
1/1✓ Branch 1 taken 406488 times.
|
406488 | UnsignedVector result = indices; |
| 1627 | |||
| 1628 | // nothing to do if not extensible | ||
| 1629 |
3/3✓ Branch 1 taken 406488 times.
✓ Branch 3 taken 225297 times.
✓ Branch 4 taken 181191 times.
|
406488 | if (!m_iddObject.properties().extensible) { |
| 1630 | 225297 | return result; | |
| 1631 | } | ||
| 1632 | |||
| 1633 | // nothing to do if last index is not in extensible group | ||
| 1634 |
7/7✓ Branch 1 taken 150855 times.
✓ Branch 2 taken 30336 times.
✓ Branch 5 taken 150855 times.
✓ Branch 7 taken 137680 times.
✓ Branch 8 taken 13175 times.
✓ Branch 9 taken 137680 times.
✓ Branch 10 taken 43511 times.
|
181191 | if (!result.empty() && !m_iddObject.isExtensibleField(result.back())) { |
| 1635 | 137680 | return result; | |
| 1636 | } | ||
| 1637 | |||
| 1638 | // otherwise, find group indices of extensible field indices in result | ||
| 1639 | 43511 | UnsignedVector groupIndices; | |
| 1640 |
2/2✓ Branch 5 taken 23421 times.
✓ Branch 6 taken 43511 times.
|
66932 | for (unsigned index : result) { |
| 1641 |
3/3✓ Branch 1 taken 23421 times.
✓ Branch 3 taken 14636 times.
✓ Branch 4 taken 8785 times.
|
23421 | if (m_iddObject.isExtensibleField(index)) { |
| 1642 |
2/2✓ Branch 1 taken 14636 times.
✓ Branch 4 taken 14636 times.
|
14636 | groupIndices.push_back(m_iddObject.extensibleIndex(index).field); |
| 1643 | } | ||
| 1644 | } | ||
| 1645 | |||
| 1646 | 43511 | unsigned n = m_fields.size(); | |
| 1647 |
1/1✓ Branch 1 taken 43511 times.
|
43511 | unsigned nn = m_iddObject.numFields(); |
| 1648 |
1/1✓ Branch 1 taken 43511 times.
|
43511 | unsigned ne = m_iddObject.properties().numExtensible; |
| 1649 | 43511 | unsigned groupIndex = 1; | |
| 1650 |
2/2✓ Branch 0 taken 142242 times.
✓ Branch 1 taken 43511 times.
|
185753 | while (nn + groupIndex * ne < n) { |
| 1651 |
2/2✓ Branch 5 taken 9854 times.
✓ Branch 6 taken 142242 times.
|
152096 | for (unsigned gi : groupIndices) { |
| 1652 | 9854 | unsigned index = nn + groupIndex * ne + gi; | |
| 1653 |
1/2✓ Branch 0 taken 9854 times.
✗ Branch 1 not taken.
|
9854 | if (index < n) { |
| 1654 |
1/1✓ Branch 1 taken 9854 times.
|
9854 | result.push_back(index); |
| 1655 | } | ||
| 1656 | } | ||
| 1657 | 142242 | ++groupIndex; | |
| 1658 | } | ||
| 1659 | |||
| 1660 | 43511 | return result; | |
| 1661 | 43511 | } | |
| 1662 | |||
| 1663 | // QUERY HELPERS | ||
| 1664 | |||
| 1665 | 996667 | void IdfObject_Impl::populateValidityReport(ValidityReport& report, bool /*checkNames*/) const { | |
| 1666 | // field-level errors | ||
| 1667 |
4/4✓ Branch 1 taken 996667 times.
✓ Branch 4 taken 996667 times.
✓ Branch 7 taken 996432 times.
✓ Branch 8 taken 235 times.
|
996667 | if (report.level() > StrictnessLevel::None) { |
| 1668 |
2/2✓ Branch 1 taken 11719678 times.
✓ Branch 2 taken 996432 times.
|
12716110 | for (unsigned index = 0; index < m_fields.size(); ++index) { |
| 1669 |
2/2✓ Branch 1 taken 11719678 times.
✓ Branch 4 taken 11719678 times.
|
11719678 | DataErrorVector fieldErrors = fieldDataIsValid(index, report.level()); |
| 1670 |
2/2✓ Branch 5 taken 75 times.
✓ Branch 6 taken 11719678 times.
|
11719753 | for (const DataError& error : fieldErrors) { |
| 1671 |
1/1✓ Branch 1 taken 75 times.
|
75 | report.insertError(error); |
| 1672 | } | ||
| 1673 | 11719678 | } | |
| 1674 | } | ||
| 1675 | |||
| 1676 | // StrictnessLevel::Final | ||
| 1677 |
4/4✓ Branch 1 taken 996667 times.
✓ Branch 4 taken 996667 times.
✓ Branch 7 taken 3472 times.
✓ Branch 8 taken 993195 times.
|
996667 | if (report.level() > StrictnessLevel::Draft) { |
| 1678 | |||
| 1679 | // DataErrorType::NumberOfFields | ||
| 1680 | // object-level | ||
| 1681 |
11/14✓ Branch 1 taken 3472 times.
✓ Branch 4 taken 3472 times.
✓ Branch 6 taken 3472 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 3472 times.
✓ Branch 11 taken 2336 times.
✓ Branch 12 taken 1136 times.
✓ Branch 14 taken 2336 times.
✓ Branch 17 taken 2336 times.
✓ Branch 20 taken 2336 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 2336 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 3472 times.
|
6944 | if ((numFields() < minFields()) || (maxFields() && (numFields() > maxFields().get()))) { |
| 1682 | ✗ | report.insertError(DataError(getObject<IdfObject>(), DataErrorType(DataErrorType::NumberOfFields))); | |
| 1683 | } | ||
| 1684 | |||
| 1685 | } // end StrictnessLevel::Final | ||
| 1686 | 996667 | } | |
| 1687 | |||
| 1688 | 12827479 | std::vector<DataError> IdfObject_Impl::fieldDataIsValid(unsigned index, const StrictnessLevel& level) const { | |
| 1689 | 12827479 | DataErrorVector result; | |
| 1690 | |||
| 1691 | // StrictnessLevel::Minimal | ||
| 1692 |
2/3✓ Branch 1 taken 12827479 times.
✓ Branch 4 taken 12827479 times.
✗ Branch 5 not taken.
|
12827479 | if (level > StrictnessLevel::None) { |
| 1693 | |||
| 1694 | // DataErrorType::NoIdd | ||
| 1695 | // field-level | ||
| 1696 |
2/3✓ Branch 1 taken 12827479 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12827479 times.
|
12827479 | if (!m_iddObject.getField(index)) { |
| 1697 | ✗ | result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NoIdd))); | |
| 1698 | // no other checks will work | ||
| 1699 | ✗ | return result; | |
| 1700 | } | ||
| 1701 | } | ||
| 1702 | |||
| 1703 | // StrictnessLevel::Draft | ||
| 1704 |
3/3✓ Branch 1 taken 12827479 times.
✓ Branch 4 taken 10965471 times.
✓ Branch 5 taken 1862008 times.
|
12827479 | if (level > StrictnessLevel::Minimal) { |
| 1705 | |||
| 1706 | // DataErrorType::DataType | ||
| 1707 | // DataErrorType::NumericBound | ||
| 1708 | // field-level | ||
| 1709 |
3/3✓ Branch 1 taken 10965471 times.
✓ Branch 3 taken 291 times.
✓ Branch 4 taken 10965180 times.
|
10965471 | if (!fieldDataIsCorrectType(index)) { |
| 1710 |
4/4✓ Branch 1 taken 291 times.
✓ Branch 4 taken 291 times.
✓ Branch 7 taken 291 times.
✓ Branch 10 taken 291 times.
|
291 | result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::DataType))); |
| 1711 | } | ||
| 1712 |
3/3✓ Branch 1 taken 10965471 times.
✓ Branch 3 taken 493 times.
✓ Branch 4 taken 10964978 times.
|
10965471 | if (!fieldDataIsWithinBounds(index)) { |
| 1713 |
4/4✓ Branch 1 taken 493 times.
✓ Branch 4 taken 493 times.
✓ Branch 7 taken 493 times.
✓ Branch 10 taken 493 times.
|
493 | result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NumericBound))); |
| 1714 | } | ||
| 1715 | |||
| 1716 | } // end StrictnessLevel::Draft | ||
| 1717 | |||
| 1718 | // StrictnessLevel::Final | ||
| 1719 |
3/3✓ Branch 1 taken 12827479 times.
✓ Branch 4 taken 31837 times.
✓ Branch 5 taken 12795642 times.
|
12827479 | if (level > StrictnessLevel::Draft) { |
| 1720 | |||
| 1721 | // DataErrorType::NullAndRequired | ||
| 1722 | // field-level | ||
| 1723 |
3/3✓ Branch 1 taken 31837 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 31832 times.
|
31837 | if (!fieldIsNonnullIfRequired(index)) { |
| 1724 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
|
5 | result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NullAndRequired))); |
| 1725 | } | ||
| 1726 | } // end StrictnessLevel::Final | ||
| 1727 | |||
| 1728 | 12827479 | return result; | |
| 1729 | ✗ | } | |
| 1730 | |||
| 1731 | 8652620 | bool IdfObject_Impl::fieldDataIsCorrectType(unsigned index) const { | |
| 1732 |
1/1✓ Branch 1 taken 8652620 times.
|
8652620 | OptionalIddField oIddField = m_iddObject.getField(index); |
| 1733 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8652620 times.
|
8652620 | if (!oIddField) { |
| 1734 | ✗ | return true; | |
| 1735 | } | ||
| 1736 | |||
| 1737 |
1/1✓ Branch 1 taken 8652620 times.
|
8652620 | IddField iddField = *oIddField; |
| 1738 |
1/1✓ Branch 1 taken 8652620 times.
|
8652620 | IddFieldType fieldType = iddField.properties().type; |
| 1739 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 8652620 times.
✗ Branch 4 not taken.
|
8652620 | OS_ASSERT(m_fields.size() > index); |
| 1740 | |||
| 1741 |
7/7✓ Branch 1 taken 8652620 times.
✓ Branch 4 taken 665242 times.
✓ Branch 5 taken 7987378 times.
✓ Branch 8 taken 554156 times.
✓ Branch 9 taken 111086 times.
✓ Branch 10 taken 554156 times.
✓ Branch 11 taken 8098464 times.
|
8652620 | if ((fieldType == IddFieldType::IntegerType) && (!m_fields[index].empty())) { |
| 1742 |
1/1✓ Branch 1 taken 554156 times.
|
554156 | OptionalInt value = getInt(index); |
| 1743 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 554156 times.
|
554156 | if (!value) { |
| 1744 | // ok if autosize or autocalculate | ||
| 1745 | ✗ | if (iddField.properties().autosizable && istringEqual(m_fields[index], "autosize")) { | |
| 1746 | ✗ | } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autocalculate")) { | |
| 1747 | ✗ | } else if (iddField.properties().autosizable && istringEqual(m_fields[index], "autocalculate")) { | |
| 1748 | ✗ | LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name() | |
| 1749 | << " has 'autocalculate' as its value even though it is autosizable."); | ||
| 1750 | ✗ | } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autosize")) { | |
| 1751 | ✗ | LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name() | |
| 1752 | << " has 'autosize' as its value even though it is autocalculable."); | ||
| 1753 | } else { | ||
| 1754 | ✗ | return false; | |
| 1755 | } | ||
| 1756 | } else { | ||
| 1757 | // integers can't be NaN or Infinity | ||
| 1758 | } | ||
| 1759 | } | ||
| 1760 | |||
| 1761 |
7/7✓ Branch 1 taken 8652620 times.
✓ Branch 4 taken 4438865 times.
✓ Branch 5 taken 4213755 times.
✓ Branch 8 taken 3255849 times.
✓ Branch 9 taken 1183016 times.
✓ Branch 10 taken 3255849 times.
✓ Branch 11 taken 5396771 times.
|
8652620 | if ((fieldType == IddFieldType::RealType) && (!m_fields[index].empty())) { |
| 1762 |
1/1✓ Branch 1 taken 3255849 times.
|
3255849 | OptionalDouble value = getDouble(index); |
| 1763 |
2/2✓ Branch 1 taken 72077 times.
✓ Branch 2 taken 3183772 times.
|
3255849 | if (!value) { |
| 1764 | // ok if autosize or autocalculate | ||
| 1765 |
13/17✓ Branch 1 taken 72077 times.
✓ Branch 3 taken 68087 times.
✓ Branch 4 taken 3990 times.
✓ Branch 6 taken 68087 times.
✓ Branch 10 taken 68087 times.
✓ Branch 12 taken 67827 times.
✓ Branch 13 taken 260 times.
✓ Branch 14 taken 68087 times.
✓ Branch 15 taken 3990 times.
✓ Branch 17 taken 68087 times.
✓ Branch 18 taken 3990 times.
✓ Branch 19 taken 4250 times.
✓ Branch 20 taken 67827 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
208251 | if (iddField.properties().autosizable && istringEqual(m_fields[index], "autosize")) { |
| 1766 |
13/17✓ Branch 1 taken 4250 times.
✓ Branch 3 taken 3989 times.
✓ Branch 4 taken 261 times.
✓ Branch 6 taken 3989 times.
✓ Branch 10 taken 3989 times.
✓ Branch 12 taken 3983 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 3989 times.
✓ Branch 15 taken 261 times.
✓ Branch 17 taken 3989 times.
✓ Branch 18 taken 261 times.
✓ Branch 19 taken 267 times.
✓ Branch 20 taken 3983 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
12228 | } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autocalculate")) { |
| 1767 |
12/17✓ Branch 1 taken 267 times.
✓ Branch 3 taken 260 times.
✓ Branch 4 taken 7 times.
✓ Branch 6 taken 260 times.
✓ Branch 10 taken 260 times.
✓ Branch 12 taken 260 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 260 times.
✓ Branch 15 taken 7 times.
✓ Branch 17 taken 260 times.
✓ Branch 18 taken 7 times.
✓ Branch 19 taken 260 times.
✓ Branch 20 taken 7 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
787 | } else if (iddField.properties().autosizable && istringEqual(m_fields[index], "autocalculate")) { |
| 1768 |
13/13✓ Branch 1 taken 260 times.
✓ Branch 4 taken 260 times.
✓ Branch 7 taken 260 times.
✓ Branch 10 taken 260 times.
✓ Branch 13 taken 260 times.
✓ Branch 16 taken 260 times.
✓ Branch 19 taken 260 times.
✓ Branch 22 taken 260 times.
✓ Branch 25 taken 260 times.
✓ Branch 28 taken 260 times.
✓ Branch 33 taken 260 times.
✓ Branch 36 taken 260 times.
✓ Branch 39 taken 260 times.
|
260 | LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name() |
| 1769 | << " has 'autocalculate' as its value even though it is autosizable."); | ||
| 1770 |
12/17✓ Branch 1 taken 7 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 1 time.
✓ Branch 17 taken 6 times.
✓ Branch 18 taken 1 time.
✓ Branch 19 taken 6 times.
✓ Branch 20 taken 1 time.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
19 | } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autosize")) { |
| 1771 |
13/13✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 19 taken 6 times.
✓ Branch 22 taken 6 times.
✓ Branch 25 taken 6 times.
✓ Branch 28 taken 6 times.
✓ Branch 33 taken 6 times.
✓ Branch 36 taken 6 times.
✓ Branch 39 taken 6 times.
|
6 | LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name() |
| 1772 | << " has 'autosize' as its value even though it is autocalculable."); | ||
| 1773 | } else { | ||
| 1774 | 9 | return false; | |
| 1775 | } | ||
| 1776 | } else { | ||
| 1777 |
3/3✓ Branch 1 taken 3183772 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3183769 times.
|
3183772 | if (std::isnan(*value)) { |
| 1778 |
13/13✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 25 taken 3 times.
✓ Branch 28 taken 3 times.
✓ Branch 33 taken 3 times.
✓ Branch 36 taken 3 times.
✓ Branch 39 taken 3 times.
|
3 | LOG(Warn, "Cannot set field " << index << ", '" << iddField.name() << "', an object of type " << m_iddObject.name() << " to NaN."); |
| 1779 | 3 | return false; | |
| 1780 |
3/3✓ Branch 1 taken 3183769 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 3183764 times.
|
3183769 | } else if (std::isinf(*value)) { |
| 1781 |
13/13✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✓ Branch 19 taken 5 times.
✓ Branch 22 taken 5 times.
✓ Branch 25 taken 5 times.
✓ Branch 28 taken 5 times.
✓ Branch 33 taken 5 times.
✓ Branch 36 taken 5 times.
✓ Branch 39 taken 5 times.
|
5 | LOG(Warn, "Cannot set field " << index << ", '" << iddField.name() << "', an object of type " << m_iddObject.name() << " to Infinity."); |
| 1782 | 5 | return false; | |
| 1783 | } | ||
| 1784 | } | ||
| 1785 | } | ||
| 1786 | |||
| 1787 |
7/7✓ Branch 1 taken 8652611 times.
✓ Branch 4 taken 1848058 times.
✓ Branch 5 taken 6804553 times.
✓ Branch 8 taken 1441212 times.
✓ Branch 9 taken 406846 times.
✓ Branch 10 taken 1441212 times.
✓ Branch 11 taken 7211399 times.
|
8652611 | if ((fieldType == IddFieldType::ChoiceType) && (!m_fields[index].empty())) { |
| 1788 | // value should iequal one of the keys | ||
| 1789 |
1/1✓ Branch 1 taken 1441212 times.
|
1441212 | IddKeyVector keys = iddField.keys(); |
| 1790 |
1/1✓ Branch 2 taken 1441212 times.
|
1441212 | NameFinder<IddKey> finder(m_fields[index]); |
| 1791 |
2/2✓ Branch 1 taken 1441212 times.
✓ Branch 6 taken 1441212 times.
|
1441212 | auto loc = std::find_if(keys.begin(), keys.end(), finder); |
| 1792 |
2/2✓ Branch 2 taken 282 times.
✓ Branch 3 taken 1440930 times.
|
1441212 | if (loc == keys.end()) { |
| 1793 | 282 | return false; | |
| 1794 | } | ||
| 1795 | 1441494 | } | |
| 1796 | |||
| 1797 | 8652329 | return true; | |
| 1798 | 8652620 | } | |
| 1799 | |||
| 1800 | 10965471 | bool IdfObject_Impl::fieldDataIsWithinBounds(unsigned index) const { | |
| 1801 |
1/1✓ Branch 1 taken 10965471 times.
|
10965471 | OptionalIddField oIddField = m_iddObject.getField(index); |
| 1802 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10965471 times.
|
10965471 | if (!oIddField) { |
| 1803 | ✗ | return true; | |
| 1804 | } // default to true | ||
| 1805 | |||
| 1806 |
1/1✓ Branch 1 taken 10965471 times.
|
10965471 | IddField iddField = *oIddField; |
| 1807 |
1/1✓ Branch 1 taken 10965471 times.
|
10965471 | IddFieldType fieldType = iddField.properties().type; |
| 1808 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 10965471 times.
✗ Branch 4 not taken.
|
10965471 | OS_ASSERT(m_fields.size() > index); |
| 1809 | |||
| 1810 |
3/3✓ Branch 1 taken 10965471 times.
✓ Branch 4 taken 665242 times.
✓ Branch 5 taken 10300229 times.
|
10965471 | if (fieldType == IddFieldType::IntegerType) { |
| 1811 |
1/1✓ Branch 1 taken 665242 times.
|
665242 | OptionalInt value = getInt(index); |
| 1812 |
2/2✓ Branch 0 taken 554156 times.
✓ Branch 1 taken 111086 times.
|
665242 | if (value) { |
| 1813 |
1/1✓ Branch 1 taken 554156 times.
|
554156 | auto fieldValue = static_cast<double>(*value); |
| 1814 |
1/1✓ Branch 1 taken 554156 times.
|
554156 | return withinBounds(fieldValue, iddField); |
| 1815 | } | ||
| 1816 | } | ||
| 1817 |
3/3✓ Branch 1 taken 10411315 times.
✓ Branch 4 taken 4438865 times.
✓ Branch 5 taken 5972450 times.
|
10411315 | if (fieldType == IddFieldType::RealType) { |
| 1818 |
1/1✓ Branch 1 taken 4438865 times.
|
4438865 | OptionalDouble value = getDouble(index); |
| 1819 |
2/2✓ Branch 0 taken 3183772 times.
✓ Branch 1 taken 1255093 times.
|
4438865 | if (value) { |
| 1820 |
2/2✓ Branch 1 taken 3183772 times.
✓ Branch 4 taken 3183772 times.
|
3183772 | return withinBounds(*value, iddField); |
| 1821 | } | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | 7227543 | return true; | |
| 1825 | 10965471 | } | |
| 1826 | |||
| 1827 | 27236 | bool IdfObject_Impl::fieldIsNonnullIfRequired(unsigned index) const { | |
| 1828 |
1/1✓ Branch 1 taken 27236 times.
|
27236 | OptionalIddField oIddField = m_iddObject.getField(index); |
| 1829 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27236 times.
|
27236 | if (!oIddField) { |
| 1830 | ✗ | return true; | |
| 1831 | } // default to true | ||
| 1832 | |||
| 1833 |
1/1✓ Branch 1 taken 27236 times.
|
27236 | IddField iddField = *oIddField; |
| 1834 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 27236 times.
✗ Branch 4 not taken.
|
27236 | OS_ASSERT(m_fields.size() > index); |
| 1835 | |||
| 1836 |
8/10✓ Branch 1 taken 27236 times.
✓ Branch 3 taken 8242 times.
✓ Branch 4 taken 18994 times.
✓ Branch 6 taken 8242 times.
✓ Branch 8 taken 7945 times.
✓ Branch 9 taken 297 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7945 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 27236 times.
|
27236 | if (iddField.properties().required && (!iddField.isObjectListField()) && m_fields[index].empty()) { |
| 1837 | ✗ | return false; | |
| 1838 | } | ||
| 1839 | 27236 | return true; | |
| 1840 | 27236 | } | |
| 1841 | |||
| 1842 | 3737928 | bool IdfObject_Impl::withinBounds(double fieldValue, const IddField& iddField) const { | |
| 1843 | |||
| 1844 | // minimum bounds | ||
| 1845 |
1/1✓ Branch 1 taken 3737928 times.
|
3737928 | OptionalDouble boundValue = iddField.properties().minBoundValue; |
| 1846 |
1/1✓ Branch 1 taken 3737928 times.
|
3737928 | IddFieldProperties::BoundTypes boundType = iddField.properties().minBoundType; |
| 1847 |
2/2✓ Branch 0 taken 874520 times.
✓ Branch 1 taken 2863408 times.
|
3737928 | if (boundType != IddFieldProperties::Unbounded) { |
| 1848 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 874520 times.
✗ Branch 4 not taken.
|
874520 | OS_ASSERT(boundValue); |
| 1849 | // check min bound | ||
| 1850 |
2/2✓ Branch 0 taken 786438 times.
✓ Branch 1 taken 88082 times.
|
874520 | if (boundType == IddFieldProperties::InclusiveBound) { |
| 1851 |
3/3✓ Branch 1 taken 786438 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 786144 times.
|
786438 | if (fieldValue < *boundValue) { |
| 1852 | 294 | return false; | |
| 1853 | } | ||
| 1854 |
3/3✓ Branch 1 taken 88082 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 87922 times.
|
88082 | } else if (fieldValue <= *boundValue) { |
| 1855 | 160 | return false; | |
| 1856 | } | ||
| 1857 | } | ||
| 1858 | |||
| 1859 | // maximum bounds | ||
| 1860 |
1/1✓ Branch 1 taken 3737474 times.
|
3737474 | boundValue = iddField.properties().maxBoundValue; |
| 1861 |
1/1✓ Branch 1 taken 3737474 times.
|
3737474 | boundType = iddField.properties().maxBoundType; |
| 1862 |
2/2✓ Branch 0 taken 496206 times.
✓ Branch 1 taken 3241268 times.
|
3737474 | if (boundType != IddFieldProperties::Unbounded) { |
| 1863 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 496206 times.
✗ Branch 4 not taken.
|
496206 | OS_ASSERT(boundValue); |
| 1864 |
2/2✓ Branch 0 taken 490891 times.
✓ Branch 1 taken 5315 times.
|
496206 | if (boundType == IddFieldProperties::InclusiveBound) { |
| 1865 |
3/3✓ Branch 1 taken 490891 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 490857 times.
|
490891 | if (fieldValue > *boundValue) { |
| 1866 | 34 | return false; | |
| 1867 | } | ||
| 1868 |
3/3✓ Branch 1 taken 5315 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5310 times.
|
5315 | } else if (fieldValue >= *boundValue) { |
| 1869 | 5 | return false; | |
| 1870 | } | ||
| 1871 | } | ||
| 1872 | |||
| 1873 | 3737435 | return true; | |
| 1874 | } | ||
| 1875 | |||
| 1876 | 2 | OSOptionalQuantity IdfObject_Impl::getQuantityFromDouble(unsigned index, boost::optional<double> value, bool returnIP) const { | |
| 1877 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalIddField iddField = m_iddObject.getField(index); |
| 1878 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!iddField) { |
| 1879 | ✗ | LOG_AND_THROW("get/setQuantity not available without an IddField. Asked to getQuantity at " | |
| 1880 | "field " | ||
| 1881 | << index << "for IdfObject with Idd:\n" | ||
| 1882 | << m_iddObject); | ||
| 1883 | } | ||
| 1884 | |||
| 1885 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalUnit siUnit = iddField->getUnits(false); |
| 1886 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalUnit units = siUnit; |
| 1887 | 2 | OptionalUnit ipUnit; | |
| 1888 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (returnIP) { |
| 1889 | ✗ | ipUnit = iddField->getUnits(true); | |
| 1890 | ✗ | units = ipUnit; | |
| 1891 | } | ||
| 1892 | |||
| 1893 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!units) { |
| 1894 | ✗ | LOG_AND_THROW("Unable to construct a unit for field " << index << " for IdfObject with " << "Idd:\n" << m_iddObject); | |
| 1895 | } | ||
| 1896 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(siUnit); |
| 1897 | |||
| 1898 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (value) { |
| 1899 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | Quantity result(*value, *siUnit); |
| 1900 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (returnIP) { |
| 1901 | ✗ | OptionalQuantity temp = convert(result, *ipUnit); | |
| 1902 | ✗ | if (temp) { | |
| 1903 | ✗ | result = *temp; | |
| 1904 | } | ||
| 1905 | ✗ | } | |
| 1906 |
1/1✓ Branch 1 taken 2 times.
|
2 | return OSOptionalQuantity(result); |
| 1907 | 2 | } | |
| 1908 | |||
| 1909 | ✗ | return OSOptionalQuantity(*units); | |
| 1910 | 2 | } | |
| 1911 | |||
| 1912 | 1 | boost::optional<double> IdfObject_Impl::getDoubleFromQuantity(unsigned index, const Quantity& q) const { | |
| 1913 | 1 | OptionalDouble result; | |
| 1914 | |||
| 1915 |
1/1✓ Branch 1 taken 1 time.
|
1 | OptionalIddField iddField = m_iddObject.getField(index); |
| 1916 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | if (!iddField) { |
| 1917 | ✗ | LOG(Error, "get/setQuantity not available without an IddField. Asked to setQuantity at field " << index << "for IdfObject with Idd:\n" | |
| 1918 | << m_iddObject); | ||
| 1919 | ✗ | return result; | |
| 1920 | } | ||
| 1921 | |||
| 1922 |
1/1✓ Branch 1 taken 1 time.
|
1 | Quantity wq(q); |
| 1923 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | OptionalUnit unit = iddField->getUnits(false); |
| 1924 | |||
| 1925 | // dimensionless | ||
| 1926 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | if (!unit) { |
| 1927 | ✗ | wq.setScale(0); | |
| 1928 | ✗ | if (wq.standardUnitsString(true).empty()) { | |
| 1929 | ✗ | result = wq.value(); | |
| 1930 | } | ||
| 1931 | ✗ | return result; | |
| 1932 | } | ||
| 1933 | |||
| 1934 | // has unit, convert to it | ||
| 1935 | // (QuantityConverter checks for equality first, sets scale.) | ||
| 1936 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | OptionalQuantity candidate = convert(wq, *unit); |
| 1937 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | if (!candidate) { |
| 1938 | ✗ | return result; | |
| 1939 | } | ||
| 1940 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | wq = *candidate; |
| 1941 | |||
| 1942 |
4/6✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 12 not taken.
|
1 | OS_ASSERT(wq.units() == *unit); |
| 1943 | |||
| 1944 |
12/12✓ 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.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
|
1 | LOG(Trace, "Converted " << q << " to " << wq << "to set field with units " << *unit << "."); |
| 1945 | |||
| 1946 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | result = wq.value(); |
| 1947 | 1 | return result; | |
| 1948 | 1 | } | |
| 1949 | |||
| 1950 | 1823437 | std::vector<std::string> IdfObject_Impl::fields() const { | |
| 1951 | 1823437 | return m_fields; | |
| 1952 | } | ||
| 1953 | |||
| 1954 | 1823437 | std::vector<std::string> IdfObject_Impl::fieldComments() const { | |
| 1955 | 1823437 | return m_fieldComments; | |
| 1956 | } | ||
| 1957 | |||
| 1958 | 4892545 | std::string IdfObject_Impl::encodeString(const std::string& value) const { | |
| 1959 | 4892545 | std::string result; | |
| 1960 |
2/2✓ Branch 5 taken 48562120 times.
✓ Branch 6 taken 4892545 times.
|
53454665 | for (auto const& s : value) { |
| 1961 |
4/6✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 48561980 times.
|
48562120 | switch (s) { |
| 1962 | ✗ | case '\n': | |
| 1963 | ✗ | result.append("
"); | |
| 1964 | ✗ | break; | |
| 1965 | ✗ | case '\r': | |
| 1966 | ✗ | result.append("
"); | |
| 1967 | ✗ | break; | |
| 1968 | 75 | case ',': | |
| 1969 |
1/1✓ Branch 1 taken 75 times.
|
75 | result.append(","); |
| 1970 | 75 | break; | |
| 1971 | 3 | case ';': | |
| 1972 |
1/1✓ Branch 1 taken 3 times.
|
3 | result.append(";"); |
| 1973 | 3 | break; | |
| 1974 | 62 | case '!': | |
| 1975 |
1/1✓ Branch 1 taken 62 times.
|
62 | result.append("!"); |
| 1976 | 62 | break; | |
| 1977 | 48561980 | default: | |
| 1978 |
1/1✓ Branch 1 taken 48561980 times.
|
48561980 | result.push_back(s); |
| 1979 | 48561980 | break; | |
| 1980 | } | ||
| 1981 | } | ||
| 1982 | 4892545 | return result; | |
| 1983 | ✗ | } | |
| 1984 | |||
| 1985 | 53901950 | std::string IdfObject_Impl::decodeString(const std::string& value) const { | |
| 1986 | 53901950 | std::string result; | |
| 1987 | char c; | ||
| 1988 | 53901950 | bool special_char = false; | |
| 1989 | 53901950 | auto const max_length = value.size(); | |
| 1990 | 53901950 | auto const length = max_length - 3; | |
| 1991 | // auto const * str = value.c_str(); | ||
| 1992 |
1/1✓ Branch 1 taken 53901950 times.
|
53901950 | result.reserve(max_length); |
| 1993 | |||
| 1994 |
2/2✓ Branch 0 taken 583643340 times.
✓ Branch 1 taken 53901950 times.
|
637545290 | for (size_t i = 0; i < max_length; ++i) { |
| 1995 |
8/8✓ Branch 0 taken 449716425 times.
✓ Branch 1 taken 133926915 times.
✓ Branch 3 taken 4169 times.
✓ Branch 4 taken 449712256 times.
✓ Branch 6 taken 1239 times.
✓ Branch 7 taken 2930 times.
✓ Branch 8 taken 1239 times.
✓ Branch 9 taken 583642101 times.
|
583643340 | if (i < length && value[i] == '&' && value[i + 1] == '#') { |
| 1996 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1239 times.
|
1239 | if (value[i + 2] == '1') { |
| 1997 | ✗ | if (value[i + 3] == '0') { | |
| 1998 | ✗ | special_char = true; | |
| 1999 | ✗ | c = '\n'; // "
" | |
| 2000 | ✗ | } else if (value[i + 3] == '3') { | |
| 2001 | ✗ | special_char = true; | |
| 2002 | ✗ | c = '\r'; // "
" | |
| 2003 | } | ||
| 2004 |
5/6✓ Branch 1 taken 951 times.
✓ Branch 2 taken 288 times.
✓ Branch 4 taken 951 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 951 times.
✓ Branch 7 taken 288 times.
|
1239 | } else if (value[i + 2] == '3' && value[i + 3] == '3') { |
| 2005 | 951 | special_char = true; | |
| 2006 | 951 | c = '!'; // "!" | |
| 2007 |
5/6✓ Branch 1 taken 221 times.
✓ Branch 2 taken 67 times.
✓ Branch 4 taken 221 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 221 times.
✓ Branch 7 taken 67 times.
|
288 | } else if (value[i + 2] == '4' && value[i + 3] == '4') { |
| 2008 | 221 | special_char = true; | |
| 2009 | 221 | c = ','; // "," | |
| 2010 |
3/6✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 67 times.
✗ Branch 7 not taken.
|
67 | } else if (value[i + 2] == '5' && value[i + 3] == '9') { |
| 2011 | 67 | special_char = true; | |
| 2012 | 67 | c = ';'; // ";" | |
| 2013 | } | ||
| 2014 | } | ||
| 2015 | |||
| 2016 |
2/2✓ Branch 0 taken 1239 times.
✓ Branch 1 taken 583642101 times.
|
583643340 | if (special_char) { |
| 2017 | 1239 | special_char = false; | |
| 2018 | 1239 | i += 3; | |
| 2019 |
1/1✓ Branch 1 taken 1239 times.
|
1239 | result.push_back(c); |
| 2020 | } else { | ||
| 2021 |
1/1✓ Branch 2 taken 583642101 times.
|
583642101 | result.push_back(value[i]); |
| 2022 | } | ||
| 2023 | } | ||
| 2024 | 53901950 | return result; | |
| 2025 | ✗ | } | |
| 2026 | |||
| 2027 | } // namespace detail | ||
| 2028 | |||
| 2029 | // CONSTRUCTORS | ||
| 2030 | |||
| 2031 | 225262 | IdfObject::IdfObject(IddObjectType type, bool fastName) : m_impl(std::make_shared<detail::IdfObject_Impl>(type, fastName)) { | |
| 2032 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 225262 times.
✗ Branch 4 not taken.
|
225262 | OS_ASSERT(m_impl); |
| 2033 | 225262 | } | |
| 2034 | |||
| 2035 | 21861 | IdfObject::IdfObject(const IddObject& iddObject, bool fastName) : m_impl(std::make_shared<detail::IdfObject_Impl>(iddObject, fastName)) { | |
| 2036 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 21861 times.
✗ Branch 4 not taken.
|
21861 | OS_ASSERT(m_impl); |
| 2037 | 21861 | } | |
| 2038 | |||
| 2039 | 56135600 | IdfObject::IdfObject(std::shared_ptr<detail::IdfObject_Impl> impl) : m_impl(std::move(impl)) { | |
| 2040 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 56135600 times.
✗ Branch 4 not taken.
|
56135600 | OS_ASSERT(m_impl); |
| 2041 | 56135600 | } | |
| 2042 | |||
| 2043 | 15663452 | IdfObject::IdfObject(const IdfObject& other) : m_impl(other.m_impl) { | |
| 2044 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 15663452 times.
✗ Branch 4 not taken.
|
15663452 | OS_ASSERT(m_impl); |
| 2045 | 15663452 | } | |
| 2046 | |||
| 2047 | 3141 | IdfObject& IdfObject::operator=(const IdfObject& other) { | |
| 2048 | 3141 | m_impl = other.m_impl; | |
| 2049 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3141 times.
|
3141 | OS_ASSERT(m_impl); |
| 2050 | 3141 | return *this; | |
| 2051 | } | ||
| 2052 | |||
| 2053 | 62082914 | IdfObject::IdfObject(IdfObject&& other) noexcept : m_impl(std::move(other.m_impl)) {} | |
| 2054 | |||
| 2055 | 10607304 | IdfObject& IdfObject::operator=(IdfObject&& other) noexcept { | |
| 2056 | 10607304 | m_impl = std::move(other.m_impl); | |
| 2057 | 10607304 | return *this; | |
| 2058 | } | ||
| 2059 | |||
| 2060 | 2 | IdfObject IdfObject::clone(bool keepHandle) const { | |
| 2061 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | IdfObject copy(std::make_shared<detail::IdfObject_Impl>(*m_impl, keepHandle)); |
| 2062 | 2 | return copy; | |
| 2063 | } | ||
| 2064 | |||
| 2065 | // GETTERS | ||
| 2066 | |||
| 2067 | 14027445 | Handle IdfObject::handle() const { | |
| 2068 | 14027445 | return m_impl->handle(); | |
| 2069 | } | ||
| 2070 | |||
| 2071 | 55746635 | IddObject IdfObject::iddObject() const { | |
| 2072 | 55746635 | return m_impl->iddObject(); | |
| 2073 | } | ||
| 2074 | |||
| 2075 | 165 | std::string IdfObject::comment() const { | |
| 2076 | 165 | return m_impl->comment(); | |
| 2077 | } | ||
| 2078 | |||
| 2079 | 27 | boost::optional<std::string> IdfObject::fieldComment(unsigned index, bool returnDefault) const { | |
| 2080 | 27 | return m_impl->fieldComment(index, returnDefault); | |
| 2081 | } | ||
| 2082 | |||
| 2083 | 30493554 | boost::optional<std::string> IdfObject::name(bool returnDefault) const { | |
| 2084 | 30493554 | return m_impl->name(returnDefault); | |
| 2085 | } | ||
| 2086 | |||
| 2087 | 423355 | std::string IdfObject::nameString(bool returnDefault) const { | |
| 2088 | 423355 | return m_impl->nameString(returnDefault); | |
| 2089 | } | ||
| 2090 | |||
| 2091 | 70106 | std::string IdfObject::briefDescription() const { | |
| 2092 | 70106 | return m_impl->briefDescription(); | |
| 2093 | } | ||
| 2094 | |||
| 2095 | 916 | bool IdfObject::isEmpty(unsigned index) const { | |
| 2096 | 916 | return m_impl->isEmpty(index); | |
| 2097 | } | ||
| 2098 | |||
| 2099 | 698428 | boost::optional<std::string> IdfObject::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const { | |
| 2100 | 698428 | return m_impl->getString(index, returnDefault, returnUninitializedEmpty); | |
| 2101 | } | ||
| 2102 | |||
| 2103 | ✗ | boost::optional<std::string> IdfObject::getField(unsigned index, bool returnDefault) const { | |
| 2104 | ✗ | return m_impl->getField(index, returnDefault); | |
| 2105 | } | ||
| 2106 | |||
| 2107 | 275736 | boost::optional<double> IdfObject::getDouble(unsigned index, bool returnDefault) const { | |
| 2108 | 275736 | return m_impl->getDouble(index, returnDefault); | |
| 2109 | } | ||
| 2110 | |||
| 2111 | 2 | OSOptionalQuantity IdfObject::getQuantity(unsigned index, bool returnDefault, bool returnIP) const { | |
| 2112 | 2 | return m_impl->getQuantity(index, returnDefault, returnIP); | |
| 2113 | } | ||
| 2114 | |||
| 2115 | 5 | OptionalUnsigned IdfObject::getUnsigned(unsigned index, bool returnDefault) const { | |
| 2116 | 5 | return m_impl->getUnsigned(index, returnDefault); | |
| 2117 | } | ||
| 2118 | |||
| 2119 | 155438 | OptionalInt IdfObject::getInt(unsigned index, bool returnDefault) const { | |
| 2120 | 155438 | return m_impl->getInt(index, returnDefault); | |
| 2121 | } | ||
| 2122 | |||
| 2123 | 1911 | IdfExtensibleGroup IdfObject::getExtensibleGroup(unsigned groupIndex) const { | |
| 2124 | 1911 | return m_impl->getExtensibleGroup(groupIndex); | |
| 2125 | } | ||
| 2126 | |||
| 2127 | 60067 | std::vector<IdfExtensibleGroup> IdfObject::extensibleGroups() const { | |
| 2128 | 60067 | return m_impl->extensibleGroups(); | |
| 2129 | } | ||
| 2130 | |||
| 2131 | // SETTERS | ||
| 2132 | |||
| 2133 | 73 | void IdfObject::setComment(const std::string& msg) { | |
| 2134 | 73 | return m_impl->setComment(msg); | |
| 2135 | } | ||
| 2136 | |||
| 2137 | 8 | bool IdfObject::setFieldComment(unsigned index, const std::string& cmnt) { | |
| 2138 | 8 | return m_impl->setFieldComment(index, cmnt); | |
| 2139 | } | ||
| 2140 | |||
| 2141 | 106200 | boost::optional<std::string> IdfObject::setName(const std::string& newName) { | |
| 2142 | 106200 | return m_impl->setName(newName); | |
| 2143 | } | ||
| 2144 | |||
| 2145 | 99 | boost::optional<std::string> IdfObject::createName(bool overwrite) { | |
| 2146 | 99 | return m_impl->createName(overwrite); | |
| 2147 | } | ||
| 2148 | |||
| 2149 | 447594 | bool IdfObject::setString(unsigned index, const std::string& value) { | |
| 2150 | 447594 | return m_impl->setString(index, value); | |
| 2151 | } | ||
| 2152 | |||
| 2153 | 190896 | bool IdfObject::setDouble(unsigned index, double value) { | |
| 2154 | 190896 | return m_impl->setDouble(index, value); | |
| 2155 | } | ||
| 2156 | |||
| 2157 | 1 | bool IdfObject::setQuantity(unsigned index, const Quantity& q) { | |
| 2158 | 1 | return m_impl->setQuantity(index, q); | |
| 2159 | } | ||
| 2160 | |||
| 2161 | 35 | bool IdfObject::setUnsigned(unsigned index, unsigned value) { | |
| 2162 | 35 | return m_impl->setUnsigned(index, value); | |
| 2163 | } | ||
| 2164 | |||
| 2165 | 11029 | bool IdfObject::setInt(unsigned index, int value) { | |
| 2166 | 11029 | return m_impl->setInt(index, value); | |
| 2167 | } | ||
| 2168 | |||
| 2169 | 41766 | IdfExtensibleGroup IdfObject::pushExtensibleGroup() { | |
| 2170 |
1/1✓ Branch 2 taken 41766 times.
|
41766 | return pushExtensibleGroup(StringVector()); |
| 2171 | } | ||
| 2172 | |||
| 2173 | 49172 | IdfExtensibleGroup IdfObject::pushExtensibleGroup(const StringVector& values) { | |
| 2174 | 49172 | return m_impl->pushExtensibleGroup(values); | |
| 2175 | } | ||
| 2176 | |||
| 2177 | 5 | IdfExtensibleGroup IdfObject::insertExtensibleGroup(unsigned groupIndex) { | |
| 2178 |
1/1✓ Branch 2 taken 5 times.
|
5 | return insertExtensibleGroup(groupIndex, StringVector()); |
| 2179 | } | ||
| 2180 | |||
| 2181 | 15 | IdfExtensibleGroup IdfObject::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values) { | |
| 2182 | 15 | return m_impl->insertExtensibleGroup(groupIndex, values); | |
| 2183 | } | ||
| 2184 | |||
| 2185 | 3108 | std::vector<std::string> IdfObject::popExtensibleGroup() { | |
| 2186 | 3108 | return m_impl->popExtensibleGroup(); | |
| 2187 | } | ||
| 2188 | |||
| 2189 | 296 | std::vector<std::string> IdfObject::eraseExtensibleGroup(unsigned groupIndex) { | |
| 2190 | 296 | return m_impl->eraseExtensibleGroup(groupIndex); | |
| 2191 | } | ||
| 2192 | |||
| 2193 | 10701 | std::vector<std::vector<std::string>> IdfObject::clearExtensibleGroups() { | |
| 2194 | 10701 | return m_impl->clearExtensibleGroups(); | |
| 2195 | } | ||
| 2196 | |||
| 2197 | 5 | void IdfObject::initializeFields(bool fill_default) { | |
| 2198 | 5 | return m_impl->initializeFields(fill_default); | |
| 2199 | } | ||
| 2200 | |||
| 2201 | // QUERIES | ||
| 2202 | |||
| 2203 | 1866775 | unsigned IdfObject::numFields() const { | |
| 2204 | 1866775 | return m_impl->numFields(); | |
| 2205 | } | ||
| 2206 | |||
| 2207 | 2348 | unsigned IdfObject::numNonextensibleFields() const { | |
| 2208 | 2348 | return m_impl->numNonextensibleFields(); | |
| 2209 | } | ||
| 2210 | |||
| 2211 | 2 | unsigned IdfObject::minFields() const { | |
| 2212 | 2 | return m_impl->minFields(); | |
| 2213 | } | ||
| 2214 | |||
| 2215 | ✗ | boost::optional<unsigned> IdfObject::maxFields() const { | |
| 2216 | ✗ | return m_impl->maxFields(); | |
| 2217 | } | ||
| 2218 | |||
| 2219 | 1273 | unsigned IdfObject::numExtensibleGroups() const { | |
| 2220 | 1273 | return m_impl->numExtensibleGroups(); | |
| 2221 | } | ||
| 2222 | |||
| 2223 | ✗ | unsigned IdfObject::minExtensibleGroups() const { | |
| 2224 | ✗ | return m_impl->minExtensibleGroups(); | |
| 2225 | } | ||
| 2226 | |||
| 2227 | ✗ | boost::optional<unsigned> IdfObject::maxExtensibleGroups() const { | |
| 2228 | ✗ | return m_impl->maxExtensibleGroups(); | |
| 2229 | } | ||
| 2230 | |||
| 2231 | ✗ | bool IdfObject::isObjectListField(unsigned index) const { | |
| 2232 | ✗ | return m_impl->isObjectListField(index); | |
| 2233 | } | ||
| 2234 | |||
| 2235 | 2179 | std::vector<unsigned> IdfObject::objectListFields() const { | |
| 2236 | 2179 | return m_impl->objectListFields(); | |
| 2237 | } | ||
| 2238 | |||
| 2239 | ✗ | bool IdfObject::isDataField(unsigned index) const { | |
| 2240 | ✗ | return m_impl->isDataField(index); | |
| 2241 | } | ||
| 2242 | |||
| 2243 | 2321 | std::vector<unsigned> IdfObject::dataFields() const { | |
| 2244 | 2321 | return m_impl->dataFields(); | |
| 2245 | } | ||
| 2246 | |||
| 2247 | ✗ | std::vector<unsigned> IdfObject::requiredFields() const { | |
| 2248 | ✗ | return m_impl->requiredFields(); | |
| 2249 | } | ||
| 2250 | |||
| 2251 | 182935 | bool IdfObject::isValid(StrictnessLevel level, bool checkNames) const { | |
| 2252 | 182935 | return m_impl->isValid(level, checkNames); | |
| 2253 | } | ||
| 2254 | |||
| 2255 | 1365 | ValidityReport IdfObject::validityReport(StrictnessLevel level, bool checkNames) const { | |
| 2256 | 1365 | return m_impl->validityReport(level, checkNames); | |
| 2257 | } | ||
| 2258 | |||
| 2259 | 2321 | bool IdfObject::dataFieldsEqual(const IdfObject& other) const { | |
| 2260 | 2321 | return m_impl->dataFieldsEqual(other); | |
| 2261 | } | ||
| 2262 | |||
| 2263 | ✗ | bool IdfObject::objectListFieldsEqual(const IdfObject& other) const { | |
| 2264 | ✗ | return m_impl->objectListFieldsEqual(other); | |
| 2265 | } | ||
| 2266 | |||
| 2267 | 12 | bool IdfObject::objectListFieldsNonConflicting(const IdfObject& other) const { | |
| 2268 | 12 | return m_impl->objectListFieldsNonConflicting(other); | |
| 2269 | } | ||
| 2270 | |||
| 2271 | 2036477 | bool IdfObject::operator==(const IdfObject& other) const { | |
| 2272 | 2036477 | return (m_impl == other.m_impl); | |
| 2273 | } | ||
| 2274 | |||
| 2275 | 74044 | bool IdfObject::operator!=(const IdfObject& other) const { | |
| 2276 | 74044 | return !(operator==(other)); | |
| 2277 | } | ||
| 2278 | |||
| 2279 | // SERIALIZATION | ||
| 2280 | |||
| 2281 | 302 | OptionalIdfObject IdfObject::load(const std::string& text) { | |
| 2282 |
1/1✓ Branch 1 taken 302 times.
|
302 | std::shared_ptr<detail::IdfObject_Impl> p = detail::IdfObject_Impl::load(text); |
| 2283 |
1/2✓ Branch 1 taken 302 times.
✗ Branch 2 not taken.
|
302 | if (p) { |
| 2284 |
2/2✓ Branch 2 taken 302 times.
✓ Branch 5 taken 302 times.
|
302 | return IdfObject(p); |
| 2285 | } | ||
| 2286 | ✗ | return boost::none; | |
| 2287 | 302 | } | |
| 2288 | |||
| 2289 | 1250333 | OptionalIdfObject IdfObject::load(const std::string& text, const IddObject& iddObject) { | |
| 2290 |
1/1✓ Branch 1 taken 1250333 times.
|
1250333 | std::shared_ptr<detail::IdfObject_Impl> p = detail::IdfObject_Impl::load(text, iddObject); |
| 2291 |
1/2✓ Branch 1 taken 1250333 times.
✗ Branch 2 not taken.
|
1250333 | if (p) { |
| 2292 |
2/2✓ Branch 2 taken 1250333 times.
✓ Branch 5 taken 1250333 times.
|
1250333 | return IdfObject(p); |
| 2293 | } | ||
| 2294 | ✗ | return boost::none; | |
| 2295 | 1250333 | } | |
| 2296 | |||
| 2297 | 10619879 | int IdfObject::printedFieldSpace() { | |
| 2298 | 10619879 | return 38; | |
| 2299 | } | ||
| 2300 | |||
| 2301 | 959824 | std::ostream& IdfObject::print(std::ostream& os) const { | |
| 2302 | 959824 | return m_impl->print(os); | |
| 2303 | } | ||
| 2304 | |||
| 2305 | 5 | std::ostream& IdfObject::printName(std::ostream& os, bool hasFields) const { | |
| 2306 | 5 | return m_impl->printName(os, hasFields); | |
| 2307 | } | ||
| 2308 | |||
| 2309 | 33 | std::ostream& IdfObject::printField(std::ostream& os, unsigned index, bool isLastField) const { | |
| 2310 | 33 | return m_impl->printField(os, index, isLastField); | |
| 2311 | } | ||
| 2312 | |||
| 2313 | /** Function object for sorting by name. */ | ||
| 2314 | 324522 | bool IdfObjectNameLess::operator()(const IdfObject& left, const IdfObject& right) const { | |
| 2315 |
1/1✓ Branch 1 taken 324522 times.
|
324522 | boost::optional<std::string> leftName = left.name(); |
| 2316 |
1/1✓ Branch 1 taken 324522 times.
|
324522 | boost::optional<std::string> rightName = right.name(); |
| 2317 | |||
| 2318 | 324522 | bool result = false; | |
| 2319 |
3/6✓ Branch 0 taken 324522 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 324522 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 324522 times.
✗ Branch 5 not taken.
|
649044 | if (leftName && rightName) { |
| 2320 | // a < b | ||
| 2321 |
3/3✓ Branch 1 taken 324522 times.
✓ Branch 4 taken 324522 times.
✓ Branch 7 taken 324522 times.
|
324522 | result = istringLess(*leftName, *rightName); |
| 2322 | ✗ | } else if (!leftName && rightName) { | |
| 2323 | // nil < !nil | ||
| 2324 | ✗ | result = true; | |
| 2325 | } | ||
| 2326 | 324522 | return result; | |
| 2327 | 324522 | } | |
| 2328 | |||
| 2329 | /** Function object for sorting by impl. */ | ||
| 2330 | 1414 | bool IdfObjectImplLess::operator()(const IdfObject& left, const IdfObject& right) const { | |
| 2331 | 1414 | return (left.getImpl<detail::IdfObject_Impl>() < right.getImpl<detail::IdfObject_Impl>()); | |
| 2332 | } | ||
| 2333 | |||
| 2334 | /** Function object for sorting by IddObjectType. */ | ||
| 2335 | ✗ | bool IdfObjectTypeLess::operator()(const IdfObject& left, const IdfObject& right) const { | |
| 2336 | ✗ | return (left.iddObject().type() < right.iddObject().type()); | |
| 2337 | } | ||
| 2338 | |||
| 2339 | // ostream operator | ||
| 2340 | 860303 | std::ostream& operator<<(std::ostream& os, const IdfObject& idfObject) { | |
| 2341 | 860303 | return idfObject.print(os); | |
| 2342 | } | ||
| 2343 | |||
| 2344 | ✗ | std::string objectName(const IdfObject& obj) { | |
| 2345 | ✗ | std::string result; | |
| 2346 | ✗ | if (obj.name()) { | |
| 2347 | ✗ | result = obj.name().get(); | |
| 2348 | } else { | ||
| 2349 | ✗ | result = obj.iddObject().name(); | |
| 2350 | } | ||
| 2351 | ✗ | return result; | |
| 2352 | ✗ | } | |
| 2353 | |||
| 2354 | } // namespace openstudio | ||
| 2355 |