GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 1 / 1 / 2
Functions: 100.0% 1 / 1 / 2
Branches: -% 0 / 1 / 1

src/model/ScheduleTypeRegistry.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_SCHEDULETYPEREGISTRY_HPP
7 #define MODEL_SCHEDULETYPEREGISTRY_HPP
8
9 #include "ModelAPI.hpp"
10
11 #include "../utilities/core/Logger.hpp"
12
13 #include <map>
14 #include <string>
15
16 #include <boost/optional.hpp>
17
18 namespace openstudio {
19
20 namespace model {
21
22 class Model;
23 class Schedule;
24 class ScheduleTypeLimits;
25
26 /** Data structure for registering and viewing a specific type of schedule that can exist in a
27 * Model. */
28 struct MODEL_API ScheduleType
29 {
30 /** The name of a class that can point to a schedule. */
31 std::string className;
32 /** The display name of that schedule (which is used as a key in ScheduleTypeRegistry,
33 * and is also intented for use in UI displays). */
34 std::string scheduleDisplayName;
35 /** The name of the Relationship that points from the user (of type className) to the Schedule. */
36 std::string scheduleRelationshipName;
37 /** Set to true if the schedule values are continuous (doubles); false if they are discrete
38 * (integers). Used to set or test the ScheduleTypeLimits field "Numeric Type". */
39 bool isContinuous;
40 /** Key into the ScheduleTypeLimits field "Unit Type". */
41 std::string unitType;
42 /** Minimum value for this schedule type (or unbounded if == boost::none). */
43 boost::optional<double> lowerLimitValue;
44 /** Maximum value for this schedule type (or unbounded if == boost::none). */
45 boost::optional<double> upperLimitValue;
46 };
47
48 /** \relates ScheduleType */
49 using ScheduleTypeVector = std::vector<ScheduleType>;
50
51 /** Returns true if candidate is consistent with scheduleType.
52 * When isStringent is true, we also check that if scheduleType does not have a lower/upper bound, then candidate must not have them either.
53 * \relates ScheduleType */
54 MODEL_API bool isCompatible(const ScheduleType& scheduleType, const ScheduleTypeLimits& candidate, bool isStringent = false);
55
56 /** Singleton class that contains a registry of all types of schedules that can exist in a Model. */
57 class MODEL_API ScheduleTypeRegistry
58 {
59 public:
60 static ScheduleTypeRegistry& instance();
61
62 ScheduleTypeRegistry(const ScheduleTypeRegistry& other) = delete;
63 ScheduleTypeRegistry(ScheduleTypeRegistry&& other) = delete;
64 ScheduleTypeRegistry& operator=(const ScheduleTypeRegistry&) = delete;
65 ScheduleTypeRegistry& operator=(ScheduleTypeRegistry&&) = delete;
66
67 /** Returns the names of classes that have \link ScheduleType ScheduleTypes \endlink registered
68 * with the ScheduleTypeRegistry. */
69 std::vector<std::string> classNames() const;
70
71 /** Returns all the \link ScheduleType ScheduleTypes \endlink registered for className. */
72 std::vector<ScheduleType> getScheduleTypesByClassName(const std::string& className) const;
73
74 /** Returns a particular ScheduleType, based on the className and scheduleDisplayName keys. Throws
75 * if there is no such ScheduleType registered. */
76 ScheduleType getScheduleType(const std::string& className, const std::string& scheduleDisplayName) const;
77
78 /** Finds and returns a compatible ScheduleTypeLimits already in model, or creates and returns a
79 * new one. If the scheduleType is not fully specified, that is, if at least one of
80 * lowerLimitValue and upperLimitValue are not fixed, a new ScheduleTypeLimits is always
81 * created so the user can change those limits at will. */
82 ScheduleTypeLimits getOrCreateScheduleTypeLimits(const ScheduleType& scheduleType, Model& model) const;
83
84 std::string getDefaultName(const ScheduleType& scheduleType) const;
85
86 private:
87 ScheduleTypeRegistry();
88 1285 ~ScheduleTypeRegistry() = default;
89
90 − REGISTER_LOGGER("openstudio.model.ScheduleTypeRegistry");
91
92 using ClassNameToScheduleTypesMap = std::map<std::string, std::vector<ScheduleType>>;
93 ClassNameToScheduleTypesMap m_classNameToScheduleTypesMap;
94 };
95
96 /** Returns true if candidate is consistent with the ScheduleType that corresponds to className
97 * and scheduleRelationshipName. Throws if there is no such ScheduleType.
98 * \relates ScheduleTypeRegistry */
99 MODEL_API bool isCompatible(const std::string& className, const std::string& scheduleDisplayName, const ScheduleTypeLimits& candidate);
100
101 /** If schedule.scheduleTypeLimtis(), returns true if that ScheduleTypeLimits isCompatible and
102 * otherwise returns false. Otherwise, uses
103 * ScheduleTypeRegistry::getOrCreateScheduleTypeLimits to find an appropriate
104 * ScheduleTypeLimits and then calls Schedule::setScheduleTypeLimtis, which should succeed in
105 * this case. This method is used by all of the ModelObject methods that set schedules.
106 * \relates ScheduleTypeRegistry */
107 MODEL_API bool checkOrAssignScheduleTypeLimits(const std::string& className, const std::string& scheduleDisplayName, Schedule& schedule);
108
109 /** Returns all of the ScheduleTypeLimtis already in model that are \link isCompatible
110 * compatible\endlink with className and scheduleDisplayName. May be used instead of
111 * ScheduleTypeRegistry::getOrCreateScheduleTypeLimits to reduce the number of
112 * ScheduleTypeLimits that are ultimately created and present in a model.
113 * \relates ScheduleTypeRegistry */
114 MODEL_API std::vector<ScheduleTypeLimits> getCompatibleScheduleTypeLimits(const Model& model, const std::string& className,
115 const std::string& scheduleDisplayName);
116
117 MODEL_API std::vector<Schedule> getCompatibleSchedules(const Model& model, const std::string& className, const std::string& scheduleDisplayName);
118
119 } // namespace model
120 } // namespace openstudio
121
122 #endif // MODEL_SCHEDULETYPEREGISTRY_HPP
123