src/model/SpaceItem.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 "SpaceItem.hpp" | ||
| 7 | #include "SpaceItem_Impl.hpp" | ||
| 8 | |||
| 9 | #include "Model.hpp" | ||
| 10 | #include "Model_Impl.hpp" | ||
| 11 | #include "Space.hpp" | ||
| 12 | #include "Space_Impl.hpp" | ||
| 13 | #include "ParentObject.hpp" | ||
| 14 | #include "ParentObject_Impl.hpp" | ||
| 15 | |||
| 16 | #include "../utilities/core/Assert.hpp" | ||
| 17 | |||
| 18 | namespace openstudio { | ||
| 19 | namespace model { | ||
| 20 | |||
| 21 | namespace detail { | ||
| 22 | |||
| 23 | 5196 | SpaceItem_Impl::SpaceItem_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : ModelObject_Impl(idfObject, model, keepHandle) {} | |
| 24 | |||
| 25 | 3361 | SpaceItem_Impl::SpaceItem_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 26 | 3361 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 27 | |||
| 28 | 2791 | SpaceItem_Impl::SpaceItem_Impl(const SpaceItem_Impl& other, Model_Impl* model, bool keepHandle) : ModelObject_Impl(other, model, keepHandle) {} | |
| 29 | |||
| 30 | 6 | boost::optional<ParentObject> SpaceItem_Impl::parent() const { | |
| 31 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | return boost::optional<ParentObject>(this->space()); |
| 32 | } | ||
| 33 | |||
| 34 | 14 | bool SpaceItem_Impl::setParent(ParentObject& newParent) { | |
| 35 | 14 | bool result = false; | |
| 36 |
2/3✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
|
28 | if (newParent.optionalCast<Space>()) { |
| 37 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | result = this->setSpace(newParent.cast<Space>()); |
| 38 | } | ||
| 39 | 14 | return result; | |
| 40 | } | ||
| 41 | |||
| 42 | 3496 | boost::optional<Space> SpaceItem_Impl::space() const { | |
| 43 | 3496 | boost::optional<Space> result; | |
| 44 |
2/2✓ Branch 1 taken 3496 times.
✓ Branch 4 taken 3496 times.
|
3496 | OptionalWorkspaceObject space = getTarget(this->spaceIndex()); |
| 45 |
2/2✓ Branch 0 taken 3437 times.
✓ Branch 1 taken 59 times.
|
3496 | if (space) { |
| 46 |
2/2✓ Branch 1 taken 3437 times.
✓ Branch 4 taken 3437 times.
|
3437 | result = space->optionalCast<Space>(); |
| 47 | } | ||
| 48 | 6992 | return result; | |
| 49 | 3496 | } | |
| 50 | |||
| 51 | 1285 | bool SpaceItem_Impl::setSpace(const Space& space) { | |
| 52 |
3/3✓ Branch 1 taken 1285 times.
✓ Branch 4 taken 1285 times.
✓ Branch 7 taken 1285 times.
|
1285 | return setPointer(this->spaceIndex(), space.handle()); |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | void SpaceItem_Impl::resetSpace() { | |
| 56 | ✗ | bool ok = setString(this->spaceIndex(), ""); | |
| 57 | ✗ | OS_ASSERT(ok); | |
| 58 | ✗ | } | |
| 59 | |||
| 60 | ✗ | boost::optional<ModelObject> SpaceItem_Impl::spaceAsModelObject() const { | |
| 61 | ✗ | OptionalModelObject result; | |
| 62 | ✗ | OptionalSpace intermediate = space(); | |
| 63 | ✗ | if (intermediate) { | |
| 64 | ✗ | result = *intermediate; | |
| 65 | } | ||
| 66 | ✗ | return result; | |
| 67 | ✗ | } | |
| 68 | |||
| 69 | ✗ | bool SpaceItem_Impl::setSpaceAsModelObject(const boost::optional<ModelObject>& modelObject) { | |
| 70 | ✗ | if (modelObject) { | |
| 71 | ✗ | OptionalSpace intermediate = modelObject->optionalCast<Space>(); | |
| 72 | ✗ | if (intermediate) { | |
| 73 | ✗ | return setSpace(*intermediate); | |
| 74 | } else { | ||
| 75 | ✗ | return false; | |
| 76 | } | ||
| 77 | ✗ | } else { | |
| 78 | ✗ | resetSpace(); | |
| 79 | } | ||
| 80 | ✗ | return true; | |
| 81 | } | ||
| 82 | |||
| 83 | } // namespace detail | ||
| 84 | |||
| 85 | 1828 | SpaceItem::SpaceItem(IddObjectType type, const Model& model) : ModelObject(type, model) { | |
| 86 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1828 times.
✗ Branch 5 not taken.
|
1828 | OS_ASSERT(getImpl<detail::SpaceItem_Impl>()); |
| 87 | 1828 | } | |
| 88 | |||
| 89 |
1/1✓ Branch 3 taken 7634 times.
|
7634 | SpaceItem::SpaceItem(std::shared_ptr<detail::SpaceItem_Impl> impl) : ModelObject(std::move(impl)) {} |
| 90 | |||
| 91 | 2047 | boost::optional<Space> SpaceItem::space() const { | |
| 92 |
1/1✓ Branch 3 taken 2047 times.
|
2047 | return getImpl<detail::SpaceItem_Impl>()->space(); |
| 93 | } | ||
| 94 | |||
| 95 | 1174 | bool SpaceItem::setSpace(const Space& space) { | |
| 96 |
1/1✓ Branch 3 taken 1174 times.
|
1174 | return getImpl<detail::SpaceItem_Impl>()->setSpace(space); |
| 97 | } | ||
| 98 | |||
| 99 | ✗ | void SpaceItem::resetSpace() { | |
| 100 | ✗ | return getImpl<detail::SpaceItem_Impl>()->resetSpace(); | |
| 101 | } | ||
| 102 | |||
| 103 | } // namespace model | ||
| 104 | } // namespace openstudio | ||
| 105 |