src/model/OutputDiagnostics.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 "OutputDiagnostics.hpp" | ||
| 7 | #include "OutputDiagnostics_Impl.hpp" | ||
| 8 | |||
| 9 | #include "Model.hpp" | ||
| 10 | #include "Model_Impl.hpp" | ||
| 11 | |||
| 12 | #include <utilities/idd/IddFactory.hxx> | ||
| 13 | #include <utilities/idd/IddEnums.hxx> | ||
| 14 | #include <utilities/idd/OS_Output_Diagnostics_FieldEnums.hxx> | ||
| 15 | |||
| 16 | #include "../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 17 | #include "../utilities/core/Assert.hpp" | ||
| 18 | |||
| 19 | namespace openstudio { | ||
| 20 | namespace model { | ||
| 21 | |||
| 22 | namespace detail { | ||
| 23 | |||
| 24 | 15 | OutputDiagnostics_Impl::OutputDiagnostics_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 25 | 15 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 26 |
4/6✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 13 not taken.
|
15 | OS_ASSERT(idfObject.iddObject().type() == OutputDiagnostics::iddObjectType()); |
| 27 | 15 | } | |
| 28 | |||
| 29 | 9 | OutputDiagnostics_Impl::OutputDiagnostics_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 30 | 9 | : ModelObject_Impl(other, model, keepHandle) { | |
| 31 |
4/6✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 13 not taken.
|
9 | OS_ASSERT(other.iddObject().type() == OutputDiagnostics::iddObjectType()); |
| 32 | 9 | } | |
| 33 | |||
| 34 | 5 | OutputDiagnostics_Impl::OutputDiagnostics_Impl(const OutputDiagnostics_Impl& other, Model_Impl* model, bool keepHandle) | |
| 35 | 5 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 36 | |||
| 37 | ✗ | const std::vector<std::string>& OutputDiagnostics_Impl::outputVariableNames() const { | |
| 38 | ✗ | static const std::vector<std::string> result; | |
| 39 | ✗ | if (result.empty()) { | |
| 40 | } | ||
| 41 | ✗ | return result; | |
| 42 | } | ||
| 43 | |||
| 44 | ✗ | IddObjectType OutputDiagnostics_Impl::iddObjectType() const { | |
| 45 | ✗ | return OutputDiagnostics::iddObjectType(); | |
| 46 | } | ||
| 47 | |||
| 48 | 49 | std::vector<std::string> OutputDiagnostics_Impl::keys() const { | |
| 49 | 49 | std::vector<std::string> result; | |
| 50 |
3/3✓ Branch 1 taken 49 times.
✓ Branch 8 taken 80 times.
✓ Branch 9 taken 49 times.
|
129 | for (const auto& eg : extensibleGroups()) { |
| 51 |
1/1✓ Branch 1 taken 80 times.
|
80 | auto _s = eg.getString(OS_Output_DiagnosticsExtensibleFields::Key); |
| 52 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 4 not taken.
|
80 | OS_ASSERT(_s); |
| 53 |
2/2✓ Branch 1 taken 80 times.
✓ Branch 4 taken 80 times.
|
80 | result.push_back(_s.get()); |
| 54 | 129 | } | |
| 55 | 49 | return result; | |
| 56 | ✗ | } | |
| 57 | |||
| 58 | 19 | bool OutputDiagnostics_Impl::addKey(const std::string& key) { | |
| 59 |
1/1✓ Branch 1 taken 19 times.
|
19 | std::vector<std::string> existingKeys = this->keys(); |
| 60 |
1/1✓ Branch 3 taken 19 times.
|
40 | if (std::find_if(existingKeys.begin(), existingKeys.end(), [&key](const std::string& k) { return openstudio::istringEqual(k, key); }) |
| 61 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 16 times.
|
38 | != existingKeys.end()) { |
| 62 |
7/7✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
✓ Branch 19 taken 3 times.
|
3 | LOG(Info, "Not adding key '" << key << "' to Output:Diagnostics since it is already present"); |
| 63 | // Return true anyways, it's a success | ||
| 64 | 3 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>(); |
| 68 |
1/1✓ Branch 1 taken 16 times.
|
16 | bool result = eg.setString(OS_Output_DiagnosticsExtensibleFields::Key, key); |
| 69 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
|
16 | if (!result) { |
| 70 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex()); |
| 71 | } | ||
| 72 | |||
| 73 | 16 | return result; | |
| 74 | 19 | } | |
| 75 | |||
| 76 | 5 | bool OutputDiagnostics_Impl::setKeys(const std::vector<std::string>& keys) { | |
| 77 | 5 | bool result = true; | |
| 78 | |||
| 79 | 5 | clearKeys(); | |
| 80 | |||
| 81 |
2/2✓ Branch 5 taken 15 times.
✓ Branch 6 taken 5 times.
|
20 | for (const auto& k : keys) { |
| 82 |
1/1✓ Branch 1 taken 15 times.
|
15 | bool thisResult = addKey(k); |
| 83 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 14 times.
|
15 | if (!thisResult) { |
| 84 |
7/7✓ 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.
|
1 | LOG(Warn, "Couldn't add key " << k << " to OutputDiagnostics, skipping and continuing."); |
| 85 | 1 | result = false; | |
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | 5 | return result; | |
| 90 | } | ||
| 91 | |||
| 92 | 1 | bool OutputDiagnostics_Impl::enableDisplayExtraWarnings() { | |
| 93 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | return addKey("DisplayExtraWarnings"); |
| 94 | } | ||
| 95 | |||
| 96 | 6 | void OutputDiagnostics_Impl::clearKeys() { | |
| 97 |
1/1✓ Branch 1 taken 6 times.
|
6 | clearExtensibleGroups(); |
| 98 | 6 | } | |
| 99 | |||
| 100 | } // namespace detail | ||
| 101 | |||
| 102 | 7772 | IddObjectType OutputDiagnostics::iddObjectType() { | |
| 103 |
1/1✓ Branch 1 taken 7772 times.
|
7772 | return {IddObjectType::OS_Output_Diagnostics}; |
| 104 | } | ||
| 105 | |||
| 106 | ✗ | std::vector<std::string> OutputDiagnostics::keyValues() { | |
| 107 | ✗ | IddObject obj = IddFactory::instance().getObject(iddObjectType()).get(); | |
| 108 | // Return IddKeyNames in extensible portion | ||
| 109 | ✗ | return getIddKeyNames(obj, obj.numFields() + OS_Output_DiagnosticsExtensibleFields::Key); | |
| 110 | ✗ | } | |
| 111 | |||
| 112 | ✗ | std::vector<std::string> OutputDiagnostics::validKeyValues() { | |
| 113 | ✗ | return keyValues(); | |
| 114 | } | ||
| 115 | |||
| 116 | 30 | std::vector<std::string> OutputDiagnostics::keys() const { | |
| 117 |
1/1✓ Branch 3 taken 30 times.
|
30 | return getImpl<detail::OutputDiagnostics_Impl>()->keys(); |
| 118 | } | ||
| 119 | |||
| 120 | 3 | bool OutputDiagnostics::addKey(const std::string& key) { | |
| 121 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::OutputDiagnostics_Impl>()->addKey(key); |
| 122 | } | ||
| 123 | |||
| 124 | 5 | bool OutputDiagnostics::setKeys(const std::vector<std::string>& keys) { | |
| 125 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::OutputDiagnostics_Impl>()->setKeys(keys); |
| 126 | } | ||
| 127 | |||
| 128 | 1 | bool OutputDiagnostics::enableDisplayExtraWarnings() { | |
| 129 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::OutputDiagnostics_Impl>()->enableDisplayExtraWarnings(); |
| 130 | } | ||
| 131 | |||
| 132 | 1 | void OutputDiagnostics::clearKeys() { | |
| 133 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::OutputDiagnostics_Impl>()->clearKeys(); |
| 134 | 1 | } | |
| 135 | |||
| 136 | /// @cond | ||
| 137 |
1/1✓ Branch 2 taken 9 times.
|
9 | OutputDiagnostics::OutputDiagnostics(std::shared_ptr<detail::OutputDiagnostics_Impl> impl) : ModelObject(impl) {} |
| 138 | 6 | OutputDiagnostics::OutputDiagnostics(Model& model) : ModelObject(OutputDiagnostics::iddObjectType(), model) {} | |
| 139 | |||
| 140 | /// @endcond | ||
| 141 | |||
| 142 | } // namespace model | ||
| 143 | } // namespace openstudio | ||
| 144 |