src/model/ResourceObject.hpp
| 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 | #ifndef MODEL_RESOURCEOBJECT_HPP | ||
| 7 | #define MODEL_RESOURCEOBJECT_HPP | ||
| 8 | |||
| 9 | #include "ModelAPI.hpp" | ||
| 10 | #include "ParentObject.hpp" | ||
| 11 | |||
| 12 | namespace openstudio { | ||
| 13 | namespace model { | ||
| 14 | |||
| 15 | namespace detail { | ||
| 16 | class ResourceObject_Impl; | ||
| 17 | } | ||
| 18 | |||
| 19 | /** ResourceObject is an abstract class derived from ParentObject. | ||
| 20 | * | ||
| 21 | * ResourceObject is a pure virtual class for ModelObjects that are shared, globally across a Model. | ||
| 22 | * Examples include Constructions (referenced by many Surfaces), Materials (referenced by many Constructions), | ||
| 23 | * and Schedules (referenced by almost everything). Methods such as ModelObject::clone and Model::purgeUnusedResourceObjects | ||
| 24 | * handle special cases related to ResourceObjects. | ||
| 25 | */ | ||
| 26 | class MODEL_API ResourceObject : public ParentObject | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | /** Returns the number of objects that use this resource directly. All usages count equally. | ||
| 30 | * For instance, the use of a Material in a LayeredConstruction counts as one use of the | ||
| 31 | * Material object, and usages of that LayeredConstruction do not add to the Material's use | ||
| 32 | * count. If excludeChildren is true then children of this object do not contribute to the use count.*/ | ||
| 33 | unsigned directUseCount(bool excludeChildren = false) const; | ||
| 34 | |||
| 35 | /** Returns the number of non-ResourceObjects that use this resource either directly or | ||
| 36 | * indirectly. Non-ResourceObjects include Building, Zone, Surface, Lights, and AirLoopHVAC, | ||
| 37 | * for instance. An example of indirect use is the use of a Material object through inclusion | ||
| 38 | * in a Construction. If a particular Material is used in exactly one LayeredConstruction, which | ||
| 39 | * is in turn used by three PlanarSurface objects, then the nonResourceObjectUseCount of both | ||
| 40 | * the Material and the LayeredConstruction is three. | ||
| 41 | * If excludeChildren is true then children of this object do not contribute to the use count.*/ | ||
| 42 | unsigned nonResourceObjectUseCount(bool excludeChildren = false) const; | ||
| 43 | |||
| 44 | 1523867 | virtual ~ResourceObject() override = default; | |
| 45 | // Default the copy and move operators because the virtual dtor is explicit | ||
| 46 | 187930 | ResourceObject(const ResourceObject& other) = default; | |
| 47 | 899124 | ResourceObject(ResourceObject&& other) = default; | |
| 48 | 25 | ResourceObject& operator=(const ResourceObject&) = default; | |
| 49 | 11408 | ResourceObject& operator=(ResourceObject&&) = default; | |
| 50 | |||
| 51 | protected: | ||
| 52 | /** @name Constructors and Destructors */ | ||
| 53 | //@{ | ||
| 54 | |||
| 55 | /// Constructs a new PlanarSurface object in the model. | ||
| 56 | ResourceObject(IddObjectType type, const Model& model); | ||
| 57 | |||
| 58 | //@} | ||
| 59 | |||
| 60 | /// @cond | ||
| 61 | |||
| 62 | using ImplType = detail::ResourceObject_Impl; | ||
| 63 | |||
| 64 | friend class Model; | ||
| 65 | friend class openstudio::IdfObject; | ||
| 66 | friend class detail::ResourceObject_Impl; | ||
| 67 | |||
| 68 | explicit ResourceObject(std::shared_ptr<detail::ResourceObject_Impl> impl); | ||
| 69 | |||
| 70 | private: | ||
| 71 | REGISTER_LOGGER("openstudio.model.ResourceObject"); | ||
| 72 | |||
| 73 | /// @endcond | ||
| 74 | }; | ||
| 75 | |||
| 76 | /** \relates ResourceObject */ | ||
| 77 | using OptionalResourceObject = boost::optional<ResourceObject>; | ||
| 78 | |||
| 79 | /** \relates ResourceObject */ | ||
| 80 | using ResourceObjectVector = std::vector<ResourceObject>; | ||
| 81 | |||
| 82 | /** Returns all \link ResourceObject ResourceObjects \endlink accessible by recursively calling | ||
| 83 | * .resources() starting from object. Will not return object even if object is a ResourceObject. | ||
| 84 | * \relates ModelObject */ | ||
| 85 | MODEL_API std::vector<ResourceObject> getRecursiveResources(const ModelObject& object); | ||
| 86 | |||
| 87 | /** Returns all objects in getRecursiveResources(object) that can be cast to type T. */ | ||
| 88 | template <typename T> | ||
| 89 | std::vector<T> getSubsetOfRecursiveResources(const ModelObject& object) { | ||
| 90 | std::vector<ResourceObject> allResources = getRecursiveResources(object); | ||
| 91 | std::vector<T> result; | ||
| 92 | for (const ResourceObject& resource : allResources) { | ||
| 93 | boost::optional<T> candidate = resource.optionalCast<T>(); | ||
| 94 | if (candidate) { | ||
| 95 | result.push_back(*candidate); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | return result; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** Returns all \link ResourceObject ResourceObjects \endlink and their children accessible | ||
| 102 | * by alternately calling ModelObject::resources() and getRecursiveChilden. Each element of the | ||
| 103 | * returned vector is a vector headed by a ResourceObject and followed by that ResourceObject's | ||
| 104 | * children. ComponentCost_LineItem objects are not technically children but may be included | ||
| 105 | * by setting the optional second argument to true.*/ | ||
| 106 | MODEL_API std::vector<std::vector<ModelObject>> getRecursiveResourceSubTrees(const ModelObject& object, bool includeComponentCostLineItems = false); | ||
| 107 | |||
| 108 | } // namespace model | ||
| 109 | } // namespace openstudio | ||
| 110 | |||
| 111 | #endif // MODEL_RESOURCEOBJECT_HPP | ||
| 112 |