| 136 | } // namespace detail |
| 137 | |
| 138 | Component::Component(const openstudio::IdfFile& idfFile) : Model(std::shared_ptr<detail::Component_Impl>(new detail::Component_Impl(idfFile))) { |
| 139 | // construct WorkspaceObject_ImplPtrs |
| 140 | openstudio::detail::WorkspaceObject_ImplPtrVector objectImplPtrs; |
| 141 | if (OptionalIdfObject vo = idfFile.versionObject()) { |
| 142 | objectImplPtrs.push_back(getImpl<detail::Model_Impl>()->createObject(*vo, true)); |
| 143 | } |
| 144 | for (const IdfObject& idfObject : idfFile.objects()) { |
| 145 | objectImplPtrs.push_back(getImpl<detail::Component_Impl>()->createObject(idfObject, true)); |
| 146 | } |
| 147 | // add Object_ImplPtrs to Workspace_Impl |
| 148 | getImpl<openstudio::detail::Workspace_Impl>()->addObjects(objectImplPtrs); |
| 149 | |
| 150 | // check that this really is a component |
| 151 | // 1 Version object |
| 152 | boost::optional<Version> versionObject = getOptionalUniqueModelObject<Version>(); |
| 153 | if (!versionObject) { |
| 154 | LOG_AND_THROW("Cannot construct Component because it does not contain a version object.") |
| 155 | } |
| 156 | |
| 157 | // 1 ComponentData object |
| 158 | ComponentDataVector componentDataObjects = getConcreteModelObjects<ComponentData>(); |
| 159 | if (componentDataObjects.size() != 1) { |
| 160 | LOG_AND_THROW("Cannot construct Component from IdfFile because the file contains " << componentDataObjects.size() << " ComponentData objects."); |
| 161 | } |
| 162 | OS_ASSERT(componentDataObjects.size() == 1); |
| 163 | ComponentData componentData = componentDataObjects[0]; |
| 164 | |
| 165 | // All other objects are Component contents |
| 166 | if (componentData.numComponentObjects() == 0) { |
| 167 | LOG_AND_THROW("Cannot construct Component from IdfFile because there are no objects listed " << "in the contents."); |
| 168 | } |
| 169 | int nNonTrivialObjects = numObjects() - getObjectsByType(IddObjectType::CommentOnly).size(); |
| 170 | if (nNonTrivialObjects != static_cast<int>(componentData.numComponentObjects()) + 1) { |
| 171 | LOG_AND_THROW("Cannot construct Component from IdfFile because the file contains " << nNonTrivialObjects << " non-trivial objects, not " |
| 172 | << componentData.numComponentObjects() + 1u |
| 173 | << ", as expected. The file: " << '\n' |
| 174 | << idfFile); |
| 175 | } |
| 176 | try { |
| 177 | ModelObjectVector componentContents = componentData.componentObjects(); |
| 178 | } catch (...) { |
| 179 | LOG_AND_THROW("Cannot construct Component from IdfFile because at least one of the " << "comprising objects cannot be located."); |
| 180 | } |
| 181 | |
| 182 | getImpl<detail::Model_Impl>()->createComponentWatchers(); |
| 183 | } |
| 184 | |
| 185 | boost::optional<Component> Component::load(const path& p) { |
| 186 | OptionalComponent result; |
nothing calls this directly
no test coverage detected