MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / toJSON

Method toJSON

src/utilities/data/Attribute.cpp:607–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605 }
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>

Callers 1

valueAsJSONMethod · 0.45

Calls 3

removeBracesFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected