src/utilities/idd/IddFieldProperties.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 "IddFieldProperties.hpp" | ||
| 7 | |||
| 8 | #include "../core/Containers.hpp" | ||
| 9 | |||
| 10 | #include <sstream> | ||
| 11 | |||
| 12 | namespace openstudio { | ||
| 13 | |||
| 14 | /// default constructor | ||
| 15 | 13984868 | IddFieldProperties::IddFieldProperties() | |
| 16 | 13984868 | : type(IddFieldType::UnknownType), | |
| 17 | 13984868 | required(false), | |
| 18 | 13984868 | autosizable(false), | |
| 19 | 13984868 | autocalculatable(false), | |
| 20 | 13984868 | retaincase(false), | |
| 21 | 13984868 | deprecated(false), | |
| 22 | 13984868 | beginExtensible(false), | |
| 23 | 13984868 | minBoundType(Unbounded), | |
| 24 | 13984868 | maxBoundType(Unbounded) {} | |
| 25 | |||
| 26 | ✗ | bool IddFieldProperties::isGeneric() const { | |
| 27 | ✗ | IddFieldProperties genericProperties; | |
| 28 | ✗ | genericProperties.type = type; | |
| 29 | ✗ | return (*this == genericProperties); | |
| 30 | ✗ | } | |
| 31 | |||
| 32 | 391 | bool IddFieldProperties::operator==(const IddFieldProperties& other) const { | |
| 33 | /** Only compare one or other of string versus numeric. */ | ||
| 34 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 390 times.
|
391 | if (this == &other) { |
| 35 | 1 | return true; | |
| 36 | } | ||
| 37 | |||
| 38 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 389 times.
|
390 | if (type != other.type) { |
| 39 | 1 | return false; | |
| 40 | } | ||
| 41 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 388 times.
|
389 | if (note != other.note) { |
| 42 | 1 | return false; | |
| 43 | } | ||
| 44 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (required != other.required) { |
| 45 | ✗ | return false; | |
| 46 | } | ||
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (autosizable != other.autosizable) { |
| 48 | ✗ | return false; | |
| 49 | } | ||
| 50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (autocalculatable != other.autocalculatable) { |
| 51 | ✗ | return false; | |
| 52 | } | ||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (retaincase != other.retaincase) { |
| 54 | ✗ | return false; | |
| 55 | } | ||
| 56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (deprecated != other.deprecated) { |
| 57 | ✗ | return false; | |
| 58 | } | ||
| 59 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (units != other.units) { |
| 60 | ✗ | return false; | |
| 61 | } | ||
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (ipUnits != other.ipUnits) { |
| 63 | ✗ | return false; | |
| 64 | } | ||
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (minBoundType != other.minBoundType) { |
| 66 | ✗ | return false; | |
| 67 | } | ||
| 68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (minBoundValue != other.minBoundValue) { |
| 69 | ✗ | return false; | |
| 70 | } | ||
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (maxBoundType != other.maxBoundType) { |
| 72 | ✗ | return false; | |
| 73 | } | ||
| 74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (maxBoundValue != other.maxBoundValue) { |
| 75 | // std::string myBound, theirBound; | ||
| 76 | // if (maxBoundText) { | ||
| 77 | // myBound = *maxBoundText; | ||
| 78 | // } | ||
| 79 | // if (other.maxBoundText) { | ||
| 80 | // theirBound = *(other.maxBoundText); | ||
| 81 | // } | ||
| 82 | ✗ | return false; | |
| 83 | } | ||
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (stringDefault != other.stringDefault) { |
| 85 | ✗ | return false; | |
| 86 | } | ||
| 87 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (objectLists != other.objectLists) { |
| 88 | ✗ | return false; | |
| 89 | } | ||
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (externalLists != other.externalLists) { |
| 91 | ✗ | return false; | |
| 92 | } | ||
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (references != other.references) { |
| 94 | ✗ | return false; | |
| 95 | } | ||
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if (referenceClassNames != other.referenceClassNames) { |
| 97 | ✗ | return false; | |
| 98 | } | ||
| 99 | |||
| 100 | 388 | return true; | |
| 101 | } | ||
| 102 | |||
| 103 | 389 | bool IddFieldProperties::operator!=(const IddFieldProperties& other) const { | |
| 104 | 389 | return !((*this) == other); | |
| 105 | } | ||
| 106 | |||
| 107 | 737462 | std::ostream& IddFieldProperties::print(std::ostream& os) const { | |
| 108 |
2/2✓ Branch 1 taken 304705 times.
✓ Branch 2 taken 432757 times.
|
737462 | if (!note.empty()) { |
| 109 |
1/1✓ Branch 2 taken 304705 times.
|
304705 | std::stringstream ss(note); |
| 110 | 304705 | std::string line; | |
| 111 |
3/3✓ Branch 1 taken 1039402 times.
✓ Branch 3 taken 734697 times.
✓ Branch 4 taken 304705 times.
|
1039402 | while (!ss.eof()) { |
| 112 |
1/1✓ Branch 1 taken 734697 times.
|
734697 | std::getline(ss, line); |
| 113 |
3/3✓ Branch 1 taken 734697 times.
✓ Branch 4 taken 734697 times.
✓ Branch 7 taken 734697 times.
|
734697 | os << " \\note " << line << '\n'; |
| 114 | } | ||
| 115 | 304705 | } | |
| 116 | |||
| 117 |
3/3✓ Branch 1 taken 737462 times.
✓ Branch 4 taken 18103 times.
✓ Branch 5 taken 719359 times.
|
737462 | if (type == IddFieldType::IntegerType) { |
| 118 | 18103 | os << " \\type integer" << '\n'; | |
| 119 |
3/3✓ Branch 1 taken 719359 times.
✓ Branch 4 taken 321423 times.
✓ Branch 5 taken 397936 times.
|
719359 | } else if (type == IddFieldType::RealType) { |
| 120 | 321423 | os << " \\type real" << '\n'; | |
| 121 |
3/3✓ Branch 1 taken 397936 times.
✓ Branch 4 taken 70331 times.
✓ Branch 5 taken 327605 times.
|
397936 | } else if (type == IddFieldType::AlphaType) { |
| 122 | 70331 | os << " \\type alpha" << '\n'; | |
| 123 |
3/3✓ Branch 1 taken 327605 times.
✓ Branch 4 taken 81808 times.
✓ Branch 5 taken 245797 times.
|
327605 | } else if (type == IddFieldType::ChoiceType) { |
| 124 | 81808 | os << " \\type choice" << '\n'; | |
| 125 |
3/3✓ Branch 1 taken 245797 times.
✓ Branch 4 taken 801 times.
✓ Branch 5 taken 244996 times.
|
245797 | } else if (type == IddFieldType::NodeType) { |
| 126 | 801 | os << " \\type node" << '\n'; | |
| 127 |
3/3✓ Branch 1 taken 244996 times.
✓ Branch 4 taken 187979 times.
✓ Branch 5 taken 57017 times.
|
244996 | } else if (type == IddFieldType::ObjectListType) { |
| 128 | 187979 | os << " \\type object-list" << '\n'; | |
| 129 |
3/3✓ Branch 1 taken 57017 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 57001 times.
|
57017 | } else if (type == IddFieldType::ExternalListType) { |
| 130 | 16 | os << " \\type external-list" << '\n'; | |
| 131 |
3/3✓ Branch 1 taken 57001 times.
✓ Branch 4 taken 401 times.
✓ Branch 5 taken 56600 times.
|
57001 | } else if (type == IddFieldType::URLType) { |
| 132 | 401 | os << " \\type url" << '\n'; | |
| 133 |
2/3✓ Branch 1 taken 56600 times.
✓ Branch 4 taken 56600 times.
✗ Branch 5 not taken.
|
56600 | } else if (type == IddFieldType::HandleType) { |
| 134 | 56600 | os << " \\type handle" << '\n'; | |
| 135 | } | ||
| 136 | |||
| 137 |
2/2✓ Branch 0 taken 410088 times.
✓ Branch 1 taken 327374 times.
|
737462 | if (required) { |
| 138 | 410088 | os << " \\required-field" << '\n'; | |
| 139 | } | ||
| 140 |
2/2✓ Branch 0 taken 40921 times.
✓ Branch 1 taken 696541 times.
|
737462 | if (autosizable) { |
| 141 | 40921 | os << " \\autosizable" << '\n'; | |
| 142 | } | ||
| 143 |
2/2✓ Branch 0 taken 3611 times.
✓ Branch 1 taken 733851 times.
|
737462 | if (autocalculatable) { |
| 144 | 3611 | os << " \\autocalculatable" << '\n'; | |
| 145 | } | ||
| 146 | |||
| 147 |
2/2✓ Branch 0 taken 7504 times.
✓ Branch 1 taken 729958 times.
|
737462 | if (retaincase) { |
| 148 | 7504 | os << " \\retaincase" << '\n'; | |
| 149 | } | ||
| 150 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 737362 times.
|
737462 | if (deprecated) { |
| 151 | 100 | os << " \\deprecated" << '\n'; | |
| 152 | } | ||
| 153 |
2/2✓ Branch 0 taken 8772 times.
✓ Branch 1 taken 728690 times.
|
737462 | if (beginExtensible) { |
| 154 | 8772 | os << " \\begin-extensible" << '\n'; | |
| 155 | } | ||
| 156 |
2/2✓ Branch 1 taken 226419 times.
✓ Branch 2 taken 511043 times.
|
1474924 | if (units) { |
| 157 | 226419 | os << " \\units " << *units << '\n'; | |
| 158 | } | ||
| 159 |
2/2✓ Branch 1 taken 39483 times.
✓ Branch 2 taken 697979 times.
|
1474924 | if (ipUnits) { |
| 160 | 39483 | os << " \\ip-units " << *ipUnits << '\n'; | |
| 161 | } | ||
| 162 |
5/6✓ Branch 0 taken 131976 times.
✓ Branch 1 taken 605486 times.
✓ Branch 3 taken 131976 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 131976 times.
✓ Branch 6 taken 605486 times.
|
869438 | if (minBoundType == IddFieldProperties::InclusiveBound && minBoundValue) { |
| 163 | 131976 | os << " \\minimum " << *minBoundValue << '\n'; | |
| 164 | } | ||
| 165 |
5/6✓ Branch 0 taken 82114 times.
✓ Branch 1 taken 655348 times.
✓ Branch 3 taken 82114 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 82114 times.
✓ Branch 6 taken 655348 times.
|
819576 | if (minBoundType == IddFieldProperties::ExclusiveBound && minBoundValue) { |
| 166 | 82114 | os << " \\minimum> " << *minBoundValue << '\n'; | |
| 167 | } | ||
| 168 |
5/6✓ Branch 0 taken 65575 times.
✓ Branch 1 taken 671887 times.
✓ Branch 3 taken 65575 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 65575 times.
✓ Branch 6 taken 671887 times.
|
803037 | if (maxBoundType == IddFieldProperties::InclusiveBound && maxBoundValue) { |
| 169 | 65575 | os << " \\maximum " << *maxBoundValue << '\n'; | |
| 170 | } | ||
| 171 |
5/6✓ Branch 0 taken 8360 times.
✓ Branch 1 taken 729102 times.
✓ Branch 3 taken 8360 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8360 times.
✓ Branch 6 taken 729102 times.
|
745822 | if (maxBoundType == IddFieldProperties::ExclusiveBound && maxBoundValue) { |
| 172 | 8360 | os << " \\maximum< " << *maxBoundValue << '\n'; | |
| 173 | } | ||
| 174 |
2/2✓ Branch 1 taken 134808 times.
✓ Branch 2 taken 602654 times.
|
1474924 | if (stringDefault) { |
| 175 | 134808 | os << " \\default " << *stringDefault << '\n'; | |
| 176 | } | ||
| 177 |
2/2✓ Branch 1 taken 188086 times.
✓ Branch 2 taken 549376 times.
|
737462 | if (!objectLists.empty()) { |
| 178 |
2/2✓ Branch 5 taken 197491 times.
✓ Branch 6 taken 188086 times.
|
385577 | for (const std::string& objectList : objectLists) { |
| 179 |
3/3✓ Branch 1 taken 197491 times.
✓ Branch 4 taken 197491 times.
✓ Branch 7 taken 197491 times.
|
197491 | os << " \\object-list " << objectList << '\n'; |
| 180 | } | ||
| 181 | } | ||
| 182 |
2/2✓ Branch 1 taken 46455 times.
✓ Branch 2 taken 691007 times.
|
737462 | if (!references.empty()) { |
| 183 |
2/2✓ Branch 5 taken 77466 times.
✓ Branch 6 taken 46455 times.
|
123921 | for (const std::string& reference : references) { |
| 184 |
3/3✓ Branch 1 taken 77466 times.
✓ Branch 4 taken 77466 times.
✓ Branch 7 taken 77466 times.
|
77466 | os << " \\reference " << reference << '\n'; |
| 185 | } | ||
| 186 | } | ||
| 187 |
2/2✓ Branch 1 taken 139 times.
✓ Branch 2 taken 737323 times.
|
737462 | if (!referenceClassNames.empty()) { |
| 188 |
2/2✓ Branch 5 taken 255 times.
✓ Branch 6 taken 139 times.
|
394 | for (const std::string& reference : referenceClassNames) { |
| 189 |
3/3✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 7 taken 255 times.
|
255 | os << " \\reference-class-name " << reference << '\n'; |
| 190 | } | ||
| 191 | } | ||
| 192 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 737446 times.
|
737462 | if (!externalLists.empty()) { |
| 193 |
2/2✓ Branch 5 taken 16 times.
✓ Branch 6 taken 16 times.
|
32 | for (const std::string& externalList : externalLists) { |
| 194 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | os << " \\external-list " << externalList << '\n'; |
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | 737462 | return os; | |
| 199 | } | ||
| 200 | |||
| 201 | 625 | StringVector intersectReferenceLists(const StringVector& list1, const StringVector& list2) { | |
| 202 |
1/1✓ Branch 3 taken 625 times.
|
625 | IStringSet set1(list1.begin(), list1.end()); |
| 203 |
1/1✓ Branch 3 taken 625 times.
|
625 | IStringSet set2(list2.begin(), list2.end()); |
| 204 | 625 | IStringSet intersection; | |
| 205 |
2/2✓ Branch 2 taken 625 times.
✓ Branch 9 taken 625 times.
|
625 | std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin()), |
| 206 | IStringSet::key_compare()); | ||
| 207 |
1/1✓ Branch 3 taken 625 times.
|
1875 | return {intersection.begin(), intersection.end()}; |
| 208 | 625 | } | |
| 209 | |||
| 210 | } // namespace openstudio | ||
| 211 |