src/model/ExternalInterfaceVariable.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 "ExternalInterfaceVariable.hpp" | ||
| 7 | #include "ExternalInterfaceVariable_Impl.hpp" | ||
| 8 | |||
| 9 | #include <utilities/idd/IddEnums.hxx> | ||
| 10 | #include <utilities/idd/OS_ExternalInterface_Variable_FieldEnums.hxx> | ||
| 11 | |||
| 12 | #include "../utilities/units/Unit.hpp" | ||
| 13 | |||
| 14 | #include "../utilities/core/Assert.hpp" | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | namespace model { | ||
| 18 | |||
| 19 | namespace detail { | ||
| 20 | |||
| 21 | 2 | ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 22 | 2 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 23 |
4/6✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
|
2 | OS_ASSERT(idfObject.iddObject().type() == ExternalInterfaceVariable::iddObjectType()); |
| 24 | 2 | } | |
| 25 | |||
| 26 | ✗ | ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, | |
| 27 | ✗ | bool keepHandle) | |
| 28 | ✗ | : ModelObject_Impl(other, model, keepHandle) { | |
| 29 | ✗ | OS_ASSERT(other.iddObject().type() == ExternalInterfaceVariable::iddObjectType()); | |
| 30 | ✗ | } | |
| 31 | |||
| 32 | 1 | ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const ExternalInterfaceVariable_Impl& other, Model_Impl* model, bool keepHandle) | |
| 33 | 1 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 34 | |||
| 35 | ✗ | const std::vector<std::string>& ExternalInterfaceVariable_Impl::outputVariableNames() const { | |
| 36 | ✗ | static const std::vector<std::string> result; | |
| 37 | ✗ | return result; | |
| 38 | } | ||
| 39 | |||
| 40 | ✗ | IddObjectType ExternalInterfaceVariable_Impl::iddObjectType() const { | |
| 41 | ✗ | return ExternalInterfaceVariable::iddObjectType(); | |
| 42 | } | ||
| 43 | |||
| 44 | 3 | double ExternalInterfaceVariable_Impl::initialValue() const { | |
| 45 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<double> value = getDouble(OS_ExternalInterface_VariableFields::InitialValue, true); |
| 46 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (value) { |
| 47 |
1/1✓ Branch 1 taken 3 times.
|
3 | return value.get(); |
| 48 | } | ||
| 49 | ✗ | return -9999; | |
| 50 | } | ||
| 51 | |||
| 52 | 3 | bool ExternalInterfaceVariable_Impl::setInitialValue(double initialValue) { | |
| 53 | 3 | bool result = setDouble(OS_ExternalInterface_VariableFields::InitialValue, initialValue); | |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | OS_ASSERT(result); |
| 55 | 3 | return result; | |
| 56 | } | ||
| 57 | |||
| 58 | 3 | bool ExternalInterfaceVariable_Impl::exportToBCVTB() const { | |
| 59 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<std::string> value = getString(OS_ExternalInterface_VariableFields::ExportToBCVTB, true); |
| 60 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
|
3 | OS_ASSERT(value); |
| 61 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
6 | return openstudio::istringEqual(value.get(), "True"); |
| 62 | 3 | } | |
| 63 | |||
| 64 | 1 | bool ExternalInterfaceVariable_Impl::isExportToBCVTBDefaulted() const { | |
| 65 | 1 | return isEmpty(OS_ExternalInterface_VariableFields::ExportToBCVTB); | |
| 66 | } | ||
| 67 | |||
| 68 | 1 | bool ExternalInterfaceVariable_Impl::setExportToBCVTB(bool exportToBCVTB) { | |
| 69 | 1 | bool result = false; | |
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | if (exportToBCVTB) { |
| 71 | ✗ | result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, "True"); | |
| 72 | } else { | ||
| 73 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
3 | result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, "False"); |
| 74 | } | ||
| 75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 76 | 1 | return result; | |
| 77 | } | ||
| 78 | |||
| 79 | 1 | void ExternalInterfaceVariable_Impl::resetExportToBCVTB() { | |
| 80 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | bool result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, ""); |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 82 | 1 | } | |
| 83 | |||
| 84 | } // namespace detail | ||
| 85 | |||
| 86 | 2 | ExternalInterfaceVariable::ExternalInterfaceVariable(const Model& model, const std::string& variableName, double initialValue) | |
| 87 | 2 | : ModelObject(ExternalInterfaceVariable::iddObjectType(), model) { | |
| 88 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 5 not taken.
|
2 | OS_ASSERT(getImpl<detail::ExternalInterfaceVariable_Impl>()); |
| 89 |
1/1✓ Branch 3 taken 2 times.
|
2 | bool ok = getImpl<detail::ExternalInterfaceVariable_Impl>()->setName(variableName).has_value(); |
| 90 |
5/11✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
2 | if ((!ok) || (variableName != this->nameString())) { |
| 91 | ✗ | remove(); | |
| 92 | ✗ | LOG_AND_THROW("Unable to set " << briefDescription() << "'s Name to " << variableName << "."); | |
| 93 | } | ||
| 94 |
1/1✓ Branch 1 taken 2 times.
|
2 | setInitialValue(initialValue); |
| 95 | 2 | } | |
| 96 | |||
| 97 | 7602 | IddObjectType ExternalInterfaceVariable::iddObjectType() { | |
| 98 |
1/1✓ Branch 1 taken 7602 times.
|
7602 | return {IddObjectType::OS_ExternalInterface_Variable}; |
| 99 | } | ||
| 100 | |||
| 101 | 3 | double ExternalInterfaceVariable::initialValue() const { | |
| 102 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ExternalInterfaceVariable_Impl>()->initialValue(); |
| 103 | } | ||
| 104 | |||
| 105 | 3 | bool ExternalInterfaceVariable::setInitialValue(double initialValue) { | |
| 106 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ExternalInterfaceVariable_Impl>()->setInitialValue(initialValue); |
| 107 | } | ||
| 108 | |||
| 109 | 3 | bool ExternalInterfaceVariable::exportToBCVTB() const { | |
| 110 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ExternalInterfaceVariable_Impl>()->exportToBCVTB(); |
| 111 | } | ||
| 112 | |||
| 113 | 1 | bool ExternalInterfaceVariable::isExportToBCVTBDefaulted() const { | |
| 114 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::ExternalInterfaceVariable_Impl>()->isExportToBCVTBDefaulted(); |
| 115 | } | ||
| 116 | |||
| 117 | 1 | bool ExternalInterfaceVariable::setExportToBCVTB(bool exportToBCVTB) { | |
| 118 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::ExternalInterfaceVariable_Impl>()->setExportToBCVTB(exportToBCVTB); |
| 119 | } | ||
| 120 | |||
| 121 | 1 | void ExternalInterfaceVariable::resetExportToBCVTB() { | |
| 122 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::ExternalInterfaceVariable_Impl>()->resetExportToBCVTB(); |
| 123 | 1 | } | |
| 124 | |||
| 125 | /// @cond | ||
| 126 |
1/1✓ Branch 2 taken 1 time.
|
1 | ExternalInterfaceVariable::ExternalInterfaceVariable(std::shared_ptr<detail::ExternalInterfaceVariable_Impl> impl) : ModelObject(impl) {} |
| 127 | /// @endcond | ||
| 128 | |||
| 129 | } // namespace model | ||
| 130 | } // namespace openstudio | ||
| 131 |