src/model/AdditionalProperties.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 <string> | ||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | #include "AdditionalProperties.hpp" | ||
| 10 | #include "AdditionalProperties_Impl.hpp" | ||
| 11 | |||
| 12 | #include "Model.hpp" | ||
| 13 | #include "Model_Impl.hpp" | ||
| 14 | #include "ModelObject.hpp" | ||
| 15 | #include "ModelObject_Impl.hpp" | ||
| 16 | #include "ModelExtensibleGroup.hpp" | ||
| 17 | #include "ResourceObject.hpp" | ||
| 18 | |||
| 19 | #include <utilities/idd/OS_AdditionalProperties_FieldEnums.hxx> | ||
| 20 | #include <utilities/idd/IddEnums.hxx> | ||
| 21 | #include <utilities/idd/IddFactory.hxx> | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | namespace model { | ||
| 25 | namespace detail { | ||
| 26 | |||
| 27 | 5925 | AdditionalProperties_Impl::AdditionalProperties_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 28 | 5925 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 29 |
4/6✓ Branch 1 taken 5925 times.
✓ Branch 4 taken 5925 times.
✓ Branch 7 taken 5925 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5925 times.
✗ Branch 13 not taken.
|
5925 | OS_ASSERT(idfObject.iddObject().type() == AdditionalProperties::iddObjectType()); |
| 30 | 5925 | } | |
| 31 | |||
| 32 | 858 | AdditionalProperties_Impl::AdditionalProperties_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 33 | 858 | : ModelObject_Impl(other, model, keepHandle) { | |
| 34 |
4/6✓ Branch 1 taken 858 times.
✓ Branch 4 taken 858 times.
✓ Branch 7 taken 858 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 858 times.
✗ Branch 13 not taken.
|
858 | OS_ASSERT(other.iddObject().type() == AdditionalProperties::iddObjectType()); |
| 35 | 858 | } | |
| 36 | |||
| 37 | 2907 | AdditionalProperties_Impl::AdditionalProperties_Impl(const AdditionalProperties_Impl& other, Model_Impl* model, bool keepHandle) | |
| 38 | 2907 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 39 | |||
| 40 | 4 | ModelObject AdditionalProperties_Impl::modelObject() const { | |
| 41 | boost::optional<ModelObject> result = | ||
| 42 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | getObject<AdditionalProperties>().getModelObjectTarget<ModelObject>(OS_AdditionalPropertiesFields::ObjectName); |
| 43 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
|
4 | if (!result) { |
| 44 | // DLM: should we remove ourself? probably worse to do that since user may call other methods and cause a crash | ||
| 45 | //this->remove(); | ||
| 46 |
13/13✓ 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 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.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
|
1 | LOG_AND_THROW("Cannot retrieve associated ModelObject"); |
| 47 | } | ||
| 48 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
|
3 | OS_ASSERT(result); |
| 49 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | return *result; |
| 50 | 4 | } | |
| 51 | |||
| 52 | ✗ | const std::vector<std::string>& AdditionalProperties_Impl::outputVariableNames() const { | |
| 53 | ✗ | static const std::vector<std::string> result; | |
| 54 | ✗ | return result; | |
| 55 | } | ||
| 56 | |||
| 57 | ✗ | IddObjectType AdditionalProperties_Impl::iddObjectType() const { | |
| 58 | ✗ | return AdditionalProperties::iddObjectType(); | |
| 59 | } | ||
| 60 | |||
| 61 | ✗ | boost::optional<ParentObject> AdditionalProperties_Impl::parent() const { | |
| 62 | // DLM: should this return the model object? no because model object is not a parent object. | ||
| 63 | ✗ | return {}; | |
| 64 | } | ||
| 65 | |||
| 66 | ✗ | bool AdditionalProperties_Impl::setParent(ParentObject& /*newParent*/) { | |
| 67 | // DLM: should we allow this? no because model object is not a parent object. | ||
| 68 | ✗ | return false; | |
| 69 | } | ||
| 70 | |||
| 71 | 3 | std::vector<ResourceObject> AdditionalProperties_Impl::resources() const { | |
| 72 | 3 | return {}; | |
| 73 | } | ||
| 74 | |||
| 75 | 896 | std::vector<std::string> AdditionalProperties_Impl::featureNames() const { | |
| 76 | 896 | std::set<std::string> nameSet; | |
| 77 |
4/4✓ Branch 1 taken 896 times.
✓ Branch 4 taken 896 times.
✓ Branch 12 taken 2387 times.
✓ Branch 13 taken 896 times.
|
3283 | for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) { |
| 78 |
1/1✓ Branch 1 taken 2387 times.
|
2387 | boost::optional<std::string> name = group.getString(OS_AdditionalPropertiesExtensibleFields::FeatureName); |
| 79 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2387 times.
✗ Branch 4 not taken.
|
2387 | OS_ASSERT(name); |
| 80 |
2/2✓ Branch 1 taken 2387 times.
✓ Branch 4 taken 2387 times.
|
2387 | nameSet.insert(*name); |
| 81 | 3283 | } | |
| 82 | 896 | std::vector<std::string> names; | |
| 83 |
1/1✓ Branch 3 taken 896 times.
|
896 | names.assign(nameSet.begin(), nameSet.end()); |
| 84 | 1792 | return names; | |
| 85 | 896 | } | |
| 86 | |||
| 87 | 40127 | boost::optional<ModelExtensibleGroup> AdditionalProperties_Impl::getFeatureGroupByName(const std::string& name) const { | |
| 88 | |||
| 89 |
4/4✓ Branch 1 taken 40127 times.
✓ Branch 4 taken 40127 times.
✓ Branch 12 taken 66120 times.
✓ Branch 13 taken 18121 times.
|
84241 | for (ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) { |
| 90 |
1/1✓ Branch 1 taken 66120 times.
|
66120 | const boost::optional<std::string> featureName(group.getString(OS_AdditionalPropertiesExtensibleFields::FeatureName)); |
| 91 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 66120 times.
✗ Branch 4 not taken.
|
66120 | OS_ASSERT(featureName); |
| 92 |
3/3✓ Branch 1 taken 66120 times.
✓ Branch 4 taken 22006 times.
✓ Branch 5 taken 44114 times.
|
66120 | if (*featureName == name) { |
| 93 |
1/1✓ Branch 1 taken 22006 times.
|
22006 | return group; |
| 94 | } | ||
| 95 | 106247 | } | |
| 96 | 18121 | return boost::none; | |
| 97 | } | ||
| 98 | |||
| 99 | 11343 | bool AdditionalProperties_Impl::hasFeature(const std::string& name) const { | |
| 100 |
1/1✓ Branch 1 taken 11343 times.
|
11343 | return getFeatureGroupByName(name).has_value(); |
| 101 | } | ||
| 102 | |||
| 103 | 2384 | boost::optional<std::string> AdditionalProperties_Impl::getFeatureDataType(const std::string& name) const { | |
| 104 | 2384 | boost::optional<std::string> dataType; | |
| 105 |
1/1✓ Branch 1 taken 2384 times.
|
2384 | boost::optional<ModelExtensibleGroup> group(getFeatureGroupByName(name)); |
| 106 |
2/2✓ Branch 0 taken 2381 times.
✓ Branch 1 taken 3 times.
|
2384 | if (group) { |
| 107 |
2/2✓ Branch 1 taken 2381 times.
✓ Branch 4 taken 2381 times.
|
2381 | dataType = group->getString(OS_AdditionalPropertiesExtensibleFields::FeatureDataType); |
| 108 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2381 times.
✗ Branch 4 not taken.
|
2381 | OS_ASSERT(dataType); |
| 109 | } else { | ||
| 110 | 3 | dataType = boost::none; | |
| 111 | } | ||
| 112 | 4768 | return dataType; | |
| 113 | 2384 | } | |
| 114 | |||
| 115 | 9954 | boost::optional<std::string> AdditionalProperties_Impl::getFeatureStringAndCheckForType(const std::string& name, | |
| 116 | const std::string& expectedDataType) const { | ||
| 117 | 9954 | boost::optional<std::string> value; | |
| 118 |
1/1✓ Branch 1 taken 9954 times.
|
9954 | boost::optional<ModelExtensibleGroup> group(getFeatureGroupByName(name)); |
| 119 |
2/2✓ Branch 0 taken 9936 times.
✓ Branch 1 taken 18 times.
|
9954 | if (group) { |
| 120 |
2/2✓ Branch 1 taken 9936 times.
✓ Branch 4 taken 9936 times.
|
9936 | boost::optional<std::string> dataType(group->getString(OS_AdditionalPropertiesExtensibleFields::FeatureDataType)); |
| 121 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9936 times.
✗ Branch 4 not taken.
|
9936 | OS_ASSERT(dataType); |
| 122 |
3/3✓ Branch 1 taken 9936 times.
✓ Branch 4 taken 9932 times.
✓ Branch 5 taken 4 times.
|
9936 | if (*dataType == expectedDataType) { |
| 123 |
2/2✓ Branch 1 taken 9932 times.
✓ Branch 4 taken 9932 times.
|
9932 | value = group->getString(OS_AdditionalPropertiesExtensibleFields::FeatureValue); |
| 124 | } else { | ||
| 125 | 4 | value = boost::none; | |
| 126 | } | ||
| 127 | 9936 | } else { | |
| 128 | 18 | value = boost::none; | |
| 129 | } | ||
| 130 | 19908 | return value; | |
| 131 | 9954 | } | |
| 132 | |||
| 133 | 9931 | boost::optional<std::string> AdditionalProperties_Impl::getFeatureAsString(const std::string& name) const { | |
| 134 |
2/2✓ Branch 1 taken 9931 times.
✓ Branch 4 taken 9931 times.
|
19862 | return getFeatureStringAndCheckForType(name, "String"); |
| 135 | } | ||
| 136 | |||
| 137 | 12 | boost::optional<double> AdditionalProperties_Impl::getFeatureAsDouble(const std::string& name) const { | |
| 138 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | boost::optional<std::string> strValue(getFeatureStringAndCheckForType(name, "Double")); |
| 139 | 12 | boost::optional<double> value; | |
| 140 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (strValue) { |
| 141 | try { | ||
| 142 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
|
10 | value = boost::lexical_cast<double>(*strValue); |
| 143 | ✗ | } catch (boost::bad_lexical_cast&) { | |
| 144 | ✗ | LOG(Error, "Value: " + *strValue + ", not castable to type double.") | |
| 145 | ✗ | value = boost::none; | |
| 146 | ✗ | } | |
| 147 | } else { | ||
| 148 | 2 | value = boost::none; | |
| 149 | } | ||
| 150 | 12 | return value; | |
| 151 | 12 | } | |
| 152 | |||
| 153 | 7 | boost::optional<int> AdditionalProperties_Impl::getFeatureAsInteger(const std::string& name) const { | |
| 154 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | boost::optional<std::string> strValue(getFeatureStringAndCheckForType(name, "Integer")); |
| 155 | 7 | boost::optional<int> value; | |
| 156 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
|
7 | if (strValue) { |
| 157 | try { | ||
| 158 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
5 | value = boost::lexical_cast<int>(*strValue); |
| 159 | ✗ | } catch (boost::bad_lexical_cast&) { | |
| 160 | ✗ | LOG(Error, "Value: " + *strValue + ", not castable to type integer.") | |
| 161 | ✗ | value = boost::none; | |
| 162 | ✗ | } | |
| 163 | } else { | ||
| 164 | 2 | value = boost::none; | |
| 165 | } | ||
| 166 | 7 | return value; | |
| 167 | 7 | } | |
| 168 | |||
| 169 | 4 | boost::optional<bool> AdditionalProperties_Impl::getFeatureAsBoolean(const std::string& name) const { | |
| 170 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | boost::optional<std::string> strValue(getFeatureStringAndCheckForType(name, "Boolean")); |
| 171 | 4 | boost::optional<bool> value; | |
| 172 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (strValue) { |
| 173 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
|
4 | if (*strValue == "false") { |
| 174 |
1/1✓ Branch 1 taken 2 times.
|
2 | value = false; |
| 175 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
2 | } else if (*strValue == "true") { |
| 176 |
1/1✓ Branch 1 taken 2 times.
|
2 | value = true; |
| 177 | } else { | ||
| 178 | ✗ | LOG(Error, "Value: " + *strValue + ", not castable to type boolean.") | |
| 179 | ✗ | value = boost::none; | |
| 180 | } | ||
| 181 | } else { | ||
| 182 | ✗ | value = boost::none; | |
| 183 | } | ||
| 184 | 4 | return value; | |
| 185 | 4 | } | |
| 186 | |||
| 187 | 2 | std::vector<std::string> AdditionalProperties_Impl::suggestedFeatureNames() const { | |
| 188 | 2 | std::set<std::string> availableFeatureNames; | |
| 189 | // DLM: this should be based on the model object type right? | ||
| 190 | // DLM: should we create a virtual method for all model objects similar to outputVariableNames | ||
| 191 | // DLM: long term, this should pull from a list that can be updated at run time, possibly related to OpenStudio standards | ||
| 192 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 2 times.
|
6 | for (const AdditionalProperties& addlProps : this->model().getConcreteModelObjects<AdditionalProperties>()) { |
| 193 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 4 times.
|
10 | for (const std::string& featureName : addlProps.featureNames()) { |
| 194 |
1/1✓ Branch 1 taken 6 times.
|
6 | availableFeatureNames.insert(featureName); |
| 195 | 4 | } | |
| 196 | 2 | } | |
| 197 | 2 | std::vector<std::string> retvals; | |
| 198 |
1/1✓ Branch 3 taken 2 times.
|
2 | retvals.assign(availableFeatureNames.begin(), availableFeatureNames.end()); |
| 199 | 4 | return retvals; | |
| 200 | 2 | } | |
| 201 | |||
| 202 | 16446 | bool AdditionalProperties_Impl::setFeatureGroupDataTypeAndValue(const std::string& name, const std::string& dataType, const std::string& value) { | |
| 203 |
1/1✓ Branch 1 taken 16446 times.
|
16446 | boost::optional<ModelExtensibleGroup> group(getFeatureGroupByName(name)); |
| 204 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 16437 times.
|
16446 | if (group) { |
| 205 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | const bool dataTypeOK = group->setString(OS_AdditionalPropertiesExtensibleFields::FeatureDataType, dataType, false); |
| 206 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | const bool valueOK = group->setString(OS_AdditionalPropertiesExtensibleFields::FeatureValue, value, false); |
| 207 | // Since we're doing this checking in the public setters, these should always return true. | ||
| 208 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(dataTypeOK); |
| 209 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(valueOK); |
| 210 |
1/1✓ Branch 1 taken 9 times.
|
9 | this->emitChangeSignals(); |
| 211 | 9 | return true; | |
| 212 | } else { | ||
| 213 | 16437 | std::vector<std::string> temp; | |
| 214 |
1/1✓ Branch 1 taken 16437 times.
|
16437 | temp.push_back(name); |
| 215 |
1/1✓ Branch 1 taken 16437 times.
|
16437 | temp.push_back(dataType); |
| 216 |
1/1✓ Branch 1 taken 16437 times.
|
16437 | temp.push_back(value); |
| 217 |
2/2✓ Branch 1 taken 16437 times.
✓ Branch 4 taken 16437 times.
|
16437 | auto newgroup = pushExtensibleGroup(temp).cast<ModelExtensibleGroup>(); |
| 218 |
1/1✓ Branch 1 taken 16437 times.
|
16437 | return (!newgroup.empty()); |
| 219 | 16437 | } | |
| 220 | 16446 | } | |
| 221 | |||
| 222 | 13022 | bool AdditionalProperties_Impl::setFeature(const std::string& name, const std::string& value) { | |
| 223 |
2/2✓ Branch 1 taken 13022 times.
✓ Branch 4 taken 13022 times.
|
26044 | return setFeatureGroupDataTypeAndValue(name, "String", value); |
| 224 | } | ||
| 225 | |||
| 226 | 5 | bool AdditionalProperties_Impl::setFeature(const std::string& name, const char* value) { | |
| 227 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | return setFeature(name, std::string(value)); |
| 228 | } | ||
| 229 | |||
| 230 | 5 | bool AdditionalProperties_Impl::setFeature(const std::string& name, double value) { | |
| 231 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
15 | return setFeatureGroupDataTypeAndValue(name, "Double", boost::lexical_cast<std::string>(value)); |
| 232 | } | ||
| 233 | |||
| 234 | 8 | bool AdditionalProperties_Impl::setFeature(const std::string& name, int value) { | |
| 235 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
24 | return setFeatureGroupDataTypeAndValue(name, "Integer", boost::lexical_cast<std::string>(value)); |
| 236 | } | ||
| 237 | |||
| 238 | 3411 | bool AdditionalProperties_Impl::setFeature(const std::string& name, bool value) { | |
| 239 |
1/1✓ Branch 1 taken 3411 times.
|
3411 | auto strValue(boost::lexical_cast<std::string>(value)); |
| 240 |
2/2✓ Branch 0 taken 878 times.
✓ Branch 1 taken 2533 times.
|
3411 | if (value) { |
| 241 |
1/1✓ Branch 1 taken 878 times.
|
878 | strValue = "true"; |
| 242 | } else { | ||
| 243 |
1/1✓ Branch 1 taken 2533 times.
|
2533 | strValue = "false"; |
| 244 | } | ||
| 245 |
2/2✓ Branch 1 taken 3411 times.
✓ Branch 4 taken 3411 times.
|
6822 | return setFeatureGroupDataTypeAndValue(name, "Boolean", strValue); |
| 246 | 3411 | } | |
| 247 | |||
| 248 | 5 | bool AdditionalProperties_Impl::resetFeature(const std::string& name) { | |
| 249 | 5 | unsigned n_groups = numExtensibleGroups(); | |
| 250 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
|
11 | for (unsigned i = 0; i < n_groups; ++i) { |
| 251 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | auto group = getExtensibleGroup(i).cast<ModelExtensibleGroup>(); |
| 252 |
1/1✓ Branch 1 taken 9 times.
|
9 | const boost::optional<std::string> featureName(group.getString(OS_AdditionalPropertiesExtensibleFields::FeatureName)); |
| 253 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
|
9 | OS_ASSERT(featureName); |
| 254 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 6 times.
|
9 | if (*featureName == name) { |
| 255 |
1/1✓ Branch 1 taken 3 times.
|
3 | eraseExtensibleGroup(i); |
| 256 | 3 | return true; | |
| 257 | } | ||
| 258 | 12 | } | |
| 259 | 2 | return false; | |
| 260 | } | ||
| 261 | |||
| 262 | 877 | void AdditionalProperties_Impl::merge(const AdditionalProperties& other, bool overwrite) { | |
| 263 |
4/5✓ Branch 1 taken 877 times.
✓ Branch 4 taken 877 times.
✓ Branch 7 taken 877 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 877 times.
|
877 | if (other.handle() == this->handle()) { |
| 264 | ✗ | return; | |
| 265 | } | ||
| 266 | |||
| 267 |
3/3✓ Branch 1 taken 877 times.
✓ Branch 8 taken 2359 times.
✓ Branch 9 taken 877 times.
|
3236 | for (const auto& featureName : other.featureNames()) { |
| 268 | // check if we already have this key | ||
| 269 |
3/11✗ Branch 0 not taken.
✓ Branch 1 taken 2359 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2359 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2359 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
2359 | if ((!overwrite) && this->getFeatureDataType(featureName)) { |
| 270 | ✗ | continue; | |
| 271 | } | ||
| 272 | |||
| 273 |
1/1✓ Branch 1 taken 2359 times.
|
2359 | boost::optional<std::string> dataType = other.getFeatureDataType(featureName); |
| 274 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2359 times.
✗ Branch 4 not taken.
|
2359 | OS_ASSERT(dataType); |
| 275 |
4/5✓ Branch 1 taken 2359 times.
✓ Branch 4 taken 2359 times.
✓ Branch 7 taken 2359 times.
✓ Branch 10 taken 2359 times.
✗ Branch 11 not taken.
|
7077 | if (istringEqual("String", *dataType)) { |
| 276 |
1/1✓ Branch 1 taken 2359 times.
|
2359 | boost::optional<std::string> v = other.getFeatureAsString(featureName); |
| 277 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2359 times.
✗ Branch 4 not taken.
|
2359 | OS_ASSERT(v); |
| 278 |
2/2✓ Branch 1 taken 2359 times.
✓ Branch 4 taken 2359 times.
|
2359 | this->setFeature(featureName, *v); |
| 279 |
0/5✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
2359 | } else if (istringEqual("Double", *dataType)) { |
| 280 | ✗ | boost::optional<double> v = other.getFeatureAsDouble(featureName); | |
| 281 | ✗ | OS_ASSERT(v); | |
| 282 | ✗ | this->setFeature(featureName, *v); | |
| 283 | ✗ | } else if (istringEqual("Boolean", *dataType)) { | |
| 284 | ✗ | boost::optional<bool> v = other.getFeatureAsBoolean(featureName); | |
| 285 | ✗ | OS_ASSERT(v); | |
| 286 | ✗ | this->setFeature(featureName, *v); | |
| 287 | ✗ | } else if (istringEqual("Integer", *dataType)) { | |
| 288 | ✗ | boost::optional<int> v = other.getFeatureAsInteger(featureName); | |
| 289 | ✗ | OS_ASSERT(v); | |
| 290 | ✗ | this->setFeature(featureName, *v); | |
| 291 | } | ||
| 292 | 3236 | } | |
| 293 | } | ||
| 294 | |||
| 295 | } // namespace detail | ||
| 296 | |||
| 297 | 5067 | AdditionalProperties::AdditionalProperties(const ModelObject& modelObject) | |
| 298 |
3/3✓ Branch 1 taken 5067 times.
✓ Branch 4 taken 5067 times.
✓ Branch 7 taken 5067 times.
|
5067 | : ModelObject(AdditionalProperties::iddObjectType(), modelObject.model()) { |
| 299 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 5067 times.
✗ Branch 5 not taken.
|
5067 | OS_ASSERT(getImpl<detail::AdditionalProperties_Impl>()); |
| 300 | |||
| 301 |
3/3✓ Branch 1 taken 5067 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 5066 times.
|
10134 | if (modelObject.optionalCast<AdditionalProperties>()) { |
| 302 |
1/1✓ Branch 1 taken 1 time.
|
1 | this->remove(); |
| 303 |
13/13✓ 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 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.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
|
1 | LOG_AND_THROW("Cannot create a AdditionalProperties object for AdditionalProperties object"); |
| 304 | } | ||
| 305 | |||
| 306 |
2/2✓ Branch 1 taken 5066 times.
✓ Branch 4 taken 5066 times.
|
5066 | bool ok = setPointer(OS_AdditionalPropertiesFields::ObjectName, modelObject.handle()); |
| 307 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 5066 times.
✗ Branch 3 not taken.
|
5066 | OS_ASSERT(ok); |
| 308 | 5067 | } | |
| 309 | |||
| 310 | 4 | ModelObject AdditionalProperties::modelObject() const { | |
| 311 |
1/1✓ Branch 3 taken 3 times.
|
4 | return getImpl<detail::AdditionalProperties_Impl>()->modelObject(); |
| 312 | } | ||
| 313 | |||
| 314 | 19477 | IddObjectType AdditionalProperties::iddObjectType() { | |
| 315 |
1/1✓ Branch 1 taken 19477 times.
|
19477 | IddObjectType result(IddObjectType::OS_AdditionalProperties); |
| 316 | 19477 | return result; | |
| 317 | } | ||
| 318 | |||
| 319 | 896 | std::vector<std::string> AdditionalProperties::featureNames() const { | |
| 320 |
1/1✓ Branch 3 taken 896 times.
|
896 | return getImpl<detail::AdditionalProperties_Impl>()->featureNames(); |
| 321 | } | ||
| 322 | |||
| 323 | 11343 | bool AdditionalProperties::hasFeature(const std::string& name) const { | |
| 324 |
1/1✓ Branch 3 taken 11343 times.
|
11343 | return getImpl<detail::AdditionalProperties_Impl>()->hasFeature(name); |
| 325 | } | ||
| 326 | |||
| 327 | 2384 | boost::optional<std::string> AdditionalProperties::getFeatureDataType(const std::string& name) const { | |
| 328 |
1/1✓ Branch 3 taken 2384 times.
|
2384 | return getImpl<detail::AdditionalProperties_Impl>()->getFeatureDataType(name); |
| 329 | } | ||
| 330 | |||
| 331 | 9931 | boost::optional<std::string> AdditionalProperties::getFeatureAsString(const std::string& name) const { | |
| 332 |
1/1✓ Branch 3 taken 9931 times.
|
9931 | return getImpl<detail::AdditionalProperties_Impl>()->getFeatureAsString(name); |
| 333 | } | ||
| 334 | |||
| 335 | 12 | boost::optional<double> AdditionalProperties::getFeatureAsDouble(const std::string& name) const { | |
| 336 |
1/1✓ Branch 3 taken 12 times.
|
12 | return getImpl<detail::AdditionalProperties_Impl>()->getFeatureAsDouble(name); |
| 337 | } | ||
| 338 | |||
| 339 | 7 | boost::optional<int> AdditionalProperties::getFeatureAsInteger(const std::string& name) const { | |
| 340 |
1/1✓ Branch 3 taken 7 times.
|
7 | return getImpl<detail::AdditionalProperties_Impl>()->getFeatureAsInteger(name); |
| 341 | } | ||
| 342 | |||
| 343 | 4 | boost::optional<bool> AdditionalProperties::getFeatureAsBoolean(const std::string& name) const { | |
| 344 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::AdditionalProperties_Impl>()->getFeatureAsBoolean(name); |
| 345 | } | ||
| 346 | |||
| 347 | 2 | std::vector<std::string> AdditionalProperties::suggestedFeatureNames() const { | |
| 348 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::AdditionalProperties_Impl>()->suggestedFeatureNames(); |
| 349 | } | ||
| 350 | |||
| 351 | 10658 | bool AdditionalProperties::setFeature(const std::string& name, const std::string& value) { | |
| 352 |
1/1✓ Branch 3 taken 10658 times.
|
10658 | return getImpl<detail::AdditionalProperties_Impl>()->setFeature(name, value); |
| 353 | } | ||
| 354 | |||
| 355 | 5 | bool AdditionalProperties::setFeature(const std::string& name, const char* value) { | |
| 356 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::AdditionalProperties_Impl>()->setFeature(name, value); |
| 357 | } | ||
| 358 | |||
| 359 | 5 | bool AdditionalProperties::setFeature(const std::string& name, double value) { | |
| 360 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::AdditionalProperties_Impl>()->setFeature(name, value); |
| 361 | } | ||
| 362 | |||
| 363 | 8 | bool AdditionalProperties::setFeature(const std::string& name, int value) { | |
| 364 |
1/1✓ Branch 3 taken 8 times.
|
8 | return getImpl<detail::AdditionalProperties_Impl>()->setFeature(name, value); |
| 365 | } | ||
| 366 | |||
| 367 | 3411 | bool AdditionalProperties::setFeature(const std::string& name, bool value) { | |
| 368 |
1/1✓ Branch 3 taken 3411 times.
|
3411 | return getImpl<detail::AdditionalProperties_Impl>()->setFeature(name, value); |
| 369 | } | ||
| 370 | |||
| 371 | 5 | bool AdditionalProperties::resetFeature(const std::string& name) { | |
| 372 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::AdditionalProperties_Impl>()->resetFeature(name); |
| 373 | } | ||
| 374 | |||
| 375 | 877 | void AdditionalProperties::merge(const AdditionalProperties& other, bool overwrite) { | |
| 376 |
1/1✓ Branch 3 taken 877 times.
|
877 | getImpl<detail::AdditionalProperties_Impl>()->merge(other, overwrite); |
| 377 | 877 | } | |
| 378 | |||
| 379 | /// @cond | ||
| 380 |
1/1✓ Branch 3 taken 34548 times.
|
34548 | AdditionalProperties::AdditionalProperties(std::shared_ptr<detail::AdditionalProperties_Impl> impl) : ModelObject(std::move(impl)) {} |
| 381 | /// @endcond | ||
| 382 | |||
| 383 | } // namespace model | ||
| 384 | } // namespace openstudio | ||
| 385 |