src/utilities/data/Attribute.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 "Attribute.hpp" | ||
| 7 | #include "Attribute_Impl.hpp" | ||
| 8 | |||
| 9 | #include "../core/Assert.hpp" | ||
| 10 | #include "../core/Containers.hpp" | ||
| 11 | #include "../core/FilesystemHelpers.hpp" | ||
| 12 | #include "../core/StringHelpers.hpp" | ||
| 13 | |||
| 14 | #include <boost/lexical_cast.hpp> | ||
| 15 | #include <pugixml.hpp> | ||
| 16 | #include <json/json.h> | ||
| 17 | |||
| 18 | namespace openstudio { | ||
| 19 | namespace detail { | ||
| 20 | |||
| 21 | // constructors | ||
| 22 | 491 | Attribute_Impl::Attribute_Impl(const std::string& name, bool value, const boost::optional<std::string>& units) | |
| 23 |
5/5✓ Branch 2 taken 491 times.
✓ Branch 5 taken 491 times.
✓ Branch 8 taken 491 times.
✓ Branch 13 taken 491 times.
✓ Branch 17 taken 491 times.
|
491 | : m_uuid(createUUID()), m_versionUUID(createUUID()), m_name(name), m_valueType(AttributeValueType::Boolean), m_value(value), m_units(units) {} |
| 24 | |||
| 25 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 26 | const boost::optional<std::string>& displayName, bool value, const boost::optional<std::string>& units, | ||
| 27 | ✗ | const std::string& source) | |
| 28 | ✗ | : m_uuid(uuid), | |
| 29 | ✗ | m_versionUUID(versionUUID), | |
| 30 | ✗ | m_name(name), | |
| 31 | ✗ | m_displayName(displayName), | |
| 32 | ✗ | m_source(source), | |
| 33 | ✗ | m_valueType(AttributeValueType::Boolean), | |
| 34 | ✗ | m_value(value), | |
| 35 | ✗ | m_units(units) {} | |
| 36 | |||
| 37 | 575 | Attribute_Impl::Attribute_Impl(const std::string& name, double value, const boost::optional<std::string>& units) | |
| 38 |
5/5✓ Branch 2 taken 575 times.
✓ Branch 5 taken 575 times.
✓ Branch 8 taken 575 times.
✓ Branch 13 taken 575 times.
✓ Branch 17 taken 575 times.
|
575 | : m_uuid(createUUID()), m_versionUUID(createUUID()), m_name(name), m_valueType(AttributeValueType::Double), m_value(value), m_units(units) {} |
| 39 | |||
| 40 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 41 | const boost::optional<std::string>& displayName, double value, const boost::optional<std::string>& units, | ||
| 42 | ✗ | const std::string& source) | |
| 43 | ✗ | : m_uuid(uuid), | |
| 44 | ✗ | m_versionUUID(versionUUID), | |
| 45 | ✗ | m_name(name), | |
| 46 | ✗ | m_displayName(displayName), | |
| 47 | ✗ | m_source(source), | |
| 48 | ✗ | m_valueType(AttributeValueType::Double), | |
| 49 | ✗ | m_value(value), | |
| 50 | ✗ | m_units(units) {} | |
| 51 | |||
| 52 | 19 | Attribute_Impl::Attribute_Impl(const std::string& name, int value, const boost::optional<std::string>& units) | |
| 53 |
5/5✓ Branch 2 taken 19 times.
✓ Branch 5 taken 19 times.
✓ Branch 8 taken 19 times.
✓ Branch 13 taken 19 times.
✓ Branch 17 taken 19 times.
|
19 | : m_uuid(createUUID()), m_versionUUID(createUUID()), m_name(name), m_valueType(AttributeValueType::Integer), m_value(value), m_units(units) {} |
| 54 | |||
| 55 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 56 | const boost::optional<std::string>& displayName, int value, const boost::optional<std::string>& units, | ||
| 57 | ✗ | const std::string& source) | |
| 58 | ✗ | : m_uuid(uuid), | |
| 59 | ✗ | m_versionUUID(versionUUID), | |
| 60 | ✗ | m_name(name), | |
| 61 | ✗ | m_displayName(displayName), | |
| 62 | ✗ | m_source(source), | |
| 63 | ✗ | m_valueType(AttributeValueType::Integer), | |
| 64 | ✗ | m_value(value), | |
| 65 | ✗ | m_units(units) {} | |
| 66 | |||
| 67 | 13 | Attribute_Impl::Attribute_Impl(const std::string& name, unsigned value, const boost::optional<std::string>& units) | |
| 68 |
5/5✓ Branch 2 taken 13 times.
✓ Branch 5 taken 13 times.
✓ Branch 8 taken 13 times.
✓ Branch 13 taken 13 times.
✓ Branch 17 taken 13 times.
|
13 | : m_uuid(createUUID()), m_versionUUID(createUUID()), m_name(name), m_valueType(AttributeValueType::Unsigned), m_value(value), m_units(units) {} |
| 69 | |||
| 70 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 71 | const boost::optional<std::string>& displayName, unsigned value, const boost::optional<std::string>& units, | ||
| 72 | ✗ | const std::string& source) | |
| 73 | ✗ | : m_uuid(uuid), | |
| 74 | ✗ | m_versionUUID(versionUUID), | |
| 75 | ✗ | m_name(name), | |
| 76 | ✗ | m_displayName(displayName), | |
| 77 | ✗ | m_source(source), | |
| 78 | ✗ | m_valueType(AttributeValueType::Unsigned), | |
| 79 | ✗ | m_value(value), | |
| 80 | ✗ | m_units(units) {} | |
| 81 | |||
| 82 | 1788 | Attribute_Impl::Attribute_Impl(const std::string& name, const std::string& value, const boost::optional<std::string>& units) | |
| 83 | 1788 | : m_uuid(createUUID()), | |
| 84 |
1/1✓ Branch 1 taken 1788 times.
|
1788 | m_versionUUID(createUUID()), |
| 85 |
1/1✓ Branch 1 taken 1788 times.
|
1788 | m_name(name), |
| 86 |
1/1✓ Branch 1 taken 1788 times.
|
1788 | m_valueType(AttributeValueType::String), |
| 87 |
1/1✓ Branch 1 taken 1788 times.
|
1788 | m_value(std::string(value)), |
| 88 |
2/2✓ Branch 2 taken 1788 times.
✓ Branch 7 taken 1788 times.
|
5364 | m_units(units) {} |
| 89 | |||
| 90 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 91 | const boost::optional<std::string>& displayName, const std::string& value, const boost::optional<std::string>& units, | ||
| 92 | ✗ | const std::string& source) | |
| 93 | ✗ | : m_uuid(uuid), | |
| 94 | ✗ | m_versionUUID(versionUUID), | |
| 95 | ✗ | m_name(name), | |
| 96 | ✗ | m_displayName(displayName), | |
| 97 | ✗ | m_source(source), | |
| 98 | ✗ | m_valueType(AttributeValueType::String), | |
| 99 | ✗ | m_value(value), | |
| 100 | ✗ | m_units(units) {} | |
| 101 | |||
| 102 | 214 | Attribute_Impl::Attribute_Impl(const std::string& name, const std::vector<openstudio::Attribute>& value, const boost::optional<std::string>& units) | |
| 103 | 214 | : m_uuid(createUUID()), | |
| 104 |
1/1✓ Branch 1 taken 214 times.
|
214 | m_versionUUID(createUUID()), |
| 105 |
1/1✓ Branch 1 taken 214 times.
|
214 | m_name(name), |
| 106 |
1/1✓ Branch 1 taken 214 times.
|
214 | m_valueType(AttributeValueType::AttributeVector), |
| 107 |
1/1✓ Branch 1 taken 214 times.
|
214 | m_value(value), |
| 108 |
2/2✓ Branch 2 taken 214 times.
✓ Branch 7 taken 214 times.
|
642 | m_units(units) {} |
| 109 | |||
| 110 | ✗ | Attribute_Impl::Attribute_Impl(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 111 | const boost::optional<std::string>& displayName, const std::vector<openstudio::Attribute>& value, | ||
| 112 | ✗ | const boost::optional<std::string>& units, const std::string& source) | |
| 113 | ✗ | : m_uuid(uuid), | |
| 114 | ✗ | m_versionUUID(versionUUID), | |
| 115 | ✗ | m_name(name), | |
| 116 | ✗ | m_displayName(displayName), | |
| 117 | ✗ | m_source(source), | |
| 118 | ✗ | m_valueType(AttributeValueType::AttributeVector), | |
| 119 | ✗ | m_value(value), | |
| 120 | ✗ | m_units(units) {} | |
| 121 | |||
| 122 |
3/3✓ Branch 2 taken 106 times.
✓ Branch 5 taken 106 times.
✓ Branch 11 taken 106 times.
|
106 | Attribute_Impl::Attribute_Impl(const pugi::xml_node& element) { // NOLINT(misc-no-recursion) |
| 123 |
2/3✓ Branch 1 taken 106 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 106 times.
|
106 | if (!element) { |
| 124 | ✗ | LOG_AND_THROW("Cannot construct Attribute from null pugi::xml_node element"); | |
| 125 | } | ||
| 126 | |||
| 127 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node uuidElement = element.child("UUID"); |
| 128 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node versionUUIDElement = element.child("VersionUUID"); |
| 129 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node nameElement = element.child("Name"); |
| 130 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node displayNameElement = element.child("DisplayName"); |
| 131 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node sourceElement = element.child("Source"); |
| 132 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node valueTypeElement = element.child("ValueType"); |
| 133 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node valueElement = element.child("Value"); |
| 134 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node unitsElement = element.child("Units"); |
| 135 |
1/1✓ Branch 1 taken 106 times.
|
106 | pugi::xml_node unitSystemElement = element.child("UnitSystem"); |
| 136 | |||
| 137 |
3/3✓ Branch 1 taken 106 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 105 times.
|
106 | if (!uuidElement) { |
| 138 |
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("UUID is required and cannot be null."); |
| 139 | } | ||
| 140 |
3/3✓ Branch 1 taken 105 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 104 times.
|
105 | if (!versionUUIDElement) { |
| 141 |
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("VersionUUID is required and cannot be null."); |
| 142 | } | ||
| 143 |
3/3✓ Branch 1 taken 104 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 103 times.
|
104 | if (!nameElement) { |
| 144 |
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("Name is required and cannot be null."); |
| 145 | } | ||
| 146 |
3/3✓ Branch 1 taken 103 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 102 times.
|
103 | if (!valueTypeElement) { |
| 147 |
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("ValueType is required and cannot be null."); |
| 148 | } | ||
| 149 |
3/3✓ Branch 1 taken 102 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 101 times.
|
102 | if (!valueElement) { |
| 150 |
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("Value is required and cannot be null."); |
| 151 | } | ||
| 152 | |||
| 153 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | std::string uuid = uuidElement.text().as_string(); |
| 154 |
1/1✓ Branch 1 taken 101 times.
|
101 | m_uuid = toUUID(uuid); |
| 155 | |||
| 156 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | std::string vuuid = versionUUIDElement.text().as_string(); |
| 157 |
1/1✓ Branch 1 taken 101 times.
|
101 | m_versionUUID = toUUID(vuuid); |
| 158 | |||
| 159 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | m_name = nameElement.text().as_string(); |
| 160 | |||
| 161 |
2/3✓ Branch 1 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
|
101 | if (displayNameElement) { |
| 162 | ✗ | m_displayName = displayNameElement.text().as_string(); | |
| 163 | } | ||
| 164 | |||
| 165 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 91 times.
|
101 | if (sourceElement) { |
| 166 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
|
10 | m_source = sourceElement.text().as_string(); |
| 167 | } | ||
| 168 | |||
| 169 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | std::string valueTypeString = valueTypeElement.text().as_string(); |
| 170 | // Deprecated! | ||
| 171 |
2/3✓ Branch 1 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
|
101 | if (valueTypeString == "Unit") { |
| 172 | ✗ | LOG(Warn, "AttributeValueType::Unit is deprecated and is mapped to String."); | |
| 173 | ✗ | valueTypeString = "String"; | |
| 174 |
2/3✓ Branch 1 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
|
101 | } else if (valueTypeString == "Quantity") { |
| 175 | // Deprecated! | ||
| 176 | ✗ | LOG(Warn, "AttributeValueType::Quantity is deprecated and is mapped to Double."); | |
| 177 | ✗ | valueTypeString = "Double"; | |
| 178 | // Could check if units is also there, but we don't really care | ||
| 179 | } | ||
| 180 | |||
| 181 | try { | ||
| 182 |
1/1✓ Branch 1 taken 100 times.
|
101 | m_valueType = AttributeValueType(valueTypeString); |
| 183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | } catch (const std::exception&) { |
| 184 |
17/17✓ 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 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 50 taken 1 time.
✓ Branch 53 taken 1 time.
|
1 | LOG_AND_THROW("Couldn't create an AttributeValueType with value: [" << valueTypeString << "]."); |
| 185 | 1 | } | |
| 186 | |||
| 187 |
3/3✓ Branch 1 taken 100 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 79 times.
|
100 | if (unitsElement) { |
| 188 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 7 taken 21 times.
|
21 | m_units = unitsElement.text().as_string(); |
| 189 | } | ||
| 190 | |||
| 191 | // TODO: handle unitsSystem conversion? I think it's redundant with the information contained inside "Units" and we're no longer | ||
| 192 | // creating quantities anyways | ||
| 193 | // OptionalUnitSystem sys; | ||
| 194 |
2/3✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
|
100 | if (unitSystemElement) { |
| 195 | ✗ | LOG(Warn, "UnitSystem is deprecated and isn't used, units are stored as string within the 'Units' tag instead"); | |
| 196 | // sys = UnitSystem(unitSystemElement.text().as_string()); | ||
| 197 | } | ||
| 198 | |||
| 199 | // Note JM 2018-12-17: We do not use pugixml's text().as_double (as_int, as_uint) | ||
| 200 | // because it's too permissive and will return 0 even if the string isn't actually representing a number | ||
| 201 | // So we use boost::lexical_cast instead | ||
| 202 | |||
| 203 |
3/3✓ Branch 1 taken 100 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 95 times.
|
100 | if (m_valueType.value() == AttributeValueType::Boolean) { |
| 204 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | m_value = valueElement.text().as_bool(); |
| 205 |
3/3✓ Branch 1 taken 95 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 91 times.
|
95 | } else if (m_valueType.value() == AttributeValueType::Integer) { |
| 206 | try { | ||
| 207 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | m_value = boost::lexical_cast<int>(valueElement.text().as_string()); |
| 208 | ✗ | } catch (const boost::bad_lexical_cast&) { | |
| 209 | ✗ | LOG_AND_THROW("Please double check your XML, you have an Attribute with a ValueType of 'Integer' " | |
| 210 | << "but the Value isn't an int: [" << valueElement.text().as_string() << "]."); | ||
| 211 | ✗ | } | |
| 212 |
3/3✓ Branch 1 taken 91 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 83 times.
|
91 | } else if (m_valueType.value() == AttributeValueType::Unsigned) { |
| 213 | try { | ||
| 214 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
8 | m_value = boost::lexical_cast<unsigned>(valueElement.text().as_string()); |
| 215 | ✗ | } catch (const boost::bad_lexical_cast&) { | |
| 216 | ✗ | LOG_AND_THROW("Please double check your XML, you have an Attribute with a ValueType of 'Unsigned' " | |
| 217 | << "but the Value isn't an unsigned int: [" << valueElement.text().as_string() << "]."); | ||
| 218 | ✗ | } | |
| 219 |
3/3✓ Branch 1 taken 83 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 50 times.
|
83 | } else if (m_valueType.value() == AttributeValueType::Double) { |
| 220 | try { | ||
| 221 |
3/3✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 7 taken 32 times.
|
33 | m_value = boost::lexical_cast<double>(valueElement.text().as_string()); |
| 222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | } catch (const boost::bad_lexical_cast&) { |
| 223 |
23/23✓ 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 34 taken 1 time.
✓ Branch 37 taken 1 time.
✓ Branch 40 taken 1 time.
✓ Branch 43 taken 1 time.
✓ Branch 46 taken 1 time.
✓ Branch 49 taken 1 time.
✓ Branch 52 taken 1 time.
✓ Branch 55 taken 1 time.
✓ Branch 58 taken 1 time.
✓ Branch 61 taken 1 time.
✓ Branch 64 taken 1 time.
✓ Branch 68 taken 1 time.
✓ Branch 71 taken 1 time.
|
1 | LOG_AND_THROW("Please double check your XML, you have an Attribute with a ValueType of 'Double' " << "but the Value isn't a double: [" |
| 224 | << valueElement.text().as_string() << "]."); | ||
| 225 | 1 | } | |
| 226 |
3/3✓ Branch 1 taken 50 times.
✓ Branch 3 taken 26 times.
✓ Branch 4 taken 24 times.
|
50 | } else if (m_valueType.value() == AttributeValueType::String) { |
| 227 | // Note JM 2018-12-14: Carefull not to end up with const char, | ||
| 228 | // since that'll emplace in bool by default | ||
| 229 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
|
26 | m_value.emplace<std::string>(valueElement.text().as_string()); |
| 230 |
2/3✓ Branch 1 taken 24 times.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
|
24 | } else if (m_valueType.value() == AttributeValueType::AttributeVector) { |
| 231 | 24 | std::vector<Attribute> children; | |
| 232 | |||
| 233 |
6/6✓ Branch 1 taken 24 times.
✓ Branch 6 taken 85 times.
✓ Branch 9 taken 85 times.
✓ Branch 12 taken 109 times.
✓ Branch 14 taken 85 times.
✓ Branch 15 taken 24 times.
|
109 | for (const pugi::xml_node& childElement : valueElement.children()) { |
| 234 |
1/1✓ Branch 1 taken 85 times.
|
85 | children.emplace_back(childElement); |
| 235 | } | ||
| 236 |
1/1✓ Branch 1 taken 24 times.
|
24 | m_value = children; |
| 237 | |||
| 238 | 24 | } else { | |
| 239 | // Should never happen | ||
| 240 | ✗ | OS_ASSERT(false); | |
| 241 | } | ||
| 242 | 147 | } | |
| 243 | |||
| 244 | ✗ | Attribute_Impl::Attribute_Impl(const Attribute_Impl& other) | |
| 245 | ✗ | : m_uuid(createUUID()), | |
| 246 | ✗ | m_versionUUID(createUUID()), | |
| 247 | ✗ | m_name(other.name()), | |
| 248 | ✗ | m_displayName(other.displayName()), | |
| 249 | ✗ | m_source(other.source()), | |
| 250 | ✗ | m_valueType(other.valueType()), | |
| 251 | ✗ | m_value(other.m_value), | |
| 252 | ✗ | m_units(other.units()) {} | |
| 253 | |||
| 254 | ✗ | openstudio::UUID Attribute_Impl::uuid() const { | |
| 255 | ✗ | return m_uuid; | |
| 256 | } | ||
| 257 | |||
| 258 | ✗ | openstudio::UUID Attribute_Impl::versionUUID() const { | |
| 259 | ✗ | return m_versionUUID; | |
| 260 | } | ||
| 261 | |||
| 262 | 11783 | std::string Attribute_Impl::name() const { | |
| 263 | 11783 | return m_name; | |
| 264 | } | ||
| 265 | |||
| 266 | 19 | boost::optional<std::string> Attribute_Impl::displayName(bool returnName) const { | |
| 267 | 19 | OptionalString result = m_displayName; | |
| 268 |
6/6✓ Branch 1 taken 18 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 18 times.
|
19 | if (!result && returnName) { |
| 269 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | result = name(); |
| 270 | } | ||
| 271 | 19 | return result; | |
| 272 | ✗ | } | |
| 273 | |||
| 274 | 9 | bool Attribute_Impl::setDisplayName(const std::string& displayName) { | |
| 275 | 9 | m_displayName = displayName; | |
| 276 | 9 | m_versionUUID = createUUID(); | |
| 277 | 9 | return true; | |
| 278 | } | ||
| 279 | |||
| 280 | ✗ | void Attribute_Impl::clearDisplayName() { | |
| 281 | ✗ | if (m_displayName) { | |
| 282 | ✗ | m_displayName.reset(); | |
| 283 | ✗ | m_versionUUID = createUUID(); | |
| 284 | } | ||
| 285 | ✗ | } | |
| 286 | |||
| 287 | 16 | std::string Attribute_Impl::source() const { | |
| 288 | 16 | return m_source; | |
| 289 | } | ||
| 290 | |||
| 291 | 6 | void Attribute_Impl::setSource(const std::string& source) { | |
| 292 | 6 | m_source = source; | |
| 293 | 6 | m_versionUUID = createUUID(); | |
| 294 | 6 | } | |
| 295 | |||
| 296 | ✗ | void Attribute_Impl::clearSource() { | |
| 297 | ✗ | if (!m_source.empty()) { | |
| 298 | ✗ | m_source.clear(); | |
| 299 | ✗ | m_versionUUID = createUUID(); | |
| 300 | } | ||
| 301 | ✗ | } | |
| 302 | |||
| 303 | 1122 | AttributeValueType Attribute_Impl::valueType() const { | |
| 304 | 1122 | return m_valueType; | |
| 305 | } | ||
| 306 | |||
| 307 | 6794 | bool Attribute_Impl::hasValue() const { | |
| 308 | 6794 | return (m_value.index() != 0); | |
| 309 | } | ||
| 310 | |||
| 311 | 15 | bool Attribute_Impl::valueAsBoolean() const { | |
| 312 |
7/8✓ Branch 1 taken 15 times.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 11 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 11 times.
|
15 | if (!hasValue() || m_valueType != AttributeValueType::Boolean) { |
| 313 |
27/27✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 30 taken 4 times.
✓ Branch 33 taken 4 times.
✓ Branch 36 taken 4 times.
✓ Branch 42 taken 4 times.
✓ Branch 45 taken 4 times.
✓ Branch 48 taken 4 times.
✓ Branch 51 taken 4 times.
✓ Branch 54 taken 4 times.
✓ Branch 57 taken 4 times.
✓ Branch 60 taken 4 times.
✓ Branch 63 taken 4 times.
✓ Branch 66 taken 4 times.
✓ Branch 69 taken 4 times.
✓ Branch 72 taken 4 times.
✓ Branch 75 taken 4 times.
✓ Branch 78 taken 4 times.
✓ Branch 84 taken 4 times.
✓ Branch 87 taken 4 times.
|
4 | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to Boolean."); |
| 314 | } | ||
| 315 | // Note JM 2019-05-17: This is functionally equivalent to `std::get<bool>(m_value)` except it doesn't risk throwing | ||
| 316 | // std::bad_variant_access which isn't available on mac prior to 10.14 | ||
| 317 | // No need to check if get_if succeeds because we checked the type above | ||
| 318 | 11 | return *(std::get_if<bool>(&m_value)); | |
| 319 | } | ||
| 320 | |||
| 321 | ✗ | void Attribute_Impl::setValue(bool value) { | |
| 322 | ✗ | if (m_valueType != AttributeValueType::Boolean) { | |
| 323 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not Boolean."); | |
| 324 | } | ||
| 325 | ✗ | m_value = value; | |
| 326 | ✗ | m_versionUUID = createUUID(); | |
| 327 | ✗ | } | |
| 328 | |||
| 329 | 13 | int Attribute_Impl::valueAsInteger() const { | |
| 330 |
7/8✓ Branch 1 taken 13 times.
✓ Branch 3 taken 13 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 13 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 9 times.
|
13 | if (!hasValue() || m_valueType != AttributeValueType::Integer) { |
| 331 |
27/27✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 30 taken 4 times.
✓ Branch 33 taken 4 times.
✓ Branch 36 taken 4 times.
✓ Branch 42 taken 4 times.
✓ Branch 45 taken 4 times.
✓ Branch 48 taken 4 times.
✓ Branch 51 taken 4 times.
✓ Branch 54 taken 4 times.
✓ Branch 57 taken 4 times.
✓ Branch 60 taken 4 times.
✓ Branch 63 taken 4 times.
✓ Branch 66 taken 4 times.
✓ Branch 69 taken 4 times.
✓ Branch 72 taken 4 times.
✓ Branch 75 taken 4 times.
✓ Branch 78 taken 4 times.
✓ Branch 84 taken 4 times.
✓ Branch 87 taken 4 times.
|
4 | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to Integer."); |
| 332 | } | ||
| 333 | 9 | return *(std::get_if<int>(&m_value)); | |
| 334 | } | ||
| 335 | |||
| 336 | ✗ | void Attribute_Impl::setValue(int value) { | |
| 337 | ✗ | if (m_valueType != AttributeValueType::Integer) { | |
| 338 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not Integer."); | |
| 339 | } | ||
| 340 | ✗ | m_value = value; | |
| 341 | ✗ | m_versionUUID = createUUID(); | |
| 342 | ✗ | } | |
| 343 | |||
| 344 | 16 | unsigned Attribute_Impl::valueAsUnsigned() const { | |
| 345 |
5/8✓ Branch 1 taken 16 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 16 times.
|
16 | if (!hasValue() || m_valueType != AttributeValueType::Unsigned) { |
| 346 | ✗ | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to Unsigned."); | |
| 347 | } | ||
| 348 | 16 | return *(std::get_if<unsigned>(&m_value)); | |
| 349 | } | ||
| 350 | |||
| 351 | ✗ | void Attribute_Impl::setValue(unsigned value) { | |
| 352 | ✗ | if (m_valueType != AttributeValueType::Unsigned) { | |
| 353 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not Unsigned."); | |
| 354 | } | ||
| 355 | ✗ | m_value = value; | |
| 356 | ✗ | m_versionUUID = createUUID(); | |
| 357 | ✗ | } | |
| 358 | |||
| 359 | 294 | double Attribute_Impl::valueAsDouble() const { | |
| 360 |
7/8✓ Branch 1 taken 294 times.
✓ Branch 3 taken 294 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 294 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 290 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 290 times.
|
294 | if (!hasValue() || m_valueType != AttributeValueType::Double) { |
| 361 |
27/27✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 30 taken 4 times.
✓ Branch 33 taken 4 times.
✓ Branch 36 taken 4 times.
✓ Branch 42 taken 4 times.
✓ Branch 45 taken 4 times.
✓ Branch 48 taken 4 times.
✓ Branch 51 taken 4 times.
✓ Branch 54 taken 4 times.
✓ Branch 57 taken 4 times.
✓ Branch 60 taken 4 times.
✓ Branch 63 taken 4 times.
✓ Branch 66 taken 4 times.
✓ Branch 69 taken 4 times.
✓ Branch 72 taken 4 times.
✓ Branch 75 taken 4 times.
✓ Branch 78 taken 4 times.
✓ Branch 84 taken 4 times.
✓ Branch 87 taken 4 times.
|
4 | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to Double."); |
| 362 | } | ||
| 363 | 290 | return *(std::get_if<double>(&m_value)); | |
| 364 | } | ||
| 365 | |||
| 366 | ✗ | void Attribute_Impl::setValue(double value) { | |
| 367 | ✗ | if (m_valueType != AttributeValueType::Double) { | |
| 368 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not Double."); | |
| 369 | } | ||
| 370 | ✗ | m_value = value; | |
| 371 | ✗ | m_versionUUID = createUUID(); | |
| 372 | ✗ | } | |
| 373 | |||
| 374 | 944 | std::string Attribute_Impl::valueAsString() const { | |
| 375 |
7/8✓ Branch 1 taken 944 times.
✓ Branch 3 taken 944 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 944 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 940 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 940 times.
|
944 | if (!hasValue() || m_valueType != AttributeValueType::String) { |
| 376 |
27/27✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 30 taken 4 times.
✓ Branch 33 taken 4 times.
✓ Branch 36 taken 4 times.
✓ Branch 42 taken 4 times.
✓ Branch 45 taken 4 times.
✓ Branch 48 taken 4 times.
✓ Branch 51 taken 4 times.
✓ Branch 54 taken 4 times.
✓ Branch 57 taken 4 times.
✓ Branch 60 taken 4 times.
✓ Branch 63 taken 4 times.
✓ Branch 66 taken 4 times.
✓ Branch 69 taken 4 times.
✓ Branch 72 taken 4 times.
✓ Branch 75 taken 4 times.
✓ Branch 78 taken 4 times.
✓ Branch 84 taken 4 times.
✓ Branch 87 taken 4 times.
|
4 | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to String."); |
| 377 | } | ||
| 378 | 940 | return *(std::get_if<std::string>(&m_value)); | |
| 379 | } | ||
| 380 | |||
| 381 | ✗ | void Attribute_Impl::setValue(const char* value) { | |
| 382 | ✗ | if (m_valueType != AttributeValueType::String) { | |
| 383 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not String."); | |
| 384 | } | ||
| 385 | ✗ | m_value = std::string(value); | |
| 386 | ✗ | m_versionUUID = createUUID(); | |
| 387 | ✗ | } | |
| 388 | |||
| 389 | ✗ | void Attribute_Impl::setValue(const std::string& value) { | |
| 390 | ✗ | if (m_valueType != AttributeValueType::String) { | |
| 391 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not String."); | |
| 392 | } | ||
| 393 | ✗ | m_value = value; | |
| 394 | ✗ | m_versionUUID = createUUID(); | |
| 395 | ✗ | } | |
| 396 | |||
| 397 | 3060 | std::vector<Attribute> Attribute_Impl::valueAsAttributeVector() const { | |
| 398 |
7/8✓ Branch 1 taken 3060 times.
✓ Branch 3 taken 3060 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3060 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 3056 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 3056 times.
|
3060 | if (!hasValue() || m_valueType != AttributeValueType::AttributeVector) { |
| 399 |
27/27✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 30 taken 4 times.
✓ Branch 33 taken 4 times.
✓ Branch 36 taken 4 times.
✓ Branch 42 taken 4 times.
✓ Branch 45 taken 4 times.
✓ Branch 48 taken 4 times.
✓ Branch 51 taken 4 times.
✓ Branch 54 taken 4 times.
✓ Branch 57 taken 4 times.
✓ Branch 60 taken 4 times.
✓ Branch 63 taken 4 times.
✓ Branch 66 taken 4 times.
✓ Branch 69 taken 4 times.
✓ Branch 72 taken 4 times.
✓ Branch 75 taken 4 times.
✓ Branch 78 taken 4 times.
✓ Branch 84 taken 4 times.
✓ Branch 87 taken 4 times.
|
4 | LOG_AND_THROW("Cannot convert attribute '" << name() << "' of type " << valueType().valueDescription() << " to AttributeVector."); |
| 400 | } | ||
| 401 | 3056 | return *(std::get_if<std::vector<Attribute>>(&m_value)); | |
| 402 | } | ||
| 403 | |||
| 404 | 344 | void Attribute_Impl::setValue(const std::vector<Attribute>& value) { | |
| 405 |
2/3✓ Branch 1 taken 344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 344 times.
|
344 | if (m_valueType != AttributeValueType::AttributeVector) { |
| 406 | ✗ | LOG_AND_THROW("Attribute is '" << name() << "' is of type " << valueType().valueDescription() << ", not AttributeVector."); | |
| 407 | } | ||
| 408 | 344 | m_value = value; | |
| 409 | 344 | m_versionUUID = createUUID(); | |
| 410 | 344 | } | |
| 411 | |||
| 412 | struct FindChildByName | ||
| 413 | { | ||
| 414 | 2410 | FindChildByName(const std::string& name) : m_name(name) {} | |
| 415 | |||
| 416 | 5291 | bool operator()(const Attribute& attribute) const { | |
| 417 |
1/1✓ Branch 1 taken 5291 times.
|
5291 | return m_name == attribute.name(); |
| 418 | } | ||
| 419 | |||
| 420 | std::string m_name; | ||
| 421 | }; | ||
| 422 | |||
| 423 | 2410 | boost::optional<Attribute> Attribute_Impl::findChildByName(const std::string& name) const { | |
| 424 | 2410 | boost::optional<Attribute> result; | |
| 425 |
5/8✓ Branch 1 taken 2410 times.
✓ Branch 3 taken 2410 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2410 times.
✓ Branch 9 taken 2410 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2410 times.
✗ Branch 12 not taken.
|
2410 | if (hasValue() && m_valueType == AttributeValueType::AttributeVector) { |
| 426 |
1/1✓ Branch 1 taken 2410 times.
|
2410 | std::vector<Attribute> children = this->valueAsAttributeVector(); |
| 427 |
2/2✓ Branch 1 taken 2410 times.
✓ Branch 6 taken 2410 times.
|
2410 | auto it = std::find_if(children.begin(), children.end(), FindChildByName(name)); |
| 428 |
2/2✓ Branch 2 taken 1141 times.
✓ Branch 3 taken 1269 times.
|
2410 | if (it != children.end()) { |
| 429 |
1/1✓ Branch 2 taken 1141 times.
|
1141 | result = *it; |
| 430 | } | ||
| 431 | 2410 | } | |
| 432 | 2410 | return result; | |
| 433 | ✗ | } | |
| 434 | |||
| 435 | 174 | boost::optional<std::string> Attribute_Impl::units() const { | |
| 436 | 174 | return m_units; | |
| 437 | } | ||
| 438 | |||
| 439 | ✗ | bool Attribute_Impl::setUnits(const std::string& units) { | |
| 440 | ✗ | m_units = units; | |
| 441 | ✗ | m_versionUUID = createUUID(); | |
| 442 | ✗ | return true; | |
| 443 | } | ||
| 444 | |||
| 445 | 77 | std::string Attribute_Impl::toString() const { | |
| 446 |
1/1✓ Branch 1 taken 77 times.
|
77 | std::stringstream ss; |
| 447 | |||
| 448 | // We use std::visit, filtering out the case where it's monostate | ||
| 449 | // Aside from monostate, every possible type is streamable | ||
| 450 | // expect AttributeVector that needs a special treatment | ||
| 451 | //std::visit( | ||
| 452 | //[this, &ss](const auto& val) { | ||
| 453 | //// Needed to properly compare the types | ||
| 454 | //using T = std::remove_cv_t<std::remove_reference_t<decltype(val)>>; | ||
| 455 | |||
| 456 | //// If it's a vector of attributes | ||
| 457 | //if constexpr (std::is_same_v<T, openstudio::Attribute>) { | ||
| 458 | //// Call toXml() and save to the stringstream | ||
| 459 | //this->toXml().save(ss, " "); | ||
| 460 | |||
| 461 | //// Otherwise, if anything else but monostate, it's a simple type | ||
| 462 | //// and we print the value as is | ||
| 463 | //} else if constexpr (!std::is_same_v<T, std::monostate>) { | ||
| 464 | //ss << std::boolalpha << val; | ||
| 465 | //} | ||
| 466 | //}, | ||
| 467 | //this->m_value); | ||
| 468 | |||
| 469 | // Note JM 2019-05-17: std::visit is problematic on mac below 10.14, because it might throw std::bad_variant_access | ||
| 470 | // So we don't use it here. Same with std::get, so we use get_if instead | ||
| 471 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 77 times.
|
77 | if (const auto* p = std::get_if<bool>(&m_value)) { |
| 472 | ✗ | ss << std::boolalpha << *p; | |
| 473 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 2 taken 70 times.
|
77 | } else if (const auto* p = std::get_if<double>(&m_value)) { |
| 474 |
1/1✓ Branch 1 taken 7 times.
|
7 | ss << *p; |
| 475 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
|
70 | } else if (const auto* p = std::get_if<int>(&m_value)) { |
| 476 | ✗ | ss << *p; | |
| 477 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
|
70 | } else if (const auto* p = std::get_if<unsigned>(&m_value)) { |
| 478 | ✗ | ss << *p; | |
| 479 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | } else if (const auto* p = std::get_if<std::string>(&m_value)) { |
| 480 |
1/1✓ Branch 1 taken 70 times.
|
70 | ss << *p; |
| 481 | ✗ | } else if (std::get_if<std::vector<Attribute>>(&m_value)) { | |
| 482 | // Call toXml() and save to the stringstream | ||
| 483 | ✗ | this->toXml().save(ss, " "); | |
| 484 | } | ||
| 485 | |||
| 486 |
1/1✓ Branch 1 taken 77 times.
|
154 | return ss.str(); |
| 487 | 77 | } | |
| 488 | |||
| 489 | 98 | pugi::xml_document Attribute_Impl::toXml() const { // NOLINT(misc-no-recursion) | |
| 490 |
1/1✓ Branch 1 taken 98 times.
|
98 | pugi::xml_document doc; |
| 491 |
1/1✓ Branch 1 taken 98 times.
|
98 | pugi::xml_node element = doc.append_child("Attribute"); |
| 492 |
1/1✓ Branch 1 taken 98 times.
|
98 | this->writeValues(element); |
| 493 | 196 | return doc; | |
| 494 | ✗ | } | |
| 495 | |||
| 496 | 17 | bool Attribute_Impl::operator==(const Attribute& other) const { // NOLINT(misc-no-recursion) | |
| 497 | 17 | bool result = false; | |
| 498 | |||
| 499 |
1/1✓ Branch 1 taken 17 times.
|
17 | AttributeValueType thisValueType = this->valueType(); |
| 500 |
1/1✓ Branch 1 taken 17 times.
|
17 | AttributeValueType otherValueType = other.valueType(); |
| 501 | |||
| 502 | // std::variant operator== will start by comparing indexes (=same type), | ||
| 503 | // and if that works, compares std::get<i>(v) == std::get<i>(w), but that must be returning a type converting to bool | ||
| 504 | // Which is true except for AttributeVector, and probably undefined for std::monostate | ||
| 505 | |||
| 506 | // No need to proceed with value comparison if types aren't the same, | ||
| 507 | // and they must either have both a value or none should have one | ||
| 508 |
7/8✓ Branch 1 taken 14 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 14 times.
✓ Branch 12 taken 3 times.
|
17 | if ((thisValueType == otherValueType) && (this->hasValue() == other.hasValue())) { |
| 509 | |||
| 510 | // If there's a value to compare, let's do this | ||
| 511 |
2/3✓ Branch 1 taken 14 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
|
14 | if (this->hasValue()) { |
| 512 |
3/3✓ Branch 1 taken 14 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 11 times.
|
14 | if (thisValueType == AttributeValueType::AttributeVector) { |
| 513 |
1/1✓ Branch 1 taken 3 times.
|
3 | std::vector<Attribute> thisAttributes = this->valueAsAttributeVector(); |
| 514 |
1/1✓ Branch 1 taken 3 times.
|
3 | std::vector<Attribute> otherAttributes = other.valueAsAttributeVector(); |
| 515 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
|
3 | if (thisAttributes.size() == otherAttributes.size()) { |
| 516 | 1 | result = true; | |
| 517 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | for (unsigned i = 0; i < thisAttributes.size(); ++i) { |
| 518 |
4/7✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
|
1 | if (!(result && (thisAttributes[i] == otherAttributes[i]))) { |
| 519 | ✗ | result = false; | |
| 520 | } | ||
| 521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | if (!result) { |
| 522 | ✗ | break; | |
| 523 | } | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 527 | 3 | } else { | |
| 528 |
1/1✓ Branch 3 taken 11 times.
|
11 | OSAttributeVariant otherValue = other.getImpl<Attribute_Impl>()->m_value; |
| 529 |
1/1✓ Branch 1 taken 11 times.
|
11 | result = (m_value == otherValue); |
| 530 | 11 | } | |
| 531 | } | ||
| 532 | |||
| 533 | // Now we check the units | ||
| 534 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9 times.
|
28 | if (m_units) { |
| 535 |
13/18✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 15 taken 4 times.
✓ Branch 18 taken 3 times.
✓ Branch 19 taken 1 time.
✓ Branch 20 taken 4 times.
✓ Branch 21 taken 1 time.
✓ Branch 23 taken 4 times.
✓ Branch 24 taken 1 time.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
9 | result = result && other.units() && (*m_units == other.units().get()); |
| 536 | } else { | ||
| 537 |
6/9✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
✓ Branch 3 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
9 | result = result && !other.units(); |
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | 17 | return result; | |
| 542 | } | ||
| 543 | |||
| 544 | 98 | void Attribute_Impl::writeValues(pugi::xml_node& element) const { // NOLINT(misc-no-recursion) | |
| 545 |
1/1✓ Branch 1 taken 98 times.
|
98 | pugi::xml_node subElement = element.append_child("UUID"); |
| 546 |
3/3✓ Branch 1 taken 98 times.
✓ Branch 4 taken 98 times.
✓ Branch 8 taken 98 times.
|
98 | subElement.text().set(openstudio::toString(m_uuid).c_str()); |
| 547 | |||
| 548 |
1/1✓ Branch 1 taken 98 times.
|
98 | subElement = element.append_child("VersionUUID"); |
| 549 |
3/3✓ Branch 1 taken 98 times.
✓ Branch 4 taken 98 times.
✓ Branch 8 taken 98 times.
|
98 | subElement.text().set(openstudio::toString(m_versionUUID).c_str()); |
| 550 | |||
| 551 |
1/1✓ Branch 1 taken 98 times.
|
98 | subElement = element.append_child("Name"); |
| 552 |
2/2✓ Branch 1 taken 98 times.
✓ Branch 5 taken 98 times.
|
98 | subElement.text().set(m_name.c_str()); |
| 553 | |||
| 554 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
|
196 | if (m_displayName) { |
| 555 | ✗ | subElement = element.append_child("DisplayName"); | |
| 556 | ✗ | subElement.text().set(m_displayName.get().c_str()); | |
| 557 | } | ||
| 558 | |||
| 559 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 88 times.
|
98 | if (!m_source.empty()) { |
| 560 |
1/1✓ Branch 1 taken 10 times.
|
10 | subElement = element.append_child("Source"); |
| 561 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 5 taken 10 times.
|
10 | subElement.text().set(m_source.c_str()); |
| 562 | } | ||
| 563 | |||
| 564 |
1/1✓ Branch 1 taken 98 times.
|
98 | subElement = element.append_child("ValueType"); |
| 565 |
3/3✓ Branch 1 taken 98 times.
✓ Branch 4 taken 98 times.
✓ Branch 8 taken 98 times.
|
98 | subElement.text().set(m_valueType.valueName().c_str()); |
| 566 | |||
| 567 |
1/1✓ Branch 1 taken 98 times.
|
98 | subElement = element.append_child("Value"); |
| 568 |
7/8✓ Branch 1 taken 98 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 31 times.
✓ Branch 7 taken 26 times.
✓ Branch 8 taken 24 times.
✗ Branch 9 not taken.
|
98 | switch (m_valueType.value()) { |
| 569 | 5 | case AttributeValueType::Boolean: | |
| 570 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
5 | subElement.text().set(this->valueAsBoolean()); |
| 571 | 5 | break; | |
| 572 | 4 | case AttributeValueType::Integer: | |
| 573 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | subElement.text().set(this->valueAsInteger()); |
| 574 | 4 | break; | |
| 575 | 8 | case AttributeValueType::Unsigned: | |
| 576 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
8 | subElement.text().set(this->valueAsUnsigned()); |
| 577 | 8 | break; | |
| 578 | 31 | case AttributeValueType::Double: | |
| 579 |
3/3✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 31 times.
|
31 | subElement.text().set(this->valueAsDouble()); |
| 580 | //temp = boost::regex_replace(openstudio::toString(QString::number(this->valueAsDouble(), | ||
| 581 | //'G', | ||
| 582 | //std::numeric_limits<double>::digits10)), | ||
| 583 | //boost::regex("\\+"),""); | ||
| 584 | 31 | break; | |
| 585 | 26 | case AttributeValueType::String: | |
| 586 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 8 taken 26 times.
|
26 | subElement.text().set(this->valueAsString().c_str()); |
| 587 | 26 | break; | |
| 588 | 24 | case AttributeValueType::AttributeVector: | |
| 589 |
3/3✓ Branch 1 taken 24 times.
✓ Branch 8 taken 85 times.
✓ Branch 9 taken 24 times.
|
109 | for (const Attribute& attribute : this->valueAsAttributeVector()) { |
| 590 | // pugi::xml_node subSubElement = subElement.append_child("Attribute"); | ||
| 591 |
1/1✓ Branch 1 taken 85 times.
|
85 | pugi::xml_document tempdoc = attribute.toXml(); |
| 592 | // Cannot append_move, since this is limited to within the same tree (allow_insert_child wild return false) | ||
| 593 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
|
85 | subElement.append_copy(tempdoc.document_element()); |
| 594 | 109 | } | |
| 595 | 24 | break; | |
| 596 | ✗ | default: | |
| 597 | ✗ | OS_ASSERT(false); | |
| 598 | ✗ | break; | |
| 599 | } | ||
| 600 | |||
| 601 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 77 times.
|
196 | if (m_units) { |
| 602 |
1/1✓ Branch 1 taken 21 times.
|
21 | subElement = element.append_child("Units"); |
| 603 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
|
21 | subElement.text().set(m_units.get().c_str()); |
| 604 | } | ||
| 605 | 98 | } | |
| 606 | |||
| 607 | ✗ | Json::Value Attribute_Impl::toJSON(bool short_version) const { // NOLINT(misc-no-recursion) | |
| 608 | |||
| 609 | ✗ | Json::Value root; | |
| 610 | ✗ | root["name"] = m_name; | |
| 611 | ✗ | if (auto displayName_ = displayName(false)) { | |
| 612 | ✗ | root["display_name"] = std::move(*displayName_); | |
| 613 | ✗ | } | |
| 614 | // root["display_name"] = displayName(true).get(); | ||
| 615 | |||
| 616 | ✗ | if (!short_version) { | |
| 617 | ✗ | root["uuid"] = openstudio::removeBraces(m_uuid); | |
| 618 | ✗ | root["versionuuid"] = openstudio::removeBraces(m_versionUUID); | |
| 619 | |||
| 620 | ✗ | if (!m_source.empty()) { | |
| 621 | ✗ | root["source"] = m_source; | |
| 622 | } | ||
| 623 | } | ||
| 624 | |||
| 625 | // TODO: do we really need the lowercase? | ||
| 626 | // root["datatype"] = ascii_to_lower_copy(m_valueType.valueName()); | ||
| 627 | |||
| 628 | ✗ | if (m_valueType == AttributeValueType::Boolean) { | |
| 629 | ✗ | root["value"] = valueAsBoolean(); | |
| 630 | ✗ | root["datatype"] = "boolean"; | |
| 631 | ✗ | } else if (m_valueType == AttributeValueType::Double) { | |
| 632 | ✗ | root["value"] = valueAsDouble(); | |
| 633 | ✗ | root["datatype"] = "float"; | |
| 634 | ✗ | } else if (m_valueType == AttributeValueType::Integer) { | |
| 635 | ✗ | root["value"] = valueAsInteger(); | |
| 636 | ✗ | root["datatype"] = "integer"; | |
| 637 | ✗ | } else if (m_valueType == AttributeValueType::Unsigned) { | |
| 638 | ✗ | root["value"] = valueAsUnsigned(); | |
| 639 | ✗ | root["datatype"] = "unsigned"; | |
| 640 | ✗ | } else if (m_valueType == AttributeValueType::String) { | |
| 641 | ✗ | root["value"] = valueAsString(); | |
| 642 | ✗ | root["datatype"] = "string"; | |
| 643 | ✗ | } else if (m_valueType == AttributeValueType::AttributeVector) { | |
| 644 | ✗ | auto& subElement = root["value"]; | |
| 645 | ✗ | root["datatype"] = "attributevector"; | |
| 646 | ✗ | for (const Attribute& attribute : this->valueAsAttributeVector()) { | |
| 647 | ✗ | subElement.append(attribute.toJSON()); | |
| 648 | ✗ | } | |
| 649 | } else { | ||
| 650 | ✗ | OS_ASSERT(false); | |
| 651 | } | ||
| 652 | |||
| 653 | ✗ | if (m_units) { | |
| 654 | ✗ | root["units"] = *m_units; | |
| 655 | } | ||
| 656 | ✗ | return root; | |
| 657 | ✗ | } | |
| 658 | |||
| 659 | // helper constant for the visitor below so we static assert we didn't miss a type | ||
| 660 | template <class> | ||
| 661 | inline constexpr bool always_false_v = false; | ||
| 662 | |||
| 663 | #if 0 | ||
| 664 | // helper type for visitor | ||
| 665 | template <class... Ts> | ||
| 666 | struct overloaded : Ts... | ||
| 667 | { | ||
| 668 | using Ts::operator()...; | ||
| 669 | }; | ||
| 670 | // explicit deduction guide (not needed as of C++20) | ||
| 671 | template <class... Ts> | ||
| 672 | overloaded(Ts...) -> overloaded<Ts...>; | ||
| 673 | |||
| 674 | Json::Value Attribute_Impl::valueAsJSON() const { | ||
| 675 | return std::visit(overloaded{// | ||
| 676 | [](std::monostate) { return Json::Value{Json::nullValue}; }, | ||
| 677 | [](const std::vector<Attribute>& arg) { | ||
| 678 | Json::Value subElement(Json::arrayValue); | ||
| 679 | for (const Attribute& attribute : arg) { | ||
| 680 | subElement.append(attribute.toJSON()); | ||
| 681 | } | ||
| 682 | return subElement; | ||
| 683 | }, | ||
| 684 | [](auto arg) { return Json::Value(arg); }}, | ||
| 685 | m_value); | ||
| 686 | } | ||
| 687 | #endif | ||
| 688 | |||
| 689 | 9 | Json::Value Attribute_Impl::valueAsJSON() const { // NOLINT(misc-no-recursion) | |
| 690 | return std::visit( | ||
| 691 | 9 | [](auto&& arg) -> Json::Value { | |
| 692 | using T = std::decay_t<decltype(arg)>; | ||
| 693 | if constexpr (std::is_same_v<T, std::monostate>) { | ||
| 694 | ✗ | return Json::nullValue; | |
| 695 | } else if constexpr (std::is_same_v<T, bool>) { // NOLINT(bugprone-branch-clone) | ||
| 696 | 2 | return arg; | |
| 697 | } else if constexpr (std::is_same_v<T, double>) { | ||
| 698 | 3 | return arg; | |
| 699 | } else if constexpr (std::is_same_v<T, int>) { | ||
| 700 | 1 | return arg; | |
| 701 | // cppcheck-suppress identicalConditionAfterEarlyExit | ||
| 702 | // cppcheck-suppress multiCondition | ||
| 703 | } else if constexpr (std::is_same_v<T, unsigned int>) { | ||
| 704 | 1 | return arg; | |
| 705 | } else if constexpr (std::is_same_v<T, std::string>) { | ||
| 706 | 1 | return arg; | |
| 707 | } else if constexpr (std::is_same_v<T, std::vector<Attribute>>) { | ||
| 708 |
1/1✓ Branch 1 taken 1 time.
|
1 | Json::Value subElement(Json::arrayValue); |
| 709 |
2/2✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 time.
|
3 | for (const Attribute& attribute : arg) { |
| 710 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | subElement.append(attribute.valueAsJSON()); |
| 711 | } | ||
| 712 | 2 | return subElement; | |
| 713 | 1 | } else { | |
| 714 | static_assert(always_false_v<T>, "non-exhaustive visitor!"); | ||
| 715 | } | ||
| 716 | }, | ||
| 717 |
1/1✓ Branch 1 taken 9 times.
|
18 | m_value); |
| 718 | } | ||
| 719 | |||
| 720 | } // namespace detail | ||
| 721 | |||
| 722 | // For debug purposes only | ||
| 723 | ✗ | std::ostream& operator<<(std::ostream& os, const OSAttributeVariant& attributeVariant) { | |
| 724 | |||
| 725 | // We use std::visit, filtering out the case where it's monostate | ||
| 726 | // Aside from monostate, every possible type is streamable | ||
| 727 | // expect AttributeVector that needs a special treatment | ||
| 728 | //std::visit( | ||
| 729 | //[&os](const auto& val) { | ||
| 730 | //// Needed to properly compare the types | ||
| 731 | //using T = std::remove_cv_t<std::remove_reference_t<decltype(val)> >; | ||
| 732 | |||
| 733 | //// If it's a vector of attributes | ||
| 734 | //if constexpr (std::is_same_v<T, std::vector<openstudio::Attribute>>) { | ||
| 735 | //// Will end up calling toXml | ||
| 736 | //os << val; | ||
| 737 | //// Otherwise, if anything else but monostate | ||
| 738 | //} else if constexpr (!std::is_same_v<T, std::monostate>) { | ||
| 739 | //os << std::boolalpha << val; | ||
| 740 | //} | ||
| 741 | //}, | ||
| 742 | //attributeVariant); | ||
| 743 | |||
| 744 | // Note JM 2019-05-17: std::visit is problematic on mac below 10.14, because it might throw std::bad_variant_access | ||
| 745 | // So we don't use it here. Same with std::get, so we use get_if instead | ||
| 746 | ✗ | if (const auto* p = std::get_if<bool>(&attributeVariant)) { | |
| 747 | ✗ | os << std::boolalpha << *p; | |
| 748 | ✗ | } else if (const auto* p = std::get_if<double>(&attributeVariant)) { | |
| 749 | ✗ | os << *p; | |
| 750 | ✗ | } else if (const auto* p = std::get_if<int>(&attributeVariant)) { | |
| 751 | ✗ | os << *p; | |
| 752 | ✗ | } else if (const auto* p = std::get_if<unsigned>(&attributeVariant)) { | |
| 753 | ✗ | os << *p; | |
| 754 | ✗ | } else if (const auto* p = std::get_if<std::string>(&attributeVariant)) { | |
| 755 | ✗ | os << *p; | |
| 756 | ✗ | } else if (const auto* p = std::get_if<std::vector<Attribute>>(&attributeVariant)) { | |
| 757 | // Will end up calling toXml | ||
| 758 | ✗ | for (const Attribute& attr : *p) { | |
| 759 | ✗ | os << attr << '\n'; | |
| 760 | } | ||
| 761 | } | ||
| 762 | |||
| 763 | ✗ | return os; | |
| 764 | } | ||
| 765 | |||
| 766 | ✗ | AttributeDescription::AttributeDescription(const std::string& t_name, const std::string& t_displayName, const std::string& t_description, | |
| 767 | ✗ | const AttributeValueType& t_validValueType, bool t_required) | |
| 768 | ✗ | : name(t_name), displayName(t_displayName), description(t_description), validValueTypes(1u, t_validValueType), required(t_required) {} | |
| 769 | |||
| 770 | ✗ | AttributeDescription::AttributeDescription(const std::string& t_name, const std::string& t_displayName, const std::string& t_description, | |
| 771 | ✗ | const AttributeValueType& t_validValueType, bool t_required, OSAttributeVariant t_defaultValue) | |
| 772 | ✗ | : name(t_name), | |
| 773 | ✗ | displayName(t_displayName), | |
| 774 | ✗ | description(t_description), | |
| 775 | ✗ | validValueTypes(1u, t_validValueType), | |
| 776 | ✗ | required(t_required), | |
| 777 | ✗ | defaultValue(t_defaultValue) {} | |
| 778 | |||
| 779 | ✗ | AttributeDescription::AttributeDescription(const std::string& t_name, const std::string& t_displayName, const std::string& t_description, | |
| 780 | ✗ | const std::vector<AttributeValueType>& t_validValueTypes, bool t_required) | |
| 781 | ✗ | : name(t_name), displayName(t_displayName), description(t_description), validValueTypes(t_validValueTypes), required(t_required) {} | |
| 782 | |||
| 783 | ✗ | AttributeDescription::AttributeDescription(const std::string& t_name, const std::string& t_displayName, const std::string& t_description, | |
| 784 | const std::vector<AttributeValueType>& t_validValueTypes, bool t_required, | ||
| 785 | ✗ | OSAttributeVariant t_defaultValue) | |
| 786 | ✗ | : name(t_name), | |
| 787 | ✗ | displayName(t_displayName), | |
| 788 | ✗ | description(t_description), | |
| 789 | ✗ | validValueTypes(t_validValueTypes), | |
| 790 | ✗ | required(t_required), | |
| 791 | ✗ | defaultValue(t_defaultValue) {} | |
| 792 | |||
| 793 | 488 | Attribute::Attribute(const std::string& name, bool value) | |
| 794 |
2/4✓ Branch 3 taken 488 times.
✓ Branch 6 taken 488 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
488 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 795 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 488 times.
✗ Branch 4 not taken.
|
488 | OS_ASSERT(m_impl); |
| 796 | 488 | } | |
| 797 | 3 | Attribute::Attribute(const std::string& name, bool value, const std::string& units) | |
| 798 |
3/5✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
3 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 799 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
|
3 | OS_ASSERT(m_impl); |
| 800 | 3 | } | |
| 801 | ✗ | Attribute::Attribute(const std::string& name, bool value, const boost::optional<std::string>& units) | |
| 802 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 803 | ✗ | OS_ASSERT(m_impl); | |
| 804 | ✗ | } | |
| 805 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 806 | const boost::optional<std::string>& displayName, bool value, const boost::optional<std::string>& units, | ||
| 807 | ✗ | const std::string& source) | |
| 808 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 809 | ✗ | OS_ASSERT(m_impl); | |
| 810 | ✗ | } | |
| 811 | |||
| 812 | 393 | Attribute::Attribute(const std::string& name, double value) | |
| 813 |
2/4✓ Branch 3 taken 393 times.
✓ Branch 6 taken 393 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
393 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 814 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
✗ Branch 4 not taken.
|
393 | OS_ASSERT(m_impl); |
| 815 | 393 | } | |
| 816 | 180 | Attribute::Attribute(const std::string& name, double value, const std::string& units) | |
| 817 |
3/5✓ Branch 2 taken 180 times.
✓ Branch 5 taken 180 times.
✓ Branch 8 taken 180 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
180 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 818 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
✗ Branch 4 not taken.
|
180 | OS_ASSERT(m_impl); |
| 819 | 180 | } | |
| 820 | 2 | Attribute::Attribute(const std::string& name, double value, const boost::optional<std::string>& units) | |
| 821 |
2/4✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
2 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 822 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(m_impl); |
| 823 | 2 | } | |
| 824 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 825 | const boost::optional<std::string>& displayName, double value, const boost::optional<std::string>& units, | ||
| 826 | ✗ | const std::string& source) | |
| 827 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 828 | ✗ | OS_ASSERT(m_impl); | |
| 829 | ✗ | } | |
| 830 | |||
| 831 | 17 | Attribute::Attribute(const std::string& name, int value) | |
| 832 |
2/4✓ Branch 3 taken 17 times.
✓ Branch 6 taken 17 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
17 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 833 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 4 not taken.
|
17 | OS_ASSERT(m_impl); |
| 834 | 17 | } | |
| 835 | 2 | Attribute::Attribute(const std::string& name, int value, const std::string& units) | |
| 836 |
3/5✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
2 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 837 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(m_impl); |
| 838 | 2 | } | |
| 839 | ✗ | Attribute::Attribute(const std::string& name, int value, const boost::optional<std::string>& units) | |
| 840 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 841 | ✗ | OS_ASSERT(m_impl); | |
| 842 | ✗ | } | |
| 843 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 844 | ✗ | const boost::optional<std::string>& displayName, int value, const boost::optional<std::string>& units, const std::string& source) | |
| 845 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 846 | ✗ | OS_ASSERT(m_impl); | |
| 847 | ✗ | } | |
| 848 | |||
| 849 | 9 | Attribute::Attribute(const std::string& name, unsigned value) | |
| 850 |
2/4✓ Branch 3 taken 9 times.
✓ Branch 6 taken 9 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
9 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 851 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
|
9 | OS_ASSERT(m_impl); |
| 852 | 9 | } | |
| 853 | 4 | Attribute::Attribute(const std::string& name, unsigned value, const std::string& units) | |
| 854 |
3/5✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
4 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 855 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
|
4 | OS_ASSERT(m_impl); |
| 856 | 4 | } | |
| 857 | ✗ | Attribute::Attribute(const std::string& name, unsigned value, const boost::optional<std::string>& units) | |
| 858 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 859 | ✗ | OS_ASSERT(m_impl); | |
| 860 | ✗ | } | |
| 861 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 862 | const boost::optional<std::string>& displayName, unsigned value, const boost::optional<std::string>& units, | ||
| 863 | ✗ | const std::string& source) | |
| 864 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 865 | ✗ | OS_ASSERT(m_impl); | |
| 866 | ✗ | } | |
| 867 | |||
| 868 | 7 | Attribute::Attribute(const std::string& name, const char* value) | |
| 869 |
3/5✓ Branch 3 taken 7 times.
✓ Branch 6 taken 7 times.
✓ Branch 9 taken 7 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
21 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, std::string(value), boost::none))) { |
| 870 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 4 not taken.
|
7 | OS_ASSERT(m_impl); |
| 871 | 7 | } | |
| 872 | ✗ | Attribute::Attribute(const std::string& name, const char* value, const std::string& units) | |
| 873 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, std::string(value), units))) { | |
| 874 | ✗ | OS_ASSERT(m_impl); | |
| 875 | ✗ | } | |
| 876 | ✗ | Attribute::Attribute(const std::string& name, const char* value, const boost::optional<std::string>& units) | |
| 877 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, std::string(value), units))) { | |
| 878 | ✗ | OS_ASSERT(m_impl); | |
| 879 | ✗ | } | |
| 880 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 881 | const boost::optional<std::string>& displayName, const char* value, const boost::optional<std::string>& units, | ||
| 882 | ✗ | const std::string& source) | |
| 883 | ✗ | : m_impl( | |
| 884 | ✗ | std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, std::string(value), units, source))) { | |
| 885 | ✗ | OS_ASSERT(m_impl); | |
| 886 | ✗ | } | |
| 887 | |||
| 888 | 1781 | Attribute::Attribute(const std::string& name, const std::string& value) | |
| 889 |
2/4✓ Branch 3 taken 1781 times.
✓ Branch 6 taken 1781 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
1781 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 890 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1781 times.
✗ Branch 4 not taken.
|
1781 | OS_ASSERT(m_impl); |
| 891 | 1781 | } | |
| 892 | ✗ | Attribute::Attribute(const std::string& name, const std::string& value, const std::string& units) | |
| 893 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 894 | ✗ | OS_ASSERT(m_impl); | |
| 895 | ✗ | } | |
| 896 | ✗ | Attribute::Attribute(const std::string& name, const std::string& value, const boost::optional<std::string>& units) | |
| 897 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 898 | ✗ | OS_ASSERT(m_impl); | |
| 899 | ✗ | } | |
| 900 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 901 | const boost::optional<std::string>& displayName, const std::string& value, const boost::optional<std::string>& units, | ||
| 902 | ✗ | const std::string& source) | |
| 903 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 904 | ✗ | OS_ASSERT(m_impl); | |
| 905 | ✗ | } | |
| 906 | |||
| 907 | 192 | Attribute::Attribute(const std::string& name, const std::vector<openstudio::Attribute>& value) | |
| 908 |
2/4✓ Branch 3 taken 192 times.
✓ Branch 6 taken 192 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
192 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, boost::none))) { |
| 909 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 4 not taken.
|
192 | OS_ASSERT(m_impl); |
| 910 | 192 | } | |
| 911 | ✗ | Attribute::Attribute(const std::string& name, const std::vector<openstudio::Attribute>& value, const std::string& units) | |
| 912 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { | |
| 913 | ✗ | OS_ASSERT(m_impl); | |
| 914 | ✗ | } | |
| 915 | 22 | Attribute::Attribute(const std::string& name, const std::vector<openstudio::Attribute>& value, const boost::optional<std::string>& units) | |
| 916 |
2/4✓ Branch 2 taken 22 times.
✓ Branch 5 taken 22 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
22 | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(name, value, units))) { |
| 917 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 4 not taken.
|
22 | OS_ASSERT(m_impl); |
| 918 | 22 | } | |
| 919 | ✗ | Attribute::Attribute(const openstudio::UUID& uuid, const openstudio::UUID& versionUUID, const std::string& name, | |
| 920 | const boost::optional<std::string>& displayName, const std::vector<openstudio::Attribute>& value, | ||
| 921 | ✗ | const boost::optional<std::string>& units, const std::string& source) | |
| 922 | ✗ | : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(uuid, versionUUID, name, displayName, value, units, source))) { | |
| 923 | ✗ | OS_ASSERT(m_impl); | |
| 924 | ✗ | } | |
| 925 | |||
| 926 |
3/4✓ Branch 2 taken 99 times.
✓ Branch 5 taken 99 times.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
|
106 | Attribute::Attribute(const pugi::xml_node& element) : m_impl(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(element))) { |
| 927 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 4 not taken.
|
99 | OS_ASSERT(m_impl); |
| 928 | 99 | } | |
| 929 | |||
| 930 | 26161 | Attribute::Attribute(const Attribute& other) : m_impl(other.m_impl) { | |
| 931 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 26161 times.
✗ Branch 4 not taken.
|
26161 | OS_ASSERT(m_impl); |
| 932 | 26161 | } | |
| 933 | |||
| 934 | ✗ | Attribute Attribute::clone() const { | |
| 935 | ✗ | Attribute result(std::shared_ptr<detail::Attribute_Impl>(new detail::Attribute_Impl(*m_impl))); | |
| 936 | ✗ | return result; | |
| 937 | } | ||
| 938 | |||
| 939 | ✗ | Attribute::Attribute(const std::shared_ptr<detail::Attribute_Impl>& impl) : m_impl(impl) { | |
| 940 | ✗ | OS_ASSERT(m_impl); | |
| 941 | ✗ | } | |
| 942 | |||
| 943 | 13 | boost::optional<Attribute> Attribute::loadFromXml(const openstudio::path& xmlPath) { | |
| 944 | 13 | boost::optional<Attribute> result; | |
| 945 | |||
| 946 |
2/3✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
|
13 | if (!openstudio::filesystem::exists(xmlPath)) { |
| 947 | ✗ | LOG(Error, "'" << xmlPath << "' does not exist."); | |
| 948 | ✗ | return result; | |
| 949 | } | ||
| 950 | |||
| 951 |
2/3✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
|
13 | if (!openstudio::filesystem::is_regular_file(xmlPath)) { |
| 952 | ✗ | LOG(Error, "'" << xmlPath << "' cannot be opened for reading Attribute XML data."); | |
| 953 | ✗ | return result; | |
| 954 | } | ||
| 955 | |||
| 956 |
1/1✓ Branch 1 taken 13 times.
|
13 | pugi::xml_document attributeXML; |
| 957 | |||
| 958 |
1/1✓ Branch 1 taken 13 times.
|
13 | openstudio::filesystem::ifstream file(xmlPath, std::ios_base::binary); |
| 959 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | if (file.is_open()) { |
| 960 |
1/1✓ Branch 1 taken 13 times.
|
13 | auto success = attributeXML.load(file); |
| 961 |
2/3✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
|
13 | if (!success) { |
| 962 | ✗ | LOG(Error, "'" << xmlPath << "' could not be read as XML data"); | |
| 963 | ✗ | return result; | |
| 964 | } | ||
| 965 |
1/1✓ Branch 1 taken 13 times.
|
13 | file.close(); |
| 966 | } else { | ||
| 967 | ✗ | file.close(); | |
| 968 | ✗ | LOG(Error, "'" << xmlPath << "' could not be opened"); | |
| 969 | ✗ | return result; | |
| 970 | } | ||
| 971 | |||
| 972 | try { | ||
| 973 |
3/3✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
|
13 | result = Attribute(attributeXML.child("Attribute")); |
| 974 | ✗ | } catch (const std::exception&) { | |
| 975 | // Output any other handled error's message to the user | ||
| 976 | // LOG(Error, "Cannot create attribute from XML: " << e.what()); | ||
| 977 | ✗ | } | |
| 978 | |||
| 979 | 13 | return result; | |
| 980 | 13 | } | |
| 981 | |||
| 982 | ✗ | openstudio::UUID Attribute::uuid() const { | |
| 983 | ✗ | return m_impl->uuid(); | |
| 984 | } | ||
| 985 | |||
| 986 | ✗ | openstudio::UUID Attribute::versionUUID() const { | |
| 987 | ✗ | return m_impl->versionUUID(); | |
| 988 | } | ||
| 989 | |||
| 990 | 11742 | std::string Attribute::name() const { | |
| 991 | 11742 | return m_impl->name(); | |
| 992 | } | ||
| 993 | |||
| 994 | 19 | boost::optional<std::string> Attribute::displayName(bool returnName) const { | |
| 995 | 19 | return m_impl->displayName(returnName); | |
| 996 | } | ||
| 997 | |||
| 998 | 9 | bool Attribute::setDisplayName(const std::string& displayName) { | |
| 999 | 9 | return m_impl->setDisplayName(displayName); | |
| 1000 | } | ||
| 1001 | |||
| 1002 | ✗ | void Attribute::clearDisplayName() { | |
| 1003 | ✗ | m_impl->clearDisplayName(); | |
| 1004 | ✗ | } | |
| 1005 | |||
| 1006 | 16 | std::string Attribute::source() const { | |
| 1007 | 16 | return m_impl->source(); | |
| 1008 | } | ||
| 1009 | |||
| 1010 | 6 | void Attribute::setSource(const std::string& source) { | |
| 1011 | 6 | m_impl->setSource(source); | |
| 1012 | 6 | } | |
| 1013 | |||
| 1014 | ✗ | void Attribute::clearSource() { | |
| 1015 | ✗ | m_impl->clearSource(); | |
| 1016 | ✗ | } | |
| 1017 | |||
| 1018 | 1065 | AttributeValueType Attribute::valueType() const { | |
| 1019 | 1065 | return m_impl->valueType(); | |
| 1020 | } | ||
| 1021 | |||
| 1022 | 14 | bool Attribute::hasValue() const { | |
| 1023 | 14 | return m_impl->hasValue(); | |
| 1024 | } | ||
| 1025 | |||
| 1026 | 10 | bool Attribute::valueAsBoolean() const { | |
| 1027 | 10 | return m_impl->valueAsBoolean(); | |
| 1028 | } | ||
| 1029 | |||
| 1030 | ✗ | void Attribute::setValue(bool value) { | |
| 1031 | ✗ | m_impl->setValue(value); | |
| 1032 | ✗ | } | |
| 1033 | |||
| 1034 | 9 | int Attribute::valueAsInteger() const { | |
| 1035 | 9 | return m_impl->valueAsInteger(); | |
| 1036 | } | ||
| 1037 | |||
| 1038 | ✗ | void Attribute::setValue(int value) { | |
| 1039 | ✗ | m_impl->setValue(value); | |
| 1040 | ✗ | } | |
| 1041 | |||
| 1042 | 8 | unsigned Attribute::valueAsUnsigned() const { | |
| 1043 | 8 | return m_impl->valueAsUnsigned(); | |
| 1044 | } | ||
| 1045 | |||
| 1046 | ✗ | void Attribute::setValue(unsigned value) { | |
| 1047 | ✗ | m_impl->setValue(value); | |
| 1048 | ✗ | } | |
| 1049 | |||
| 1050 | 263 | double Attribute::valueAsDouble() const { | |
| 1051 | 263 | return m_impl->valueAsDouble(); | |
| 1052 | } | ||
| 1053 | |||
| 1054 | ✗ | void Attribute::setValue(double value) { | |
| 1055 | ✗ | m_impl->setValue(value); | |
| 1056 | ✗ | } | |
| 1057 | |||
| 1058 | 918 | std::string Attribute::valueAsString() const { | |
| 1059 | 918 | return m_impl->valueAsString(); | |
| 1060 | } | ||
| 1061 | |||
| 1062 | ✗ | void Attribute::setValue(const char* value) { | |
| 1063 | ✗ | m_impl->setValue(value); | |
| 1064 | ✗ | } | |
| 1065 | |||
| 1066 | ✗ | void Attribute::setValue(const std::string& value) { | |
| 1067 | ✗ | m_impl->setValue(value); | |
| 1068 | ✗ | } | |
| 1069 | |||
| 1070 | 623 | std::vector<Attribute> Attribute::valueAsAttributeVector() const { | |
| 1071 | 623 | return m_impl->valueAsAttributeVector(); | |
| 1072 | } | ||
| 1073 | |||
| 1074 | 344 | void Attribute::setValue(const std::vector<Attribute>& value) { | |
| 1075 | 344 | m_impl->setValue(value); | |
| 1076 | 344 | } | |
| 1077 | |||
| 1078 | 2410 | boost::optional<Attribute> Attribute::findChildByName(const std::string& name) const { | |
| 1079 | 2410 | return m_impl->findChildByName(name); | |
| 1080 | } | ||
| 1081 | |||
| 1082 | 174 | boost::optional<std::string> Attribute::units() const { | |
| 1083 | 174 | return m_impl->units(); | |
| 1084 | } | ||
| 1085 | |||
| 1086 | ✗ | bool Attribute::setUnits(const std::string& units) { | |
| 1087 | ✗ | return m_impl->setUnits(units); | |
| 1088 | } | ||
| 1089 | |||
| 1090 | 77 | std::string Attribute::toString() const { | |
| 1091 | 77 | return m_impl->toString(); | |
| 1092 | } | ||
| 1093 | |||
| 1094 | // Protected | ||
| 1095 | 98 | pugi::xml_document Attribute::toXml() const { // NOLINT(misc-no-recursion) | |
| 1096 | 98 | return m_impl->toXml(); | |
| 1097 | } | ||
| 1098 | |||
| 1099 | ✗ | Json::Value Attribute::toJSON(bool short_version) const { // NOLINT(misc-no-recursion) | |
| 1100 | ✗ | return m_impl->toJSON(short_version); | |
| 1101 | } | ||
| 1102 | |||
| 1103 | ✗ | std::string Attribute::toJSONString() const { | |
| 1104 | ✗ | return toJSON().toStyledString(); | |
| 1105 | } | ||
| 1106 | |||
| 1107 | 9 | Json::Value Attribute::valueAsJSON() const { | |
| 1108 | 9 | return m_impl->valueAsJSON(); | |
| 1109 | } | ||
| 1110 | |||
| 1111 | 13 | bool Attribute::saveToXml(const openstudio::path& path) const { | |
| 1112 | 13 | bool result = false; | |
| 1113 | |||
| 1114 | try { | ||
| 1115 |
1/1✓ Branch 1 taken 13 times.
|
13 | openstudio::filesystem::ofstream file(path); |
| 1116 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | this->toXml().save(file, " "); |
| 1117 |
1/1✓ Branch 1 taken 13 times.
|
13 | file.close(); |
| 1118 | 13 | result = true; | |
| 1119 |
0/2✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
13 | } catch (const std::exception& e) { |
| 1120 | ✗ | LOG_FREE(Error, "openstudio.Attribute", "Error saving to XML: " << e.what()); | |
| 1121 | ✗ | } | |
| 1122 | |||
| 1123 | 13 | return result; | |
| 1124 | } | ||
| 1125 | |||
| 1126 | 17 | bool Attribute::operator==(const Attribute& other) const { // NOLINT(misc-no-recursion) | |
| 1127 | 17 | return m_impl->operator==(other); | |
| 1128 | } | ||
| 1129 | |||
| 1130 | ✗ | std::ostream& operator<<(std::ostream& os, const Attribute& attribute) { | |
| 1131 | ✗ | pugi::xml_document doc = attribute.toXml(); | |
| 1132 | ✗ | doc.save(os, " "); | |
| 1133 | ✗ | return os; | |
| 1134 | ✗ | } | |
| 1135 | |||
| 1136 | ✗ | Attribute createAttributeFromVector(const std::string& name, const std::vector<int>& value) { | |
| 1137 | ✗ | AttributeVector valueAsAttributes; | |
| 1138 | ✗ | valueAsAttributes.reserve(value.size()); | |
| 1139 | ✗ | for (int v : value) { | |
| 1140 | ✗ | valueAsAttributes.emplace_back(std::string(), v); | |
| 1141 | } | ||
| 1142 | ✗ | return Attribute(name, valueAsAttributes); | |
| 1143 | ✗ | } | |
| 1144 | |||
| 1145 | ✗ | Attribute createAttributeFromVector(const std::string& name, const std::vector<double>& value) { | |
| 1146 | ✗ | AttributeVector valueAsAttributes; | |
| 1147 | ✗ | valueAsAttributes.reserve(value.size()); | |
| 1148 | ✗ | for (double v : value) { | |
| 1149 | ✗ | valueAsAttributes.emplace_back(std::string(), v); | |
| 1150 | } | ||
| 1151 | ✗ | return Attribute(name, valueAsAttributes); | |
| 1152 | ✗ | } | |
| 1153 | |||
| 1154 | ✗ | std::vector<int> getIntVectorFromAttribute(const Attribute& attribute) { | |
| 1155 | ✗ | IntVector result; | |
| 1156 | ✗ | if (attribute.valueType() != AttributeValueType::AttributeVector) { | |
| 1157 | ✗ | LOG_FREE_AND_THROW("openstudio.Attribute", "Attribute must be of type AttributeVector for this function to be applicable."); | |
| 1158 | } | ||
| 1159 | ✗ | AttributeVector attributes = attribute.valueAsAttributeVector(); | |
| 1160 | ✗ | for (const Attribute& a : attributes) { | |
| 1161 | ✗ | result.push_back(a.valueAsInteger()); | |
| 1162 | } | ||
| 1163 | ✗ | return result; | |
| 1164 | ✗ | } | |
| 1165 | |||
| 1166 | ✗ | std::vector<double> getDoubleVectorFromAttribute(const Attribute& attribute) { | |
| 1167 | ✗ | DoubleVector result; | |
| 1168 | ✗ | if (attribute.valueType() != AttributeValueType::AttributeVector) { | |
| 1169 | ✗ | LOG_FREE_AND_THROW("openstudio.Attribute", "Attribute must be of type AttributeVector for this function to be applicable."); | |
| 1170 | } | ||
| 1171 | ✗ | AttributeVector attributes = attribute.valueAsAttributeVector(); | |
| 1172 | ✗ | for (const Attribute& a : attributes) { | |
| 1173 | ✗ | result.push_back(a.valueAsDouble()); | |
| 1174 | } | ||
| 1175 | ✗ | return result; | |
| 1176 | ✗ | } | |
| 1177 | |||
| 1178 | } // namespace openstudio | ||
| 1179 |