src/model/ResourceObject.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 "ResourceObject.hpp" | ||
| 7 | #include "ResourceObject_Impl.hpp" | ||
| 8 | |||
| 9 | #include "../utilities/core/Assert.hpp" | ||
| 10 | |||
| 11 | namespace openstudio { | ||
| 12 | namespace model { | ||
| 13 | |||
| 14 | namespace detail { | ||
| 15 | |||
| 16 | 54406 | ResourceObject_Impl::ResourceObject_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 17 | 54406 | : ParentObject_Impl(idfObject, model, keepHandle) {} | |
| 18 | |||
| 19 | 17859 | ResourceObject_Impl::ResourceObject_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 20 | 17859 | : ParentObject_Impl(other, model, keepHandle) {} | |
| 21 | |||
| 22 | 33166 | ResourceObject_Impl::ResourceObject_Impl(const ResourceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 23 | 33166 | : ParentObject_Impl(other, model, keepHandle) {} | |
| 24 | |||
| 25 | 684 | unsigned ResourceObject_Impl::directUseCount(bool excludeChildren) const { | |
| 26 | |||
| 27 | 684 | unsigned result = 0; | |
| 28 | |||
| 29 | 684 | ModelObjectVector children; | |
| 30 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 677 times.
|
684 | if (excludeChildren) { |
| 31 |
1/1✓ Branch 1 taken 7 times.
|
7 | children = this->children(); |
| 32 | } | ||
| 33 | |||
| 34 |
1/1✓ Branch 1 taken 684 times.
|
684 | WorkspaceObjectVector sources = this->sources(); |
| 35 |
2/2✓ Branch 5 taken 834 times.
✓ Branch 6 taken 684 times.
|
1518 | for (const WorkspaceObject& source : sources) { |
| 36 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 829 times.
|
834 | if (excludeChildren) { |
| 37 | // check if this is a child | ||
| 38 |
1/1✓ Branch 3 taken 5 times.
|
5 | auto it = std::find_if(children.cbegin(), children.cend(), |
| 39 |
1/1✓ Branch 1 taken 5 times.
|
5 | [h = source.handle()](const ModelObject& mo) { return handleEquals<ModelObject, Handle>(mo, h); }); |
| 40 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (it == children.end()) { |
| 41 | // non-Child--count the use | ||
| 42 | 5 | ++result; | |
| 43 | } | ||
| 44 | } else { | ||
| 45 | // count the use | ||
| 46 | 829 | ++result; | |
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 684 | return result; | |
| 51 | 684 | } | |
| 52 | |||
| 53 | 2447 | unsigned ResourceObject_Impl::nonResourceObjectUseCount(bool excludeChildren) const { | |
| 54 | |||
| 55 | 2447 | unsigned result = 0; | |
| 56 | |||
| 57 | 2447 | ModelObjectVector children; | |
| 58 |
2/2✓ Branch 0 taken 2443 times.
✓ Branch 1 taken 4 times.
|
2447 | if (excludeChildren) { |
| 59 |
1/1✓ Branch 1 taken 2443 times.
|
2443 | children = this->children(); |
| 60 | } | ||
| 61 | |||
| 62 |
1/1✓ Branch 1 taken 2447 times.
|
2447 | WorkspaceObjectVector sources = this->sources(); |
| 63 |
2/2✓ Branch 5 taken 3663 times.
✓ Branch 6 taken 2447 times.
|
6110 | for (const WorkspaceObject& source : sources) { |
| 64 |
1/1✓ Branch 1 taken 3663 times.
|
3663 | OptionalResourceObject oro = source.optionalCast<ResourceObject>(); |
| 65 |
2/2✓ Branch 0 taken 1657 times.
✓ Branch 1 taken 2006 times.
|
3663 | if (oro) { |
| 66 | // another ResourceObject, pass the request through | ||
| 67 |
2/2✓ Branch 1 taken 1657 times.
✓ Branch 4 taken 1657 times.
|
1657 | result += oro->nonResourceObjectUseCount(excludeChildren); |
| 68 | } else { | ||
| 69 | |||
| 70 |
1/2✓ Branch 0 taken 2006 times.
✗ Branch 1 not taken.
|
2006 | if (excludeChildren) { |
| 71 | // check if this is a child | ||
| 72 |
1/1✓ Branch 3 taken 2006 times.
|
2006 | auto it = std::find_if(children.cbegin(), children.cend(), |
| 73 |
1/1✓ Branch 1 taken 2006 times.
|
5870 | [h = source.handle()](const ModelObject& mo) { return handleEquals<ModelObject, Handle>(mo, h); }); |
| 74 |
2/2✓ Branch 2 taken 1110 times.
✓ Branch 3 taken 896 times.
|
2006 | if (it == children.end()) { |
| 75 | // non-ResourceObject and non-Child--count the use | ||
| 76 | 1110 | ++result; | |
| 77 | } | ||
| 78 | } else { | ||
| 79 | // non-ResourceObject--count the use | ||
| 80 | ✗ | ++result; | |
| 81 | } | ||
| 82 | } | ||
| 83 | 3663 | } | |
| 84 | |||
| 85 | 2447 | return result; | |
| 86 | 2447 | } | |
| 87 | |||
| 88 | } // namespace detail | ||
| 89 | |||
| 90 | 36280 | ResourceObject::ResourceObject(IddObjectType type, const Model& model) : ParentObject(type, model) { | |
| 91 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 36280 times.
✗ Branch 5 not taken.
|
36280 | OS_ASSERT(getImpl<detail::ResourceObject_Impl>()); |
| 92 | 36280 | } | |
| 93 | |||
| 94 |
1/1✓ Branch 3 taken 400656 times.
|
400656 | ResourceObject::ResourceObject(std::shared_ptr<detail::ResourceObject_Impl> impl) : ParentObject(std::move(impl)) {} |
| 95 | |||
| 96 | 684 | unsigned ResourceObject::directUseCount(bool excludeChildren) const { | |
| 97 |
1/1✓ Branch 3 taken 684 times.
|
684 | return getImpl<detail::ResourceObject_Impl>()->directUseCount(excludeChildren); |
| 98 | } | ||
| 99 | |||
| 100 | 2447 | unsigned ResourceObject::nonResourceObjectUseCount(bool excludeChildren) const { | |
| 101 |
1/1✓ Branch 3 taken 2447 times.
|
2447 | return getImpl<detail::ResourceObject_Impl>()->nonResourceObjectUseCount(excludeChildren); |
| 102 | } | ||
| 103 | |||
| 104 | 2 | std::vector<ResourceObject> getRecursiveResources(const ModelObject& object) { | |
| 105 | 2 | std::set<Handle> resultSet; | |
| 106 | 2 | std::pair<HandleSet::const_iterator, bool> insertResult; | |
| 107 | 2 | std::vector<ResourceObject> result; | |
| 108 | |||
| 109 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::deque<ModelObject> objectQueue; |
| 110 |
1/1✓ Branch 1 taken 2 times.
|
2 | objectQueue.push_back(object); |
| 111 | |||
| 112 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
|
10 | while (!objectQueue.empty()) { |
| 113 |
1/1✓ Branch 2 taken 8 times.
|
8 | ModelObject currentObject(objectQueue[0]); |
| 114 | 8 | objectQueue.pop_front(); | |
| 115 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 8 times.
|
14 | for (const ResourceObject& resource : currentObject.resources()) { |
| 116 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | insertResult = resultSet.insert(resource.handle()); |
| 117 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (insertResult.second) { |
| 118 |
1/1✓ Branch 1 taken 6 times.
|
6 | result.push_back(resource); |
| 119 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | objectQueue.push_back(resource.cast<ModelObject>()); |
| 120 | } | ||
| 121 | 8 | } | |
| 122 | 8 | } | |
| 123 | |||
| 124 | 4 | return result; | |
| 125 | 2 | } | |
| 126 | |||
| 127 | 1499 | std::vector<std::vector<ModelObject>> getRecursiveResourceSubTrees(const ModelObject& object, bool includeComponentCostLineItems) { | |
| 128 | 1499 | std::set<Handle> resultSet; | |
| 129 | 1499 | std::pair<HandleSet::const_iterator, bool> insertResult; | |
| 130 | 1499 | std::vector<std::vector<ModelObject>> result; | |
| 131 | |||
| 132 |
1/1✓ Branch 1 taken 1499 times.
|
1499 | std::deque<ModelObject> objectQueue; |
| 133 |
1/1✓ Branch 1 taken 1499 times.
|
1499 | objectQueue.push_back(object); |
| 134 | |||
| 135 |
2/2✓ Branch 1 taken 2310 times.
✓ Branch 2 taken 1499 times.
|
3809 | while (!objectQueue.empty()) { |
| 136 |
1/1✓ Branch 2 taken 2310 times.
|
2310 | ModelObject currentObject(objectQueue[0]); |
| 137 | 2310 | objectQueue.pop_front(); | |
| 138 |
3/3✓ Branch 1 taken 2310 times.
✓ Branch 8 taken 802 times.
✓ Branch 9 taken 2310 times.
|
3112 | for (const ResourceObject& resource : currentObject.resources()) { |
| 139 |
2/2✓ Branch 1 taken 802 times.
✓ Branch 4 taken 802 times.
|
802 | insertResult = resultSet.insert(resource.handle()); |
| 140 |
2/2✓ Branch 0 taken 742 times.
✓ Branch 1 taken 60 times.
|
802 | if (insertResult.second) { |
| 141 |
1/1✓ Branch 1 taken 742 times.
|
742 | std::vector<ModelObject> subTree = getRecursiveChildren(resource, includeComponentCostLineItems); |
| 142 |
1/1✓ Branch 5 taken 742 times.
|
742 | objectQueue.insert(objectQueue.end(), subTree.begin(), subTree.end()); |
| 143 |
1/1✓ Branch 1 taken 742 times.
|
742 | result.push_back(subTree); |
| 144 | 742 | } | |
| 145 | 2310 | } | |
| 146 | 2310 | } | |
| 147 | |||
| 148 | 2998 | return result; | |
| 149 | 1499 | } | |
| 150 | |||
| 151 | } // namespace model | ||
| 152 | } // namespace openstudio | ||
| 153 |