src/utilities/idd/IddObject.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 "IddObject.hpp" | ||
| 7 | #include "IddObject_Impl.hpp" | ||
| 8 | |||
| 9 | #include "ExtensibleIndex.hpp" | ||
| 10 | #include "IddRegex.hpp" | ||
| 11 | #include <utilities/idd/IddFactory.hxx> | ||
| 12 | #include <utilities/idd/IddEnums.hxx> | ||
| 13 | #include "IddKey.hpp" | ||
| 14 | #include "CommentRegex.hpp" | ||
| 15 | |||
| 16 | #include "../core/Assert.hpp" | ||
| 17 | #include "../core/ASCIIStrings.hpp" | ||
| 18 | |||
| 19 | #include <boost/lexical_cast.hpp> | ||
| 20 | |||
| 21 | using std::string; | ||
| 22 | using std::vector; | ||
| 23 | using boost::regex; | ||
| 24 | using boost::smatch; | ||
| 25 | using boost::regex_replace; | ||
| 26 | using boost::replace_all; | ||
| 27 | |||
| 28 | namespace openstudio { | ||
| 29 | |||
| 30 | namespace detail { | ||
| 31 | |||
| 32 | // CONSTRUCTORS | ||
| 33 | |||
| 34 | /// default constructor for serialization | ||
| 35 |
3/3✓ Branch 1 taken 224583 times.
✓ Branch 5 taken 224583 times.
✓ Branch 8 taken 224583 times.
|
673749 | IddObject_Impl::IddObject_Impl() : m_name("Catchall"), m_type(IddObjectType::Catchall) { |
| 36 | 224583 | m_properties.extensible = true; | |
| 37 | 224583 | m_properties.numExtensible = 1; | |
| 38 | 224583 | m_properties.hasURL = false; | |
| 39 |
3/3✓ Branch 1 taken 224583 times.
✓ Branch 4 taken 224583 times.
✓ Branch 7 taken 224583 times.
|
898332 | OptionalIddField oField = IddField::load("Object Type", "A1, \\field Object Type \n \\type alpha", m_name); |
| 40 |
2/2✓ Branch 1 taken 224583 times.
✓ Branch 4 taken 224583 times.
|
224583 | m_fields.push_back(*oField); |
| 41 |
3/3✓ Branch 1 taken 224583 times.
✓ Branch 4 taken 224583 times.
✓ Branch 7 taken 224583 times.
|
898332 | oField = IddField::load("Generic Data Field", "A2; \\field Generic Data Field \n \\type alpha \n \\begin-extensible", m_name); |
| 42 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 224583 times.
✗ Branch 4 not taken.
|
224583 | OS_ASSERT(oField); |
| 43 |
2/2✓ Branch 1 taken 224583 times.
✓ Branch 4 taken 224583 times.
|
224583 | m_extensibleFields.push_back(*oField); |
| 44 | 224583 | } | |
| 45 | |||
| 46 | // GETTERS | ||
| 47 | |||
| 48 | 136701052 | std::string IddObject_Impl::name() const { | |
| 49 | 136701052 | return m_name; | |
| 50 | } | ||
| 51 | |||
| 52 | 51823997 | IddObjectType IddObject_Impl::type() const { | |
| 53 | 51823997 | return m_type; | |
| 54 | } | ||
| 55 | |||
| 56 | 61131 | std::string IddObject_Impl::group() const { | |
| 57 | 61131 | return m_group; | |
| 58 | } | ||
| 59 | |||
| 60 | 39461395 | const IddObjectProperties& IddObject_Impl::properties() const { | |
| 61 | 39461395 | return m_properties; | |
| 62 | } | ||
| 63 | |||
| 64 | 201322 | const IddFieldVector& IddObject_Impl::nonextensibleFields() const { | |
| 65 | 201322 | return m_fields; | |
| 66 | } | ||
| 67 | |||
| 68 | 135414 | const IddFieldVector& IddObject_Impl::extensibleGroup() const { | |
| 69 | 135414 | return m_extensibleFields; | |
| 70 | } | ||
| 71 | |||
| 72 | 99248775 | boost::optional<IddField> IddObject_Impl::getField(unsigned index) const { | |
| 73 | 99248775 | OptionalIddField field; | |
| 74 | |||
| 75 | // is index in the regular fields | ||
| 76 |
2/2✓ Branch 1 taken 60530384 times.
✓ Branch 2 taken 38718391 times.
|
99248775 | if (index < m_fields.size()) { |
| 77 |
1/1✓ Branch 2 taken 60530384 times.
|
60530384 | field = m_fields[index]; |
| 78 |
2/2✓ Branch 1 taken 38718377 times.
✓ Branch 2 taken 14 times.
|
38718391 | } else if (!m_extensibleFields.empty()) { |
| 79 | // if not subtract out fields size and mod by number of extensible fields | ||
| 80 | 38718377 | index = index - m_fields.size(); | |
| 81 | 38718377 | index = index % m_extensibleFields.size(); | |
| 82 |
1/1✓ Branch 2 taken 38718377 times.
|
38718377 | field = m_extensibleFields[index]; |
| 83 | } | ||
| 84 | |||
| 85 | 99248775 | return field; | |
| 86 | ✗ | } | |
| 87 | |||
| 88 | 14 | boost::optional<IddField> IddObject_Impl::getField(const std::string& fieldName) const { | |
| 89 | 14 | OptionalIddField result; | |
| 90 | |||
| 91 | // look in fields | ||
| 92 |
2/2✓ Branch 5 taken 102 times.
✓ Branch 6 taken 8 times.
|
110 | for (const IddField& field : m_fields) { |
| 93 |
4/4✓ Branch 2 taken 102 times.
✓ Branch 5 taken 102 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 96 times.
|
102 | if (boost::iequals(field.name(), fieldName)) { |
| 94 |
1/1✓ Branch 1 taken 6 times.
|
6 | result = field; |
| 95 | 6 | break; | |
| 96 | } | ||
| 97 | } | ||
| 98 | // look in extensible fields | ||
| 99 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 6 times.
|
14 | if (!result) { |
| 100 |
2/2✓ Branch 5 taken 20 times.
✓ Branch 6 taken 4 times.
|
24 | for (const IddField& field : m_extensibleFields) { |
| 101 |
4/4✓ Branch 2 taken 20 times.
✓ Branch 5 taken 20 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 16 times.
|
20 | if (boost::iequals(field.name(), fieldName)) { |
| 102 |
1/1✓ Branch 1 taken 4 times.
|
4 | result = field; |
| 103 | 4 | break; | |
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | 14 | return result; | |
| 109 | ✗ | } | |
| 110 | |||
| 111 | 9504 | boost::optional<int> IddObject_Impl::getFieldIndex(const std::string& fieldName) const { | |
| 112 | 9504 | OptionalInt result; | |
| 113 | 9504 | int index = 0; | |
| 114 | |||
| 115 | // look in fields | ||
| 116 |
1/2✓ Branch 4 taken 17008 times.
✗ Branch 5 not taken.
|
17008 | for (const IddField& field : m_fields) { |
| 117 |
4/4✓ Branch 2 taken 17008 times.
✓ Branch 5 taken 17008 times.
✓ Branch 9 taken 9504 times.
✓ Branch 10 taken 7504 times.
|
17008 | if (boost::iequals(field.name(), fieldName)) { |
| 118 |
1/1✓ Branch 1 taken 9504 times.
|
9504 | result = index; |
| 119 | 9504 | break; | |
| 120 | } | ||
| 121 | 7504 | ++index; | |
| 122 | } | ||
| 123 | |||
| 124 | // look in extensible fields | ||
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9504 times.
|
9504 | if (!result) { |
| 126 | ✗ | for (const IddField& field : m_extensibleFields) { | |
| 127 | ✗ | if (boost::iequals(field.name(), fieldName)) { | |
| 128 | ✗ | result = index; | |
| 129 | ✗ | break; | |
| 130 | } | ||
| 131 | ✗ | ++index; | |
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | 9504 | return result; | |
| 136 | } | ||
| 137 | |||
| 138 | // SETTERS | ||
| 139 | |||
| 140 | 1 | void IddObject_Impl::insertHandleField() { | |
| 141 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | if (!hasHandleField()) { |
| 142 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::stringstream fieldText; |
| 143 |
5/5✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
|
1 | fieldText << " A1, \\field Handle" << '\n' << " \\type handle" << '\n' << " \\required-field"; |
| 144 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
3 | IddField handleField = IddField::load("Handle", fieldText.str(), m_name).get(); |
| 145 |
1/1✓ Branch 3 taken 1 time.
|
1 | auto it = m_fields.insert(m_fields.begin(), handleField); |
| 146 | 1 | ++it; | |
| 147 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 time.
|
5 | for (auto itEnd = m_fields.end(); it != itEnd; ++it) { |
| 148 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
|
4 | it->incrementFieldId(); // by default, applies only to 'A'-type fields |
| 149 | } | ||
| 150 | 1 | it = m_extensibleFields.begin(); | |
| 151 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
|
1 | for (auto itEnd = m_extensibleFields.end(); it != itEnd; ++it) { |
| 152 | ✗ | it->incrementFieldId(); // by default, applies only to 'A'-type fields | |
| 153 | } | ||
| 154 | 1 | ++m_properties.minFields; | |
| 155 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
2 | if (m_properties.maxFields) { |
| 156 | ✗ | unsigned newMaxFields = m_properties.maxFields.get() + 1; | |
| 157 | ✗ | m_properties.maxFields = newMaxFields; | |
| 158 | } | ||
| 159 | 1 | } | |
| 160 | 1 | } | |
| 161 | |||
| 162 | // QUERIES | ||
| 163 | |||
| 164 | 9311203 | unsigned IddObject_Impl::numFields() const { | |
| 165 | 9311203 | return m_fields.size(); | |
| 166 | } | ||
| 167 | |||
| 168 | 1675925 | unsigned IddObject_Impl::numFieldsInDefaultObject() const { | |
| 169 | 1675925 | unsigned result = m_properties.minFields; | |
| 170 | |||
| 171 | // check for non-extensible required fields | ||
| 172 | 1675925 | unsigned index = result; | |
| 173 | 1675925 | unsigned n = numFields(); | |
| 174 |
2/2✓ Branch 0 taken 6078289 times.
✓ Branch 1 taken 1675925 times.
|
7754214 | while (index < n) { |
| 175 |
2/2✓ Branch 2 taken 1968651 times.
✓ Branch 3 taken 4109638 times.
|
6078289 | if (m_fields[index].properties().required) { |
| 176 | 1968651 | result = index + 1; | |
| 177 | } | ||
| 178 | 6078289 | ++index; | |
| 179 | } | ||
| 180 | |||
| 181 | // do not pre-create extensible groups, so user can directly call | ||
| 182 | // .pushExtensibleGroup, without preceding it with a .clearExtensibleGroups. | ||
| 183 |
2/2✓ Branch 0 taken 622029 times.
✓ Branch 1 taken 1053896 times.
|
1675925 | if (result > n) { |
| 184 | 622029 | result = n; | |
| 185 | } | ||
| 186 | |||
| 187 | 1675925 | return result; | |
| 188 | } | ||
| 189 | |||
| 190 | 1271653 | bool IddObject_Impl::isVersionObject() const { | |
| 191 |
15/17✓ Branch 1 taken 1271653 times.
✓ Branch 4 taken 1271653 times.
✓ Branch 7 taken 1268263 times.
✓ Branch 8 taken 3390 times.
✓ Branch 10 taken 1268263 times.
✓ Branch 13 taken 1268263 times.
✓ Branch 16 taken 1262118 times.
✓ Branch 17 taken 6145 times.
✓ Branch 19 taken 1262118 times.
✓ Branch 22 taken 1262118 times.
✓ Branch 25 taken 1262118 times.
✓ Branch 27 taken 11449 times.
✓ Branch 28 taken 1250669 times.
✓ Branch 29 taken 1262118 times.
✓ Branch 30 taken 9535 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
|
1271653 | return (type() == IddObjectType::Version) || (type() == IddObjectType::OS_Version) || (boost::regex_match(name(), iddRegex::versionObjectName())); |
| 192 | } | ||
| 193 | |||
| 194 | 6732206 | bool IddObject_Impl::isNonextensibleField(unsigned index) const { | |
| 195 |
2/2✓ Branch 1 taken 4968835 times.
✓ Branch 2 taken 1763371 times.
|
6732206 | if (index < m_fields.size()) { |
| 196 | 4968835 | return true; | |
| 197 | } | ||
| 198 | 1763371 | return false; | |
| 199 | } | ||
| 200 | |||
| 201 | 32495443 | bool IddObject_Impl::isExtensibleField(unsigned index) const { | |
| 202 |
6/6✓ Branch 1 taken 20354993 times.
✓ Branch 2 taken 12140450 times.
✓ Branch 3 taken 20354979 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 20354979 times.
✓ Branch 6 taken 12140464 times.
|
32495443 | if ((index >= m_fields.size()) && (m_properties.extensible)) { |
| 203 | 20354979 | return true; | |
| 204 | } | ||
| 205 | 12140464 | return false; | |
| 206 | } | ||
| 207 | |||
| 208 | 3129298 | bool IddObject_Impl::hasHandleField() const { | |
| 209 |
6/6✓ Branch 1 taken 3060693 times.
✓ Branch 2 taken 68605 times.
✓ Branch 4 taken 3060693 times.
✓ Branch 8 taken 3060693 times.
✓ Branch 11 taken 2259440 times.
✓ Branch 12 taken 801253 times.
|
3129298 | return ((!m_fields.empty()) && (m_fields[0].properties().type == IddFieldType::HandleType)); |
| 210 | } | ||
| 211 | |||
| 212 | 50105163 | bool IddObject_Impl::hasNameField() const { | |
| 213 |
2/2✓ Branch 1 taken 50027777 times.
✓ Branch 2 taken 77386 times.
|
100210326 | if (m_nameFieldCache) { |
| 214 |
1/1✓ Branch 1 taken 50027777 times.
|
50027777 | return m_nameFieldCache->first; |
| 215 | } | ||
| 216 | |||
| 217 | 77386 | unsigned index = 0; | |
| 218 |
3/3✓ Branch 1 taken 77386 times.
✓ Branch 3 taken 51444 times.
✓ Branch 4 taken 25942 times.
|
77386 | if (hasHandleField()) { |
| 219 | 51444 | index = 1; | |
| 220 | } | ||
| 221 |
5/5✓ Branch 1 taken 75589 times.
✓ Branch 2 taken 1797 times.
✓ Branch 5 taken 75589 times.
✓ Branch 7 taken 52007 times.
✓ Branch 8 taken 23582 times.
|
77386 | bool result = ((m_fields.size() > index) && (m_fields[index].isNameField())); |
| 222 |
1/1✓ Branch 2 taken 77386 times.
|
77386 | m_nameFieldCache = std::pair<bool, unsigned>(result, index); |
| 223 | 77386 | return result; | |
| 224 | } | ||
| 225 | |||
| 226 | 42523993 | boost::optional<unsigned> IddObject_Impl::nameFieldIndex() const { | |
| 227 |
2/2✓ Branch 1 taken 41286332 times.
✓ Branch 2 taken 1237661 times.
|
42523993 | if (hasNameField()) { |
| 228 |
2/2✓ Branch 1 taken 41286332 times.
✓ Branch 4 taken 41286332 times.
|
41286332 | return m_nameFieldCache->second; |
| 229 | } | ||
| 230 | 1237661 | return boost::none; | |
| 231 | } | ||
| 232 | |||
| 233 | 199643 | bool IddObject_Impl::isRequiredField(unsigned index) const { | |
| 234 |
1/1✓ Branch 1 taken 199643 times.
|
199643 | OptionalIddField iddField = getField(index); |
| 235 |
1/2✓ Branch 0 taken 199643 times.
✗ Branch 1 not taken.
|
199643 | if (iddField) { |
| 236 |
2/2✓ Branch 1 taken 199643 times.
✓ Branch 4 taken 199643 times.
|
199643 | return iddField->properties().required; |
| 237 | } | ||
| 238 | ✗ | return false; | |
| 239 | 199643 | } | |
| 240 | |||
| 241 | 384 | bool IddObject_Impl::hasURL() const { | |
| 242 | 384 | return m_properties.hasURL; | |
| 243 | } | ||
| 244 | |||
| 245 | 12582082 | ExtensibleIndex IddObject_Impl::extensibleIndex(unsigned index) const { | |
| 246 |
2/3✓ Branch 1 taken 12582082 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12582082 times.
|
12582082 | if (!isExtensibleField(index)) { |
| 247 | ✗ | LOG_AND_THROW("Field " << index << " is not an extensible field in IddObject " << name() << "."); | |
| 248 | } | ||
| 249 |
1/1✓ Branch 1 taken 12582082 times.
|
12582082 | ExtensibleIndex result(0, 0); |
| 250 | 12582082 | result.field = (index - m_fields.size()) % m_properties.numExtensible; | |
| 251 | 12582082 | result.group = (index - result.field - m_fields.size()) / m_properties.numExtensible; | |
| 252 | 12582082 | return result; | |
| 253 | } | ||
| 254 | |||
| 255 | 12239868 | unsigned IddObject_Impl::index(ExtensibleIndex extensibleIndex) const { | |
| 256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12239868 times.
|
12239868 | if (!m_properties.extensible) { |
| 257 | ✗ | LOG_AND_THROW("IddObject " << name() << " does not have extensible fields."); | |
| 258 | } | ||
| 259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12239868 times.
|
12239868 | if (extensibleIndex.field >= m_properties.numExtensible) { |
| 260 | ✗ | LOG_AND_THROW("IddObject " << name() << " only has " << m_properties.numExtensible | |
| 261 | << " fields in its extensible group. Therefore, a ExtensibleIndex.field of " << extensibleIndex.field | ||
| 262 | << " is invalid."); | ||
| 263 | } | ||
| 264 | 12239868 | return m_fields.size() + extensibleIndex.group * m_properties.numExtensible + extensibleIndex.field; | |
| 265 | } | ||
| 266 | |||
| 267 | 781895 | std::vector<std::string> IddObject_Impl::references() const { | |
| 268 | 781895 | std::vector<std::string> result; | |
| 269 |
3/3✓ Branch 1 taken 781895 times.
✓ Branch 3 taken 642256 times.
✓ Branch 4 taken 139639 times.
|
1563790 | if (OptionalUnsigned index = nameFieldIndex()) { |
| 270 |
3/3✓ Branch 1 taken 642256 times.
✓ Branch 5 taken 642256 times.
✓ Branch 8 taken 642256 times.
|
642256 | result = m_fields[*index].properties().references; |
| 271 | // To ensure uniqueness of name within a given class, we add a fake reference by class | ||
| 272 | // https://github.com/NREL/OpenStudio/issues/3079 | ||
| 273 | //if (result.empty()) { | ||
| 274 |
1/1✓ Branch 1 taken 642256 times.
|
642256 | std::string ref = name(); |
| 275 |
2/2✓ Branch 1 taken 642256 times.
✓ Branch 4 taken 642256 times.
|
642256 | result.push_back(ref + "UniqueNames"); |
| 276 | //} | ||
| 277 | 642256 | } else { | |
| 278 |
1/1✓ Branch 1 taken 139639 times.
|
139639 | std::string n = name(); |
| 279 |
3/3✓ Branch 1 taken 139639 times.
✓ Branch 3 taken 21229 times.
✓ Branch 4 taken 118410 times.
|
139639 | if (n == "OS:PortList") { |
| 280 |
2/2✓ Branch 1 taken 21229 times.
✓ Branch 4 taken 21229 times.
|
42458 | result.push_back("ConnectionObject"); |
| 281 |
2/2✓ Branch 1 taken 21229 times.
✓ Branch 4 taken 21229 times.
|
42458 | result.push_back("PortLists"); |
| 282 |
3/3✓ Branch 1 taken 118410 times.
✓ Branch 3 taken 45634 times.
✓ Branch 4 taken 72776 times.
|
118410 | } else if (n == "OS:Connection") { |
| 283 |
2/2✓ Branch 1 taken 45634 times.
✓ Branch 4 taken 45634 times.
|
91268 | result.push_back("ConnectionNames"); |
| 284 | } | ||
| 285 | 139639 | } | |
| 286 | |||
| 287 | 781895 | return result; | |
| 288 | ✗ | } | |
| 289 | |||
| 290 | 390237 | std::set<std::string> IddObject_Impl::objectLists() const { | |
| 291 | 390237 | std::set<std::string> result; | |
| 292 |
2/2✓ Branch 5 taken 3387988 times.
✓ Branch 6 taken 390237 times.
|
3778225 | for (const IddField& field : m_fields) { |
| 293 |
1/1✓ Branch 1 taken 3387988 times.
|
3387988 | const IddFieldProperties& properties = field.properties(); |
| 294 |
1/1✓ Branch 3 taken 3387988 times.
|
3387988 | result.insert(properties.objectLists.begin(), properties.objectLists.end()); |
| 295 | } | ||
| 296 |
2/2✓ Branch 5 taken 451617 times.
✓ Branch 6 taken 390237 times.
|
841854 | for (const IddField& field : m_extensibleFields) { |
| 297 |
1/1✓ Branch 1 taken 451617 times.
|
451617 | const IddFieldProperties& properties = field.properties(); |
| 298 |
1/1✓ Branch 3 taken 451617 times.
|
451617 | result.insert(properties.objectLists.begin(), properties.objectLists.end()); |
| 299 | } | ||
| 300 | 390237 | return result; | |
| 301 | ✗ | } | |
| 302 | |||
| 303 | 1550621 | std::set<std::string> IddObject_Impl::objectLists(unsigned index) const { | |
| 304 | 1550621 | std::set<std::string> result; | |
| 305 | |||
| 306 |
3/3✓ Branch 1 taken 1550621 times.
✓ Branch 3 taken 1461599 times.
✓ Branch 4 taken 89022 times.
|
1550621 | if (isNonextensibleField(index)) { |
| 307 |
1/1✓ Branch 2 taken 1461599 times.
|
1461599 | const IddFieldProperties& properties = m_fields[index].properties(); |
| 308 |
1/1✓ Branch 3 taken 1461599 times.
|
1461599 | result.insert(properties.objectLists.begin(), properties.objectLists.end()); |
| 309 |
2/3✓ Branch 1 taken 89022 times.
✓ Branch 3 taken 89022 times.
✗ Branch 4 not taken.
|
89022 | } else if (isExtensibleField(index)) { |
| 310 |
1/1✓ Branch 1 taken 89022 times.
|
89022 | ExtensibleIndex eIndex = extensibleIndex(index); |
| 311 |
1/1✓ Branch 2 taken 89022 times.
|
89022 | const IddFieldProperties& properties = m_extensibleFields[eIndex.field].properties(); |
| 312 |
1/1✓ Branch 3 taken 89022 times.
|
89022 | result.insert(properties.objectLists.begin(), properties.objectLists.end()); |
| 313 | } | ||
| 314 | |||
| 315 | 1550621 | return result; | |
| 316 | ✗ | } | |
| 317 | |||
| 318 | 404413 | UnsignedVector IddObject_Impl::objectListFields() const { | |
| 319 | |||
| 320 | 404413 | UnsignedVector result; | |
| 321 | |||
| 322 |
2/2✓ Branch 1 taken 3488542 times.
✓ Branch 2 taken 404413 times.
|
3892955 | for (unsigned index = 0; index < m_fields.size(); ++index) { |
| 323 |
3/3✓ Branch 2 taken 3488542 times.
✓ Branch 4 taken 878190 times.
✓ Branch 5 taken 2610352 times.
|
3488542 | if (m_fields[index].isObjectListField()) { |
| 324 |
1/1✓ Branch 1 taken 878190 times.
|
878190 | result.push_back(index); |
| 325 | } | ||
| 326 | } | ||
| 327 |
2/2✓ Branch 1 taken 458869 times.
✓ Branch 2 taken 404413 times.
|
863282 | for (unsigned index = 0; index < m_extensibleFields.size(); ++index) { |
| 328 |
3/3✓ Branch 2 taken 458869 times.
✓ Branch 4 taken 55838 times.
✓ Branch 5 taken 403031 times.
|
458869 | if (m_extensibleFields[index].isObjectListField()) { |
| 329 |
1/1✓ Branch 2 taken 55838 times.
|
55838 | result.push_back(m_fields.size() + index); |
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | 404413 | return result; | |
| 334 | ✗ | } | |
| 335 | |||
| 336 | 1 | std::vector<unsigned> IddObject_Impl::urlFields() const { | |
| 337 | 1 | UnsignedVector result; | |
| 338 | |||
| 339 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 time.
|
11 | for (unsigned index = 0; index < m_fields.size(); ++index) { |
| 340 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 5 taken 10 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 9 times.
|
10 | if (m_fields[index].properties().type == IddFieldType::URLType) { |
| 341 |
1/1✓ Branch 1 taken 1 time.
|
1 | result.push_back(index); |
| 342 | } | ||
| 343 | } | ||
| 344 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | for (unsigned index = 0; index < m_extensibleFields.size(); ++index) { |
| 345 | ✗ | if (m_extensibleFields[index].properties().type == IddFieldType::URLType) { | |
| 346 | ✗ | result.push_back(m_fields.size() + index); | |
| 347 | } | ||
| 348 | } | ||
| 349 | |||
| 350 | 1 | return result; | |
| 351 | ✗ | } | |
| 352 | |||
| 353 | 3326671 | bool IddObject_Impl::operator==(const IddObject_Impl& other) const { | |
| 354 |
2/2✓ Branch 0 taken 83541 times.
✓ Branch 1 taken 3243130 times.
|
3326671 | if (this == &other) { |
| 355 | 83541 | return true; | |
| 356 | } | ||
| 357 | |||
| 358 |
2/2✓ Branch 1 taken 2893732 times.
✓ Branch 2 taken 349398 times.
|
3243130 | if (m_type != other.m_type) { |
| 359 | 2893732 | return false; | |
| 360 | } | ||
| 361 |
2/2✓ Branch 1 taken 349218 times.
✓ Branch 2 taken 180 times.
|
349398 | if (m_name != other.m_name) { |
| 362 | 349218 | return false; | |
| 363 | } | ||
| 364 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
|
180 | if (m_group != other.m_group) { |
| 365 | ✗ | return false; | |
| 366 | } | ||
| 367 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
|
180 | if (m_properties != other.m_properties) { |
| 368 | ✗ | return false; | |
| 369 | } | ||
| 370 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
|
180 | if (m_fields != other.m_fields) { |
| 371 | ✗ | return false; | |
| 372 | } | ||
| 373 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
|
180 | if (m_extensibleFields != other.m_extensibleFields) { |
| 374 | ✗ | return false; | |
| 375 | } | ||
| 376 | |||
| 377 | 180 | return true; | |
| 378 | } | ||
| 379 | |||
| 380 | // SERIALIZATION | ||
| 381 | |||
| 382 | 1098760 | std::shared_ptr<IddObject_Impl> IddObject_Impl::load(const std::string& name, const std::string& group, const std::string& text, | |
| 383 | IddObjectType type) { | ||
| 384 | 1098760 | std::shared_ptr<IddObject_Impl> result; | |
| 385 |
3/5✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 7 taken 1098760 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
1098760 | result = std::shared_ptr<IddObject_Impl>(new IddObject_Impl(name, group, type)); |
| 386 | |||
| 387 | try { | ||
| 388 |
1/1✓ Branch 2 taken 1098760 times.
|
1098760 | result->parse(text); |
| 389 | ✗ | } catch (...) { | |
| 390 | ✗ | return {}; | |
| 391 | ✗ | } | |
| 392 | |||
| 393 | 1098760 | return result; | |
| 394 | 1098760 | } | |
| 395 | |||
| 396 | |||
| 397 | 57587 | std::ostream& IddObject_Impl::print(std::ostream& os) const { | |
| 398 |
6/6✓ Branch 1 taken 109 times.
✓ Branch 2 taken 57478 times.
✓ Branch 4 taken 105 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 105 times.
✓ Branch 7 taken 57482 times.
|
57587 | if (m_fields.empty() && m_extensibleFields.empty()) { |
| 399 | |||
| 400 | 105 | os << m_name << ";" << '\n'; | |
| 401 | 105 | m_properties.print(os); | |
| 402 | 105 | os << '\n'; | |
| 403 | |||
| 404 | } else { | ||
| 405 | |||
| 406 | 57482 | os << m_name << "," << '\n'; | |
| 407 | 57482 | m_properties.print(os); | |
| 408 | |||
| 409 | 57482 | bool extensibleFields = !m_extensibleFields.empty(); | |
| 410 |
2/2✓ Branch 4 taken 719703 times.
✓ Branch 5 taken 57482 times.
|
777185 | for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) { |
| 411 |
2/2✓ Branch 0 taken 57836 times.
✓ Branch 1 taken 661867 times.
|
719703 | if (extensibleFields) { |
| 412 |
1/1✓ Branch 2 taken 57836 times.
|
57836 | it->print(os, false); // don't print ; just yet |
| 413 | } else { | ||
| 414 |
1/1✓ Branch 4 taken 661867 times.
|
661867 | it->print(os, (it == itend - 1)); |
| 415 | } | ||
| 416 | } | ||
| 417 |
2/2✓ Branch 3 taken 17758 times.
✓ Branch 4 taken 57482 times.
|
75240 | for (auto it = m_extensibleFields.begin(), itend = m_extensibleFields.end(); it != itend; ++it) { |
| 418 |
1/1✓ Branch 4 taken 17758 times.
|
17758 | it->print(os, (it == itend - 1)); |
| 419 | } | ||
| 420 | |||
| 421 | 57482 | os << '\n'; | |
| 422 | } | ||
| 423 | |||
| 424 | 57587 | return os; | |
| 425 | } | ||
| 426 | |||
| 427 | // PRIVATE | ||
| 428 | |||
| 429 |
2/2✓ Branch 2 taken 1098760 times.
✓ Branch 5 taken 1098760 times.
|
1098760 | IddObject_Impl::IddObject_Impl(const string& name, const string& group, IddObjectType type) : m_name(name), m_group(group), m_type(type) {} |
| 430 | |||
| 431 | 1098760 | void IddObject_Impl::parse(const std::string& text) { | |
| 432 |
1/1✓ Branch 1 taken 1098760 times.
|
1098760 | smatch matches; |
| 433 |
4/4✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 6 taken 1096263 times.
✓ Branch 7 taken 2497 times.
|
1098760 | if (boost::regex_search(text, matches, iddRegex::objectAndFields())) { |
| 434 | // find and parse the object text | ||
| 435 |
3/3✓ Branch 1 taken 1096263 times.
✓ Branch 4 taken 1096263 times.
✓ Branch 7 taken 1096263 times.
|
1096263 | string objectText(matches[1].first, matches[1].second); |
| 436 |
1/1✓ Branch 1 taken 1096263 times.
|
1096263 | parseObject(objectText); |
| 437 | |||
| 438 | // find and parse the fields text | ||
| 439 |
3/3✓ Branch 1 taken 1096263 times.
✓ Branch 4 taken 1096263 times.
✓ Branch 7 taken 1096263 times.
|
1096263 | string fieldsText(matches[2].first, matches[2].second); |
| 440 |
1/1✓ Branch 1 taken 1096263 times.
|
1096263 | parseFields(fieldsText); |
| 441 | |||
| 442 |
3/4✓ Branch 3 taken 2497 times.
✓ Branch 6 taken 2497 times.
✓ Branch 8 taken 2497 times.
✗ Branch 9 not taken.
|
1098760 | } else if (boost::regex_match(text, iddRegex::objectNoFields())) { |
| 443 | // there are no fields in this object, it is all object text | ||
| 444 |
1/1✓ Branch 1 taken 2497 times.
|
2497 | parseObject(text); |
| 445 | |||
| 446 | } else { | ||
| 447 | // error | ||
| 448 | ✗ | LOG_AND_THROW("Unexpected pattern '" << text << "' found in object '" << m_name << "'"); | |
| 449 | } | ||
| 450 | |||
| 451 | // remove existing extensible fields and add them the the extensible list | ||
| 452 |
2/2✓ Branch 0 taken 169443 times.
✓ Branch 1 taken 929317 times.
|
1098760 | if (m_properties.extensible) { |
| 453 |
1/1✓ Branch 1 taken 169443 times.
|
169443 | makeExtensible(); |
| 454 | } | ||
| 455 | 1098760 | } | |
| 456 | |||
| 457 | 169443 | void IddObject_Impl::makeExtensible() { | |
| 458 | // number of fields in extensible group | ||
| 459 | 169443 | unsigned numExtensible = m_properties.numExtensible; | |
| 460 | |||
| 461 | // check that numExtensible > 0 | ||
| 462 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 169443 times.
|
169443 | if (numExtensible == 0) { |
| 463 | ✗ | LOG(Error, "Extensible length 0 in object '" << m_name << "'"); | |
| 464 | ✗ | return; | |
| 465 | } | ||
| 466 | |||
| 467 | // find the begin extensible field, there should be only one | ||
| 468 | 169443 | auto extensibleBegin = m_fields.end(); | |
| 469 |
1/2✓ Branch 4 taken 1239949 times.
✗ Branch 5 not taken.
|
1239949 | for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) { |
| 470 |
3/3✓ Branch 2 taken 1239949 times.
✓ Branch 4 taken 169443 times.
✓ Branch 5 taken 1070506 times.
|
1239949 | if (it->properties().beginExtensible) { |
| 471 | 169443 | extensibleBegin = it; | |
| 472 | 169443 | break; | |
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | // no extensible begin found | ||
| 477 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 169443 times.
|
169443 | if (extensibleBegin == m_fields.end()) { |
| 478 | ✗ | LOG(Error, "No begin-extensible field detected in object '" << m_name << "'"); | |
| 479 | ✗ | return; | |
| 480 | } | ||
| 481 | |||
| 482 | // extensible begin is too close to the end of the field list | ||
| 483 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 169443 times.
|
169443 | if ((extensibleBegin + numExtensible) > m_fields.end()) { |
| 484 | ✗ | LOG(Error, "Extensible fields begin too close to end of fields in object '" << m_name << "'"); | |
| 485 | ✗ | return; | |
| 486 | } | ||
| 487 | |||
| 488 | // copy extensible fields | ||
| 489 |
1/1✓ Branch 2 taken 169443 times.
|
169443 | m_extensibleFields = IddFieldVector(extensibleBegin, extensibleBegin + numExtensible); |
| 490 | |||
| 491 | // remove all the extensible fields from the field list | ||
| 492 |
1/1✓ Branch 3 taken 169443 times.
|
169443 | m_fields.resize(extensibleBegin - m_fields.begin()); |
| 493 | |||
| 494 | // regexs that match extensible fields | ||
| 495 | 169443 | std::string replace; | |
| 496 | |||
| 497 | // replace names of extensible fields so they do not contain numbers | ||
| 498 | // e.g. "Vertex 1 X-coordinate" -> "Vertex X-coordinate" | ||
| 499 |
2/2✓ Branch 5 taken 346189 times.
✓ Branch 6 taken 169443 times.
|
515632 | for (IddField& extensibleField : m_extensibleFields) { |
| 500 |
1/1✓ Branch 1 taken 346189 times.
|
346189 | std::string extensibleFieldName = extensibleField.name(); |
| 501 |
3/3✓ Branch 1 taken 346189 times.
✓ Branch 4 taken 346189 times.
✓ Branch 7 taken 346189 times.
|
346189 | extensibleFieldName = regex_replace(extensibleFieldName, iddRegex::numberAndPrecedingSpace(), replace, boost::format_first_only); |
| 502 |
1/1✓ Branch 1 taken 346189 times.
|
346189 | openstudio::ascii_trim(extensibleFieldName); |
| 503 |
1/1✓ Branch 1 taken 346189 times.
|
346189 | extensibleField.setName(extensibleFieldName); |
| 504 | 346189 | } | |
| 505 | |||
| 506 | // figure out numExtensibleGroupsRequired | ||
| 507 |
2/2✓ Branch 0 taken 121618 times.
✓ Branch 1 taken 47825 times.
|
169443 | if (m_properties.minFields > 0) { |
| 508 | 121618 | unsigned minFields = m_properties.minFields; | |
| 509 |
2/2✓ Branch 1 taken 56475 times.
✓ Branch 2 taken 65143 times.
|
121618 | if (minFields > m_fields.size()) { |
| 510 | 56475 | double numerator(minFields - (unsigned)m_fields.size()); | |
| 511 | 56475 | double denominator(numExtensible); | |
| 512 | 56475 | m_properties.numExtensibleGroupsRequired = unsigned(std::ceil(numerator / denominator)); | |
| 513 | } | ||
| 514 | } | ||
| 515 | 169443 | } | |
| 516 | |||
| 517 | 1098760 | void IddObject_Impl::parseObject(const std::string& text) { | |
| 518 | // find the object name and the property text | ||
| 519 |
1/1✓ Branch 1 taken 1098760 times.
|
1098760 | smatch matches; |
| 520 | 1098760 | string propertiesText; | |
| 521 |
3/4✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 6 taken 1098760 times.
✗ Branch 7 not taken.
|
1098760 | if (boost::regex_search(text, matches, iddRegex::line())) { |
| 522 |
3/3✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 7 taken 1098760 times.
|
1098760 | std::string objectName = string(matches[1].first, matches[1].second); |
| 523 |
1/1✓ Branch 1 taken 1098760 times.
|
1098760 | openstudio::ascii_trim(objectName); |
| 524 |
2/3✓ Branch 1 taken 1098760 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1098760 times.
|
1098760 | if (!boost::equals(m_name, objectName)) { |
| 525 | ✗ | LOG_AND_THROW("Object name '" << objectName << "' does not match expected '" << m_name << "'"); | |
| 526 | } | ||
| 527 | |||
| 528 |
3/3✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 7 taken 1098760 times.
|
1098760 | propertiesText = string(matches[2].first, matches[2].second); |
| 529 |
1/1✓ Branch 1 taken 1098760 times.
|
1098760 | openstudio::ascii_trim(propertiesText); |
| 530 | 1098760 | } else { | |
| 531 | ✗ | LOG_AND_THROW("Could not determine object name from text '" << text << "'"); | |
| 532 | } | ||
| 533 | |||
| 534 |
4/4✓ Branch 1 taken 4117721 times.
✓ Branch 4 taken 4117721 times.
✓ Branch 6 taken 3018961 times.
✓ Branch 7 taken 1098760 times.
|
4117721 | while (boost::regex_search(propertiesText, matches, iddRegex::metaDataComment())) { |
| 535 |
3/3✓ Branch 1 taken 3018961 times.
✓ Branch 4 taken 3018961 times.
✓ Branch 7 taken 3018961 times.
|
3018961 | string thisProperty(matches[1].first, matches[1].second); |
| 536 |
1/1✓ Branch 1 taken 3018961 times.
|
3018961 | openstudio::ascii_trim(thisProperty); |
| 537 |
1/1✓ Branch 1 taken 3018961 times.
|
3018961 | parseProperty(thisProperty); |
| 538 | |||
| 539 |
3/3✓ Branch 1 taken 3018961 times.
✓ Branch 4 taken 3018961 times.
✓ Branch 7 taken 3018961 times.
|
3018961 | propertiesText = string(matches[2].first, matches[2].second); |
| 540 |
1/1✓ Branch 1 taken 3018961 times.
|
3018961 | openstudio::ascii_trim(propertiesText); |
| 541 | 3018961 | } | |
| 542 |
5/6✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
✓ Branch 6 taken 2103 times.
✓ Branch 7 taken 1096657 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1098760 times.
|
1100863 | if (!((boost::regex_match(propertiesText, commentRegex::whitespaceOnlyBlock())) |
| 543 |
3/4✓ Branch 1 taken 2103 times.
✓ Branch 4 taken 2103 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2103 times.
|
2103 | || (boost::regex_match(propertiesText, iddRegex::commentOnlyLine())))) { |
| 544 | ✗ | LOG_AND_THROW("Could not process properties text '" << propertiesText << "' in object '" << m_name << "'"); | |
| 545 | } | ||
| 546 | 1098760 | } | |
| 547 | |||
| 548 | 3018961 | void IddObject_Impl::parseProperty(const std::string& text) { | |
| 549 |
1/1✓ Branch 1 taken 3018961 times.
|
3018961 | smatch matches; |
| 550 |
4/4✓ Branch 1 taken 3018961 times.
✓ Branch 4 taken 3018961 times.
✓ Branch 6 taken 1809609 times.
✓ Branch 7 taken 1209352 times.
|
3018961 | if (boost::regex_search(text, matches, iddRegex::memoProperty())) { |
| 551 |
3/3✓ Branch 1 taken 1809609 times.
✓ Branch 4 taken 1809609 times.
✓ Branch 7 taken 1809609 times.
|
1809609 | string memo(matches[1].first, matches[1].second); |
| 552 |
1/1✓ Branch 1 taken 1809609 times.
|
1809609 | openstudio::ascii_trim(memo); |
| 553 |
2/2✓ Branch 1 taken 666804 times.
✓ Branch 2 taken 1142805 times.
|
1809609 | if (m_properties.memo.empty()) { |
| 554 |
1/1✓ Branch 1 taken 666804 times.
|
666804 | m_properties.memo = memo; |
| 555 | } else { | ||
| 556 |
2/2✓ Branch 1 taken 1142805 times.
✓ Branch 4 taken 1142805 times.
|
1142805 | m_properties.memo += "\n" + memo; |
| 557 | } | ||
| 558 | |||
| 559 |
4/4✓ Branch 2 taken 1209352 times.
✓ Branch 5 taken 1209352 times.
✓ Branch 7 taken 109915 times.
✓ Branch 8 taken 1099437 times.
|
3018961 | } else if (boost::regex_match(text, iddRegex::uniqueProperty())) { |
| 560 | 109915 | m_properties.unique = true; | |
| 561 | |||
| 562 |
4/4✓ Branch 1 taken 1099437 times.
✓ Branch 4 taken 1099437 times.
✓ Branch 6 taken 11964 times.
✓ Branch 7 taken 1087473 times.
|
1099437 | } else if (boost::regex_match(text, iddRegex::requiredObjectProperty())) { |
| 563 | 11964 | m_properties.required = true; | |
| 564 | |||
| 565 |
4/4✓ Branch 1 taken 1087473 times.
✓ Branch 4 taken 1087473 times.
✓ Branch 6 taken 2296 times.
✓ Branch 7 taken 1085177 times.
|
1087473 | } else if (boost::regex_match(text, iddRegex::obsoleteProperty())) { |
| 566 | 2296 | m_properties.obsolete = true; | |
| 567 | |||
| 568 |
4/4✓ Branch 1 taken 1085177 times.
✓ Branch 4 taken 1085177 times.
✓ Branch 6 taken 7531 times.
✓ Branch 7 taken 1077646 times.
|
1085177 | } else if (boost::regex_match(text, iddRegex::hasurlProperty())) { |
| 569 | 7531 | m_properties.hasURL = true; | |
| 570 | |||
| 571 |
4/4✓ Branch 1 taken 1077646 times.
✓ Branch 4 taken 1077646 times.
✓ Branch 6 taken 170763 times.
✓ Branch 7 taken 906883 times.
|
1077646 | } else if (boost::regex_search(text, matches, iddRegex::extensibleProperty())) { |
| 572 | 170763 | m_properties.extensible = true; | |
| 573 | |||
| 574 |
3/3✓ Branch 1 taken 170763 times.
✓ Branch 4 taken 170763 times.
✓ Branch 7 taken 170763 times.
|
170763 | string numExtensible(matches[1].first, matches[1].second); |
| 575 |
1/1✓ Branch 1 taken 170763 times.
|
170763 | m_properties.numExtensible = boost::lexical_cast<unsigned>(numExtensible); |
| 576 | |||
| 577 |
4/4✓ Branch 2 taken 906883 times.
✓ Branch 5 taken 906883 times.
✓ Branch 7 taken 63040 times.
✓ Branch 8 taken 843843 times.
|
1077646 | } else if (boost::regex_search(text, matches, iddRegex::formatProperty())) { |
| 578 |
3/3✓ Branch 1 taken 63040 times.
✓ Branch 4 taken 63040 times.
✓ Branch 7 taken 63040 times.
|
63040 | string format(matches[1].first, matches[1].second); |
| 579 |
1/1✓ Branch 1 taken 63040 times.
|
63040 | openstudio::ascii_trim(format); |
| 580 |
1/1✓ Branch 1 taken 63040 times.
|
63040 | m_properties.format = format; |
| 581 | |||
| 582 |
4/4✓ Branch 2 taken 843843 times.
✓ Branch 5 taken 843843 times.
✓ Branch 7 taken 813862 times.
✓ Branch 8 taken 29981 times.
|
906883 | } else if (boost::regex_search(text, matches, iddRegex::minFieldsProperty())) { |
| 583 |
3/3✓ Branch 1 taken 813862 times.
✓ Branch 4 taken 813862 times.
✓ Branch 7 taken 813862 times.
|
813862 | string minFields(matches[1].first, matches[1].second); |
| 584 |
1/1✓ Branch 1 taken 813862 times.
|
813862 | m_properties.minFields = boost::lexical_cast<unsigned>(minFields); |
| 585 | |||
| 586 |
3/4✓ Branch 2 taken 29981 times.
✓ Branch 5 taken 29981 times.
✓ Branch 7 taken 29981 times.
✗ Branch 8 not taken.
|
843843 | } else if (boost::regex_search(text, matches, iddRegex::maxFieldsProperty())) { |
| 587 |
3/3✓ Branch 1 taken 29981 times.
✓ Branch 4 taken 29981 times.
✓ Branch 7 taken 29981 times.
|
29981 | string maxFields(matches[1].first, matches[1].second); |
| 588 |
2/2✓ Branch 1 taken 29981 times.
✓ Branch 4 taken 29981 times.
|
29981 | m_properties.maxFields = boost::lexical_cast<unsigned>(maxFields); |
| 589 | 29981 | } else { | |
| 590 | // error, unknown property | ||
| 591 | ✗ | LOG_AND_THROW("Unknown property text '" << text << "' in object '" << m_name << "'"); | |
| 592 | } | ||
| 593 | 3018961 | } | |
| 594 | |||
| 595 | 1096263 | void IddObject_Impl::parseFields(const std::string& text) { | |
| 596 |
4/7✓ Branch 0 taken 4003 times.
✓ Branch 1 taken 1092260 times.
✓ Branch 3 taken 4003 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4003 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
1096263 | static const boost::regex field_start("[AN][0-9]+[\\s]*[,;]"); |
| 597 | |||
| 598 | 1096263 | auto begin = text.begin(); | |
| 599 | 1096263 | const auto end = text.end(); | |
| 600 | |||
| 601 |
1/1✓ Branch 1 taken 1096263 times.
|
1096263 | boost::match_results<std::string::const_iterator> matches; |
| 602 |
2/3✓ Branch 1 taken 1096263 times.
✓ Branch 3 taken 1096263 times.
✗ Branch 4 not taken.
|
1096263 | if (boost::regex_search(begin, end, matches, field_start)) { |
| 603 |
1/1✓ Branch 1 taken 1096263 times.
|
1096263 | begin = matches[0].first; |
| 604 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1096263 times.
|
1096263 | if (begin != text.begin()) { |
| 605 | ✗ | LOG_AND_THROW("Could not process field text '" << text << "' in object ', start is not where expected" << m_name << "'"); | |
| 606 | } | ||
| 607 | } else { | ||
| 608 | ✗ | return; | |
| 609 | } | ||
| 610 | |||
| 611 | 1096263 | std::string::const_iterator field_end; | |
| 612 | |||
| 613 |
2/2✓ Branch 1 taken 13535700 times.
✓ Branch 2 taken 1096263 times.
|
14631963 | while (begin != end) { |
| 614 |
3/3✓ Branch 2 taken 13535700 times.
✓ Branch 4 taken 12439437 times.
✓ Branch 5 taken 1096263 times.
|
13535700 | if (boost::regex_search(begin + 1, end, matches, field_start)) { |
| 615 |
1/1✓ Branch 1 taken 12439437 times.
|
12439437 | field_end = matches[0].first; |
| 616 | } else { | ||
| 617 | 1096263 | field_end = end; | |
| 618 | } | ||
| 619 | |||
| 620 | // take the text of the last field | ||
| 621 |
1/1✓ Branch 1 taken 13535700 times.
|
13535700 | string fieldText(begin, field_end); |
| 622 | 13535700 | begin = field_end; | |
| 623 | |||
| 624 | 13535700 | string fieldName; | |
| 625 | |||
| 626 | // peak ahead to find the field name for indexing in map | ||
| 627 |
1/1✓ Branch 1 taken 13535700 times.
|
13535700 | smatch nameMatches; |
| 628 |
4/4✓ Branch 1 taken 13535700 times.
✓ Branch 4 taken 13535700 times.
✓ Branch 6 taken 13524050 times.
✓ Branch 7 taken 11650 times.
|
13535700 | if (boost::regex_search(fieldText, nameMatches, iddRegex::name())) { |
| 629 |
3/3✓ Branch 1 taken 13524050 times.
✓ Branch 4 taken 13524050 times.
✓ Branch 7 taken 13524050 times.
|
13524050 | fieldName = string(nameMatches[1].first, nameMatches[1].second); |
| 630 |
1/1✓ Branch 1 taken 13524050 times.
|
13524050 | openstudio::ascii_trim(fieldName); |
| 631 |
3/4✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 6 taken 11650 times.
✗ Branch 7 not taken.
|
11650 | } else if (boost::regex_search(fieldText, nameMatches, iddRegex::field())) { |
| 632 | // if no explicit field name, use the type and number | ||
| 633 |
3/3✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 7 taken 11650 times.
|
11650 | string fieldTypeChar(nameMatches[1].first, nameMatches[1].second); |
| 634 |
1/1✓ Branch 1 taken 11650 times.
|
11650 | openstudio::ascii_trim(fieldTypeChar); |
| 635 |
3/3✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 7 taken 11650 times.
|
11650 | string fieldTypeNumber(nameMatches[2].first, nameMatches[2].second); |
| 636 |
1/1✓ Branch 1 taken 11650 times.
|
11650 | openstudio::ascii_trim(fieldTypeNumber); |
| 637 |
1/1✓ Branch 1 taken 11650 times.
|
11650 | fieldName = fieldTypeChar + fieldTypeNumber; |
| 638 | 11650 | } else { | |
| 639 | // cannot find the field name | ||
| 640 | ✗ | LOG_AND_THROW("Cannot determine field name from text '" << fieldText << "'"); | |
| 641 | } | ||
| 642 | |||
| 643 | // construct the field | ||
| 644 |
1/1✓ Branch 1 taken 13535700 times.
|
13535700 | OptionalIddField oField = IddField::load(fieldName, fieldText, m_name); |
| 645 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13535700 times.
|
13535700 | if (!oField) { |
| 646 | ✗ | LOG_AND_THROW("Cannot parse IddField text '" << fieldText << "'."); | |
| 647 | } | ||
| 648 | |||
| 649 | // construct a new object and put it in the object list and object map | ||
| 650 |
2/2✓ Branch 1 taken 13535700 times.
✓ Branch 4 taken 13535700 times.
|
13535700 | m_fields.push_back(*oField); |
| 651 | 13535700 | } | |
| 652 | 1096263 | } | |
| 653 | |||
| 654 | } // namespace detail | ||
| 655 | |||
| 656 | // CONSTRUCTORS | ||
| 657 | |||
| 658 |
2/4✓ Branch 2 taken 224583 times.
✓ Branch 5 taken 224583 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
224583 | IddObject::IddObject() : m_impl(std::shared_ptr<detail::IddObject_Impl>(new detail::IddObject_Impl())) {} |
| 659 | |||
| 660 | 135387752 | IddObject::IddObject(const IddObject& other) = default; | |
| 661 | |||
| 662 | // GETTERS | ||
| 663 | |||
| 664 | 134657039 | std::string IddObject::name() const { | |
| 665 | 134657039 | return m_impl->name(); | |
| 666 | } | ||
| 667 | |||
| 668 | 49284081 | IddObjectType IddObject::type() const { | |
| 669 | 49284081 | return m_impl->type(); | |
| 670 | } | ||
| 671 | |||
| 672 | 61131 | std::string IddObject::group() const { | |
| 673 | 61131 | return m_impl->group(); | |
| 674 | } | ||
| 675 | |||
| 676 | 39461395 | const IddObjectProperties& IddObject::properties() const { | |
| 677 | 39461395 | return m_impl->properties(); | |
| 678 | } | ||
| 679 | |||
| 680 | 201322 | const IddFieldVector& IddObject::nonextensibleFields() const { | |
| 681 | 201322 | return m_impl->nonextensibleFields(); | |
| 682 | } | ||
| 683 | |||
| 684 | 135414 | const IddFieldVector& IddObject::extensibleGroup() const { | |
| 685 | 135414 | return m_impl->extensibleGroup(); | |
| 686 | } | ||
| 687 | |||
| 688 | 99049132 | boost::optional<IddField> IddObject::getField(unsigned index) const { | |
| 689 | 99049132 | return m_impl->getField(index); | |
| 690 | } | ||
| 691 | |||
| 692 | 14 | boost::optional<IddField> IddObject::getField(const std::string& fieldName) const { | |
| 693 | 14 | return m_impl->getField(fieldName); | |
| 694 | } | ||
| 695 | |||
| 696 | 9504 | boost::optional<int> IddObject::getFieldIndex(const std::string& fieldName) const { | |
| 697 | 9504 | return m_impl->getFieldIndex(fieldName); | |
| 698 | } | ||
| 699 | |||
| 700 | // SETTERS | ||
| 701 | |||
| 702 | 1 | void IddObject::insertHandleField() { | |
| 703 | 1 | return m_impl->insertHandleField(); | |
| 704 | } | ||
| 705 | |||
| 706 | // QUERIES | ||
| 707 | |||
| 708 | 7635278 | unsigned IddObject::numFields() const { | |
| 709 | 7635278 | return m_impl->numFields(); | |
| 710 | } | ||
| 711 | |||
| 712 | 1675925 | unsigned IddObject::numFieldsInDefaultObject() const { | |
| 713 | 1675925 | return m_impl->numFieldsInDefaultObject(); | |
| 714 | } | ||
| 715 | |||
| 716 | 1271653 | bool IddObject::isVersionObject() const { | |
| 717 | 1271653 | return m_impl->isVersionObject(); | |
| 718 | } | ||
| 719 | |||
| 720 | 5181585 | bool IddObject::isNonextensibleField(unsigned index) const { | |
| 721 | 5181585 | return m_impl->isNonextensibleField(index); | |
| 722 | } | ||
| 723 | |||
| 724 | 19824339 | bool IddObject::isExtensibleField(unsigned index) const { | |
| 725 | 19824339 | return m_impl->isExtensibleField(index); | |
| 726 | } | ||
| 727 | |||
| 728 | 3051911 | bool IddObject::hasHandleField() const { | |
| 729 | 3051911 | return m_impl->hasHandleField(); | |
| 730 | } | ||
| 731 | |||
| 732 | 7581170 | bool IddObject::hasNameField() const { | |
| 733 | 7581170 | return m_impl->hasNameField(); | |
| 734 | } | ||
| 735 | |||
| 736 | 41742098 | boost::optional<unsigned> IddObject::nameFieldIndex() const { | |
| 737 | 41742098 | return m_impl->nameFieldIndex(); | |
| 738 | } | ||
| 739 | |||
| 740 | 199643 | bool IddObject::isRequiredField(unsigned index) const { | |
| 741 | 199643 | return m_impl->isRequiredField(index); | |
| 742 | } | ||
| 743 | |||
| 744 | 384 | bool IddObject::hasURL() const { | |
| 745 | 384 | return m_impl->hasURL(); | |
| 746 | } | ||
| 747 | |||
| 748 | 12493060 | ExtensibleIndex IddObject::extensibleIndex(unsigned index) const { | |
| 749 | 12493060 | return m_impl->extensibleIndex(index); | |
| 750 | } | ||
| 751 | |||
| 752 | 12239868 | unsigned IddObject::index(ExtensibleIndex extensibleIndex) const { | |
| 753 | 12239868 | return m_impl->index(extensibleIndex); | |
| 754 | } | ||
| 755 | |||
| 756 | 781895 | std::vector<std::string> IddObject::references() const { | |
| 757 | 781895 | return m_impl->references(); | |
| 758 | } | ||
| 759 | |||
| 760 | 390237 | std::set<std::string> IddObject::objectLists() const { | |
| 761 | 390237 | return m_impl->objectLists(); | |
| 762 | } | ||
| 763 | |||
| 764 | 1550621 | std::set<std::string> IddObject::objectLists(unsigned index) const { | |
| 765 | 1550621 | return m_impl->objectLists(index); | |
| 766 | } | ||
| 767 | |||
| 768 | 404413 | std::vector<unsigned> IddObject::objectListFields() const { | |
| 769 | 404413 | return m_impl->objectListFields(); | |
| 770 | } | ||
| 771 | |||
| 772 | 1 | std::vector<unsigned> IddObject::urlFields() const { | |
| 773 | 1 | return m_impl->urlFields(); | |
| 774 | } | ||
| 775 | |||
| 776 | 3326671 | bool IddObject::operator==(const IddObject& other) const { | |
| 777 | 3326671 | return (*m_impl == *(other.m_impl)); | |
| 778 | } | ||
| 779 | |||
| 780 | 2965223 | bool IddObject::operator!=(const IddObject& other) const { | |
| 781 | 2965223 | return !(*this == other); | |
| 782 | } | ||
| 783 | |||
| 784 | // SERIALIZATION | ||
| 785 | |||
| 786 | 1098760 | boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text, IddObjectType type) { | |
| 787 |
1/1✓ Branch 1 taken 1098760 times.
|
1098760 | std::shared_ptr<detail::IddObject_Impl> p = detail::IddObject_Impl::load(name, group, text, type); |
| 788 |
1/2✓ Branch 1 taken 1098760 times.
✗ Branch 2 not taken.
|
1098760 | if (p) { |
| 789 |
2/2✓ Branch 1 taken 1098760 times.
✓ Branch 4 taken 1098760 times.
|
1098760 | return IddObject(p); |
| 790 | } else { | ||
| 791 | ✗ | return boost::none; | |
| 792 | } | ||
| 793 | 1098760 | } | |
| 794 | |||
| 795 | 881104 | boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text) { | |
| 796 |
2/2✓ Branch 1 taken 881104 times.
✓ Branch 4 taken 881104 times.
|
881104 | return load(name, group, text, IddObjectType(IddObjectType::UserCustom)); |
| 797 | } | ||
| 798 | |||
| 799 | 57587 | std::ostream& IddObject::print(std::ostream& os) const { | |
| 800 | 57587 | return m_impl->print(os); | |
| 801 | } | ||
| 802 | |||
| 803 | // PRIVATE | ||
| 804 | |||
| 805 | 1098760 | IddObject::IddObject(const std::shared_ptr<detail::IddObject_Impl>& impl) : m_impl(impl) {} | |
| 806 | |||
| 807 | // NON-MEMBER FUNCTIONS | ||
| 808 | |||
| 809 | ✗ | std::ostream& operator<<(std::ostream& os, const IddObject& iddObject) { | |
| 810 | ✗ | return iddObject.print(os); | |
| 811 | } | ||
| 812 | |||
| 813 | 2 | IddObjectTypeVector getIddObjectTypeVector(const IddObjectVector& objects) { | |
| 814 | 2 | IddObjectTypeVector result; | |
| 815 |
2/2✓ Branch 4 taken 4356 times.
✓ Branch 5 taken 2 times.
|
4358 | for (const IddObject& object : objects) { |
| 816 |
2/2✓ Branch 1 taken 4356 times.
✓ Branch 4 taken 4356 times.
|
4356 | result.push_back(object.type()); |
| 817 | } | ||
| 818 | 2 | return result; | |
| 819 | ✗ | } | |
| 820 | |||
| 821 | 1 | IddObjectTypeSet getIddObjectTypeSet(const IddObjectVector& objects) { | |
| 822 | 1 | IddObjectTypeSet result; | |
| 823 |
2/2✓ Branch 4 taken 2904 times.
✓ Branch 5 taken 1 time.
|
2905 | for (const IddObject& object : objects) { |
| 824 |
2/2✓ Branch 1 taken 2904 times.
✓ Branch 4 taken 2904 times.
|
2904 | result.insert(object.type()); |
| 825 | } | ||
| 826 | 1 | return result; | |
| 827 | ✗ | } | |
| 828 | |||
| 829 | 6112 | std::vector<std::string> getIddKeyNames(const IddObject& object, unsigned index) { | |
| 830 | 6112 | StringVector result; | |
| 831 |
1/1✓ Branch 1 taken 6112 times.
|
6112 | OptionalIddField oIddField = object.getField(index); |
| 832 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6112 times.
|
6112 | if (!oIddField) { |
| 833 | ✗ | return result; | |
| 834 | } | ||
| 835 |
1/1✓ Branch 1 taken 6112 times.
|
6112 | IddField iddField = *oIddField; |
| 836 |
1/1✓ Branch 1 taken 6112 times.
|
6112 | IddKeyVector keys = iddField.keys(); |
| 837 |
2/2✓ Branch 4 taken 79793 times.
✓ Branch 5 taken 6112 times.
|
85905 | for (const IddKey& key : keys) { |
| 838 |
2/2✓ Branch 1 taken 79793 times.
✓ Branch 4 taken 79793 times.
|
79793 | result.push_back(key.name()); |
| 839 | } | ||
| 840 | 6112 | return result; | |
| 841 | 6112 | } | |
| 842 | |||
| 843 | } // namespace openstudio | ||
| 844 |