src/utilities/idd/IddObject_Impl.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 UTILITIES_IDD_IDDOBJECT_IMPL_HPP | ||
| 7 | #define UTILITIES_IDD_IDDOBJECT_IMPL_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | #include "IddObjectProperties.hpp" | ||
| 11 | #include "IddFieldProperties.hpp" | ||
| 12 | #include "IddField.hpp" | ||
| 13 | |||
| 14 | #include "../core/Logger.hpp" | ||
| 15 | #include "../core/Containers.hpp" | ||
| 16 | |||
| 17 | #include "IddEnums.hpp" | ||
| 18 | |||
| 19 | #include <string> | ||
| 20 | #include <ostream> | ||
| 21 | #include <vector> | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | |||
| 25 | // forward declarations | ||
| 26 | class ExtensibleIndex; | ||
| 27 | |||
| 28 | namespace detail { | ||
| 29 | |||
| 30 | /** Implementation of IddObject */ | ||
| 31 | class UTILITIES_API IddObject_Impl | ||
| 32 | { | ||
| 33 | public: | ||
| 34 | /** @name Constructors */ | ||
| 35 | //@{ | ||
| 36 | |||
| 37 | /** Default constructor returns Catchall object. */ | ||
| 38 | IddObject_Impl(); | ||
| 39 | |||
| 40 | //@} | ||
| 41 | /** @name Getters */ | ||
| 42 | //@{ | ||
| 43 | |||
| 44 | /** Get this IddObject's name. */ | ||
| 45 | std::string name() const; | ||
| 46 | |||
| 47 | /** Get the type of this object, as specified by the OPENSTUDIO_ENUM IddObjectType. type() | ||
| 48 | * is essentially an enum-encoding of name(). type() should be equivalent to | ||
| 49 | * IddObjectType(name()). */ | ||
| 50 | IddObjectType type() const; | ||
| 51 | |||
| 52 | /** Get the name of the Idd group to which this object belongs. */ | ||
| 53 | std::string group() const; | ||
| 54 | |||
| 55 | /** Get the properties of this object. */ | ||
| 56 | const IddObjectProperties& properties() const; | ||
| 57 | |||
| 58 | /** Get all non-extensible \link IddField IddFields\endlink. */ | ||
| 59 | const IddFieldVector& nonextensibleFields() const; | ||
| 60 | |||
| 61 | /** Get this object's extensible group, that is, the vector of extensible \link IddFields | ||
| 62 | * IddField\endlink. */ | ||
| 63 | const IddFieldVector& extensibleGroup() const; | ||
| 64 | |||
| 65 | /** Get the IddField at index, if it exists. Returns fields in extensible groups using the | ||
| 66 | * assumption that extensible groups repeat indefinitely. */ | ||
| 67 | OptionalIddField getField(unsigned index) const; | ||
| 68 | |||
| 69 | /** Get the field named fieldName. Extensible fields are included, but they are not named | ||
| 70 | * uniquely. */ | ||
| 71 | OptionalIddField getField(const std::string& fieldName) const; | ||
| 72 | |||
| 73 | /** Get the index of the IddField named fieldName. */ | ||
| 74 | boost::optional<int> getFieldIndex(const std::string& fieldName) const; | ||
| 75 | |||
| 76 | //@} | ||
| 77 | /** @name Setters */ | ||
| 78 | //@{ | ||
| 79 | |||
| 80 | /** If not already present, inserts a field of type handle at the top of the object. */ | ||
| 81 | void insertHandleField(); | ||
| 82 | |||
| 83 | //@} | ||
| 84 | /** @name Queries */ | ||
| 85 | //@{ | ||
| 86 | |||
| 87 | /** Get number of non-extensible fields. */ | ||
| 88 | unsigned numFields() const; | ||
| 89 | |||
| 90 | /** The original number of fields included in an object constructed by IddObjectType. Accounts | ||
| 91 | * for properties().minFields, properties().numExtensibleGroupsRequired, and | ||
| 92 | * IddField::properties().required. */ | ||
| 93 | unsigned numFieldsInDefaultObject() const; | ||
| 94 | |||
| 95 | /** Returns true if name contains some form of "Version". */ | ||
| 96 | bool isVersionObject() const; | ||
| 97 | |||
| 98 | /** Returns true if index in IdfObject is not part of an extensible group. */ | ||
| 99 | bool isNonextensibleField(unsigned index) const; | ||
| 100 | |||
| 101 | /** Returns true if index in IdfObject would be part of extensible group. */ | ||
| 102 | bool isExtensibleField(unsigned index) const; | ||
| 103 | |||
| 104 | /** Returns true if first IddField is of type handle. */ | ||
| 105 | bool hasHandleField() const; | ||
| 106 | |||
| 107 | /** Returns true if first IddField (after the handle field, if present) is a name. */ | ||
| 108 | bool hasNameField() const; | ||
| 109 | |||
| 110 | /** Returns the index containing the name field, if hasNameField(). Otherwise, returns | ||
| 111 | * boost::none. */ | ||
| 112 | boost::optional<unsigned> nameFieldIndex() const; | ||
| 113 | |||
| 114 | /** Returns true if index in IdfObject corresponds to a required field. */ | ||
| 115 | bool isRequiredField(unsigned index) const; | ||
| 116 | |||
| 117 | /** Get this IddObject's url flag. True if this object has a url in it */ | ||
| 118 | bool hasURL() const; | ||
| 119 | |||
| 120 | /** Returns ExtensibleIndex(groupIndex,fieldIndex) that corresponds to field index. Throws if | ||
| 121 | * !isExtensibleField(index). */ | ||
| 122 | ExtensibleIndex extensibleIndex(unsigned index) const; | ||
| 123 | |||
| 124 | /** Returns the overall IddObject index equivalent to extensibleIndex. Throws if IddObject | ||
| 125 | * is not extensible or if extensibleIndex.field >= properties().numExtensible. */ | ||
| 126 | unsigned index(ExtensibleIndex extensibleIndex) const; | ||
| 127 | |||
| 128 | /** Get the reference lists to which this object belongs. This method only returns supported | ||
| 129 | * reference lists attached to an index 0 name field. */ | ||
| 130 | std::vector<std::string> references() const; | ||
| 131 | |||
| 132 | /// get all the object lists that fields in this object refer to | ||
| 133 | StringSet objectLists() const; | ||
| 134 | |||
| 135 | /// get all the object lists that field index refers to | ||
| 136 | StringSet objectLists(unsigned index) const; | ||
| 137 | |||
| 138 | /// get the indices of the fields of \object-list type. includes indices in the first | ||
| 139 | /// extensible group | ||
| 140 | std::vector<unsigned> objectListFields() const; | ||
| 141 | |||
| 142 | /// get the indices of the fields of \type url | ||
| 143 | std::vector<unsigned> urlFields() const; | ||
| 144 | |||
| 145 | /// equality operator | ||
| 146 | bool operator==(const IddObject_Impl& other) const; | ||
| 147 | |||
| 148 | //@} | ||
| 149 | /** @name Serialization */ | ||
| 150 | //@{ | ||
| 151 | |||
| 152 | /** Load from name, group, type, and text. */ | ||
| 153 | static std::shared_ptr<IddObject_Impl> load(const std::string& name, const std::string& group, const std::string& text, IddObjectType type); | ||
| 154 | |||
| 155 | |||
| 156 | std::ostream& print(std::ostream& os) const; | ||
| 157 | |||
| 158 | //@} | ||
| 159 | |||
| 160 | private: | ||
| 161 | std::string m_name; | ||
| 162 | std::string m_group; // group name | ||
| 163 | IddObjectType m_type; | ||
| 164 | IddObjectProperties m_properties; | ||
| 165 | IddFieldVector m_fields; // vector of non-extensible fields | ||
| 166 | IddFieldVector m_extensibleFields; // vector of extensible fields, forms single | ||
| 167 | // extensible field group | ||
| 168 | std::vector<unsigned> m_urlIdx; | ||
| 169 | // .first = hasNameField(); .second = nameFieldIndex | ||
| 170 | mutable boost::optional<std::pair<bool, unsigned>> m_nameFieldCache; | ||
| 171 | |||
| 172 | // partial constructor used by load | ||
| 173 | IddObject_Impl(const std::string& name, const std::string& group, IddObjectType type); | ||
| 174 | |||
| 175 | // parse | ||
| 176 | void parse(const std::string& text); | ||
| 177 | |||
| 178 | void parseObject(const std::string& text); | ||
| 179 | void parseProperty(const std::string& text); | ||
| 180 | void parseFields(const std::string& text); | ||
| 181 | void makeExtensible(); | ||
| 182 | |||
| 183 | // configure logging | ||
| 184 | − | REGISTER_LOGGER("utilities.idd.IddObject"); | |
| 185 | }; | ||
| 186 | |||
| 187 | } // namespace detail | ||
| 188 | } // namespace openstudio | ||
| 189 | |||
| 190 | #endif // UTILITIES_IDD_IDDOBJECT_IMPL_HPP | ||
| 191 |