src/generateiddfactory/GenerateIddFactory.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 "GenerateIddFactory.hpp" | ||
| 7 | #include "WriteEnums.hpp" | ||
| 8 | |||
| 9 | #include <algorithm> | ||
| 10 | #include <iostream> | ||
| 11 | #include <iomanip> | ||
| 12 | #include <cmath> | ||
| 13 | #include <sstream> | ||
| 14 | #include <exception> | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | ✗ | IddFileFactoryDataVector constructIddFileObjects(const std::vector<std::string>& iddArgs) { | |
| 19 | ✗ | IddFileFactoryDataVector result; | |
| 20 | // Construct one IddFileFactoryData object per Idd file input by the user. Constructor will | ||
| 21 | // throw if it is unable to parse iddArg or is unable to validate the path or name. | ||
| 22 | ✗ | for (const std::string& iddArg : iddArgs) { | |
| 23 | ✗ | result.push_back(IddFileFactoryData(iddArg)); | |
| 24 | } | ||
| 25 | ✗ | return result; | |
| 26 | ✗ | } | |
| 27 | |||
| 28 | ✗ | void initializeOutFiles(GenerateIddFactoryOutFiles& outFiles, const std::vector<IddFileFactoryData>& iddFiles) { | |
| 29 | // start IddEnums.hxx | ||
| 30 | outFiles.iddEnumsHxx.tempFile << "#ifndef UTILITIES_IDD_IDDENUMS_HXX" << '\n' | ||
| 31 | << "#define UTILITIES_IDD_IDDENUMS_HXX" << '\n' | ||
| 32 | << '\n' | ||
| 33 | << "#include <utilities/core/Enum.hpp>" << '\n' | ||
| 34 | << '\n' | ||
| 35 | << "#include <boost/optional.hpp>" << '\n' | ||
| 36 | << '\n' | ||
| 37 | << "#include <vector>" << '\n' | ||
| 38 | << "#include <set>" << '\n' | ||
| 39 | << '\n' | ||
| 40 | ✗ | << "namespace openstudio {" << '\n'; | |
| 41 | |||
| 42 | // start IddFieldEnums.hxx | ||
| 43 | outFiles.iddFieldEnumsHxx.tempFile << "#ifndef UTILITIES_IDD_IDDFIELDENUMS_HXX" << '\n' | ||
| 44 | << "#define UTILITIES_IDD_IDDFIELDENUMS_HXX" << '\n' | ||
| 45 | << '\n' | ||
| 46 | << "/** \\file IddFieldEnums.hxx" << '\n' | ||
| 47 | << " * IddFieldEnums.hxx includes one file per IddObjectType (excluding Catchall, UserCustom, " << '\n' | ||
| 48 | << " * and CommentOnly). Each file so included contains one or two OPENSTUDIO_ENUM macros that " << '\n' | ||
| 49 | << " * provide enum and string access to the non-extensible fields and extensible groups of " << '\n' | ||
| 50 | << " * the corresponding IddObjects. This file should not be included directly, but rather, " << '\n' | ||
| 51 | << " * used as a reference to help locate the individual field enum files that should be " << '\n' | ||
| 52 | << " * included in a particular source file. */" << '\n' | ||
| 53 | ✗ | << '\n'; | |
| 54 | |||
| 55 | // start IddFieldEnums.ixx | ||
| 56 | outFiles.iddFieldEnumsIxx.tempFile << "#ifndef UTILITIES_IDD_IDDFIELDENUMS_IXX" << '\n' | ||
| 57 | << "#define UTILITIES_IDD_IDDFIELDENUMS_IXX" << '\n' | ||
| 58 | ✗ | << '\n'; | |
| 59 | |||
| 60 | // write IddFactory.hxx | ||
| 61 | ✗ | outFiles.iddFactoryHxx.tempFile << R"hpp(#ifndef UTILITIES_IDD_IDDFACTORY_HXX | |
| 62 | #define UTILITIES_IDD_IDDFACTORY_HXX | ||
| 63 | |||
| 64 | #include <utilities/UtilitiesAPI.hpp> | ||
| 65 | |||
| 66 | #include <utilities/idd/IddObject.hpp> | ||
| 67 | #include <utilities/idd/IddFile.hpp> | ||
| 68 | #include <utilities/idd/IddEnums.hpp> | ||
| 69 | #include <utilities/idd/IddEnums.hxx> | ||
| 70 | |||
| 71 | #include <utilities/core/Compare.hpp> | ||
| 72 | #include <utilities/core/Logger.hpp> | ||
| 73 | |||
| 74 | #include <map> | ||
| 75 | |||
| 76 | namespace openstudio{ | ||
| 77 | |||
| 78 | /** IddFactory is a Singleton can return \link IddObject IddObjects\endlink and \link IddFile | ||
| 79 | * IddFiles\endlink for the current version of EnergyPlus and OpenStudio. It can return \link IddFile | ||
| 80 | * IddFiles\endlink only (no link with other methods in this class, for instance, no | ||
| 81 | * by-IddObjectType access to individual \link IddObject IddObjects\endlink) for | ||
| 82 | * previous versions of OpenStudio, back to version 0.7.0. It also supports the default IddObject | ||
| 83 | * type, Catchall, which is provided to enable the display of IdfObjects with misspelled type | ||
| 84 | * names, and a CommentOnly object. Its primary function is to establish a single set of IDD schema | ||
| 85 | * across all of OpenStudio, thereby ensuring consistency and reducing file I-O. | ||
| 86 | **/ | ||
| 87 | class UTILITIES_API IddFactory { | ||
| 88 | |||
| 89 | public: | ||
| 90 | |||
| 91 | static IddFactory& instance(); | ||
| 92 | |||
| 93 | IddFactory(const IddFactory& other) = delete; | ||
| 94 | IddFactory(IddFactory&& other) = delete; | ||
| 95 | IddFactory& operator=(const IddFactory&) = delete; | ||
| 96 | IddFactory& operator=(IddFactory&&) = delete; | ||
| 97 | |||
| 98 | /** @name Getters */ | ||
| 99 | //@{ | ||
| 100 | |||
| 101 | /** Get the file version. Throws if fileType == IddFileType::UserCustom or | ||
| 102 | * IddFileType::WholeFactory. */ | ||
| 103 | std::string getVersion(IddFileType fileType) const; | ||
| 104 | |||
| 105 | /** Get the file header. Throws if fileType == IddFileType::UserCustom or | ||
| 106 | * IddFileType::WholeFactory. */ | ||
| 107 | std::string getHeader(IddFileType fileType) const; | ||
| 108 | |||
| 109 | /** Return all \link IddObject IddObjects\endlink registered in factory. */ | ||
| 110 | std::vector<IddObject> objects() const; | ||
| 111 | |||
| 112 | /** Return all \link IddObject IddObjects\endlink in IddFileType type. */ | ||
| 113 | std::vector<IddObject> getObjects(IddFileType fileType) const; | ||
| 114 | |||
| 115 | /** Return all groups in the factory (e.g. "" and "Simulation Parameters"). */ | ||
| 116 | std::vector<std::string> groups() const; | ||
| 117 | |||
| 118 | /** Return all groups in fileType. */ | ||
| 119 | std::vector<std::string> getGroups(IddFileType fileType) const; | ||
| 120 | |||
| 121 | /** Return all \link IddObject IddObjects\endlink in group (e.g. "Simulation Parameters"). */ | ||
| 122 | std::vector<IddObject> getObjectsInGroup(const std::string& group) const; | ||
| 123 | |||
| 124 | /** Return all \link IddObject IddObjects\endlink in group and fileType. */ | ||
| 125 | std::vector<IddObject> getObjectsInGroup(const std::string& group, IddFileType fileType) const; | ||
| 126 | |||
| 127 | /** Return all \link IddObject IddObjects\endlink that match objectRegex. */ | ||
| 128 | std::vector<IddObject> getObjects(const boost::regex& objectRegex) const; | ||
| 129 | |||
| 130 | /** Return all \link IddObject IddObjects\endlink that match objectRegex and are in fileType. */ | ||
| 131 | std::vector<IddObject> getObjects(const boost::regex& objectRegex, IddFileType fileType) const; | ||
| 132 | |||
| 133 | /** Returns the version IddObject for fileType. Throws if fileType == IddFileType::UserCustom | ||
| 134 | * or IddFileType::WholeFactory. */ | ||
| 135 | IddObject getVersionObject(IddFileType fileType) const; | ||
| 136 | |||
| 137 | /** Return the IddObject with .name() objectName, if it exists in the factory. */ | ||
| 138 | boost::optional<IddObject> getObject(const std::string& objectName) const; | ||
| 139 | |||
| 140 | /** Return the IddObject corresponding to objectType. Returns false if type == | ||
| 141 | * IddObjectType::UserCustom. */ | ||
| 142 | boost::optional<IddObject> getObject(IddObjectType objectType) const; | ||
| 143 | |||
| 144 | /** Return all objects in the factory that are required. */ | ||
| 145 | std::vector<IddObject> requiredObjects() const; | ||
| 146 | |||
| 147 | /** Return all objects in IddFile fileType that are required. */ | ||
| 148 | std::vector<IddObject> getRequiredObjects(IddFileType fileType) const; | ||
| 149 | |||
| 150 | /** Return all objects in the factory that are unique. */ | ||
| 151 | std::vector<IddObject> uniqueObjects() const; | ||
| 152 | |||
| 153 | /** Return all objects in IddFile fileType that are unique. */ | ||
| 154 | std::vector<IddObject> getUniqueObjects(IddFileType fileType) const; | ||
| 155 | |||
| 156 | /** Return the (current) IddFile corresponding to type. */ | ||
| 157 | IddFile getIddFile(IddFileType fileType) const; | ||
| 158 | |||
| 159 | /** Return the IddFile corresponding to type and version. Unless version is equal to | ||
| 160 | * VersionString(getVersion(fileType)), files are loaded from disk and returned as | ||
| 161 | * IddFileType::UserCustom, to distinguish them from the IDD information wrapped by | ||
| 162 | * the IddFactory. At this time, only IddFileType::OpenStudio files are supported, | ||
| 163 | * and only for valid version identifiers >= VersionString("0.7.0"). Returns false | ||
| 164 | * in all other cases. */ | ||
| 165 | boost::optional<IddFile> getIddFile(IddFileType fileType, const VersionString& version) const; | ||
| 166 | |||
| 167 | //@} | ||
| 168 | /** @name Queries */ | ||
| 169 | //@{ | ||
| 170 | |||
| 171 | /** Returns true if IddObject of objectType belongs to IddFile of fileType. | ||
| 172 | * IddObjectType::Catchall is in no \link IddFile IddFiles\endlink; | ||
| 173 | * IddObjectType::CommentOnly is in all \link IddFile IddFiles\endlink. */ | ||
| 174 | bool isInFile(IddObjectType objectType, IddFileType fileType) const; | ||
| 175 | |||
| 176 | //@} | ||
| 177 | private: | ||
| 178 | |||
| 179 | IddFactory(); | ||
| 180 | ~IddFactory() = default; | ||
| 181 | )hpp"; | ||
| 182 | |||
| 183 | ✗ | for (const IddFileFactoryData& iddFile : iddFiles) { | |
| 184 | ✗ | outFiles.iddFactoryHxx.tempFile << " void register" << iddFile.fileName() << "ObjectsInCallbackMap();" << '\n'; | |
| 185 | } | ||
| 186 | |||
| 187 | ✗ | outFiles.iddFactoryHxx.tempFile << R"hpp( | |
| 188 | REGISTER_LOGGER("utilities.idd.IddFactory"); | ||
| 189 | |||
| 190 | using CreateIddObjectCallback = std::function<IddObject ()>; | ||
| 191 | using IddObjectCallbackMap = std::map<IddObjectType,CreateIddObjectCallback>; | ||
| 192 | IddObjectCallbackMap m_callbackMap; | ||
| 193 | |||
| 194 | using IddObjectSourceFileMap = std::multimap<IddObjectType,IddFileType>; | ||
| 195 | IddObjectSourceFileMap m_sourceFileMap; | ||
| 196 | |||
| 197 | mutable std::map<VersionString,IddFile> m_osIddFiles; | ||
| 198 | }; | ||
| 199 | |||
| 200 | } // openstudio | ||
| 201 | |||
| 202 | #endif //UTILITIES_IDD_IDDFACTORY_HXX | ||
| 203 | )hpp"; | ||
| 204 | |||
| 205 | // start IddFactory.cxx | ||
| 206 | outFiles.iddFactoryCxx.tempFile << "#include <utilities/idd/IddFactory.hxx>" << '\n' | ||
| 207 | << "#include <utilities/idd/IddEnums.hxx>" << '\n' | ||
| 208 | << "#include <utilities/idd/IddRegex.hpp>" << '\n' | ||
| 209 | << '\n' | ||
| 210 | << "#include <utilities/core/Assert.hpp>" << '\n' | ||
| 211 | << "#include <utilities/core/Compare.hpp>" << '\n' | ||
| 212 | << "#include <utilities/core/Containers.hpp>" << '\n' | ||
| 213 | << "#include <utilities/embedded_files.hxx>" << '\n' | ||
| 214 | << '\n' | ||
| 215 | << "#include <OpenStudio.hxx>" << '\n' | ||
| 216 | << '\n' | ||
| 217 | << "namespace openstudio {" << '\n' | ||
| 218 | << '\n' | ||
| 219 | << "IddObject createCatchallIddObject() {" << '\n' | ||
| 220 | << '\n' | ||
| 221 | << " static const IddObject object;" << '\n' | ||
| 222 | << '\n' | ||
| 223 | << " // Catchall is the type of IddObject returned by the default constructor." << '\n' | ||
| 224 | << " OS_ASSERT(object.type() == IddObjectType::Catchall);" << '\n' | ||
| 225 | << " return object;" << '\n' | ||
| 226 | ✗ | << "}" << '\n'; | |
| 227 | |||
| 228 | // start other IddFactory cxx files | ||
| 229 | ✗ | for (const std::shared_ptr<IddFactoryOutFile>& cxxFile : outFiles.iddFactoryIddFileCxxs) { | |
| 230 | ✗ | cxxFile->tempFile << "#include <utilities/idd/IddFactory.hxx>" << '\n' | |
| 231 | << "#include <utilities/idd/IddEnums.hxx>" << '\n' | ||
| 232 | << '\n' | ||
| 233 | << "#include <utilities/core/Assert.hpp>" << '\n' | ||
| 234 | << "#include <utilities/core/Compare.hpp>" << '\n' | ||
| 235 | << '\n' | ||
| 236 | << '\n' | ||
| 237 | ✗ | << "namespace openstudio {" << '\n'; | |
| 238 | } | ||
| 239 | |||
| 240 | ✗ | std::cout << "IddFactory files initialized." << '\n' << '\n'; | |
| 241 | ✗ | } | |
| 242 | |||
| 243 | ✗ | void completeOutFiles(const IddFileFactoryDataVector& iddFiles, GenerateIddFactoryOutFiles& outFiles) { | |
| 244 | |||
| 245 | ✗ | std::vector<std::pair<std::string, std::string>> filetypes{{"UserCustom", ""}, {"WholeFactory", ""}}; | |
| 246 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 247 | ✗ | filetypes.emplace_back(idd.fileName(), ""); | |
| 248 | } | ||
| 249 | |||
| 250 | ✗ | std::stringstream tempSS; | |
| 251 | ✗ | writeDomain(tempSS, "IddFileType", filetypes, false); | |
| 252 | |||
| 253 | ✗ | outFiles.iddEnumsHxx.tempFile << '\n' << "/** \\class IddFileType */" << '\n' << tempSS.str(); | |
| 254 | ✗ | tempSS.str(""); | |
| 255 | |||
| 256 | ✗ | std::vector<std::pair<std::string, std::string>> objtypes{{"Catchall", ""}, {"UserCustom", ""}}; | |
| 257 | |||
| 258 | // loop through each IDD file | ||
| 259 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 260 | // write out an IddObjectType enum value for each object in the IDD file | ||
| 261 | ✗ | for (const StringPair& objectName : idd.objectNames()) { | |
| 262 | ✗ | objtypes.emplace_back(objectName.first, objectName.second); | |
| 263 | ✗ | } | |
| 264 | } | ||
| 265 | |||
| 266 | ✗ | objtypes.emplace_back("CommentOnly", ""); | |
| 267 | ✗ | writeDomain(tempSS, "IddObjectType", objtypes, false); | |
| 268 | |||
| 269 | outFiles.iddEnumsHxx.tempFile << '\n' | ||
| 270 | << "/** \\class IddObjectType */" << '\n' | ||
| 271 | ✗ | << tempSS.str() << '\n' | |
| 272 | << "}\n" | ||
| 273 | ✗ | << "#endif // UTILITIES_IDD_IDDENUMS_HXX" << '\n'; | |
| 274 | ✗ | tempSS.str(""); | |
| 275 | |||
| 276 | // complete and close IddFieldEnums.hxx | ||
| 277 | ✗ | outFiles.iddFieldEnumsHxx.tempFile << '\n' << "#endif // UTILITIES_IDD_IDDFIELDENUMS_HXX" << '\n'; | |
| 278 | |||
| 279 | // complete and close IddFieldEnums.ixx | ||
| 280 | ✗ | outFiles.iddFieldEnumsIxx.tempFile << '\n' << "#endif // UTILITIES_IDD_IDDFIELDENUMS_IXX" << '\n'; | |
| 281 | |||
| 282 | // complete and close IddFactory.cxx | ||
| 283 | |||
| 284 | // create function for CommentOnly IddObject | ||
| 285 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 286 | << "IddObject createCommentOnlyIddObject() {" << '\n' | ||
| 287 | << '\n' | ||
| 288 | << " static const IddObject object = []{" << '\n' | ||
| 289 | << " // use C++11 statics and initialize on first use idiom to ensure static" << '\n' | ||
| 290 | << " // is initialized safely exactly once, eliminating need for mutexes" << '\n' | ||
| 291 | << " std::stringstream ss;" << '\n' | ||
| 292 | << " ss << \"CommentOnly; ! Autogenerated comment only object.\" << '\\n';" << '\n' | ||
| 293 | << '\n' | ||
| 294 | << " IddObjectType objType(IddObjectType::CommentOnly);" << '\n' | ||
| 295 | << " OptionalIddObject oObj = IddObject::load(\"CommentOnly\"," << '\n' | ||
| 296 | << " \"\"," << '\n' | ||
| 297 | << " ss.str()," << '\n' | ||
| 298 | << " objType);" << '\n' | ||
| 299 | << " OS_ASSERT(oObj);" << '\n' | ||
| 300 | << " return *oObj;" << '\n' | ||
| 301 | << " }(); // immediately invoked lambda" << '\n' | ||
| 302 | << '\n' | ||
| 303 | << " return object;" << '\n' | ||
| 304 | << "}" << '\n' | ||
| 305 | ✗ | << '\n'; | |
| 306 | |||
| 307 | // static instance as a Singleton | ||
| 308 | ✗ | outFiles.iddFactoryCxx.tempFile << R"cpp(IddFactory& IddFactory::instance() { | |
| 309 | static IddFactory instance; | ||
| 310 | return instance; | ||
| 311 | } | ||
| 312 | |||
| 313 | )cpp"; | ||
| 314 | |||
| 315 | // constructor | ||
| 316 | ✗ | outFiles.iddFactoryCxx.tempFile << "IddFactory::IddFactory() {" << '\n' << '\n' << " // initialize callback map" << '\n' << '\n'; | |
| 317 | // register create functions in the callback map | ||
| 318 | // Catchall | ||
| 319 | outFiles.iddFactoryCxx.tempFile << " m_callbackMap.insert(IddObjectCallbackMap::value_type(IddObjectType::Catchall," | ||
| 320 | ✗ | << "createCatchallIddObject));" << '\n'; | |
| 321 | // parsed objects | ||
| 322 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 323 | ✗ | outFiles.iddFactoryCxx.tempFile << " register" << idd.fileName() << "ObjectsInCallbackMap();" << '\n'; | |
| 324 | } | ||
| 325 | // CommentOnly | ||
| 326 | outFiles.iddFactoryCxx.tempFile << " m_callbackMap.insert(IddObjectCallbackMap::value_type(IddObjectType::CommentOnly," | ||
| 327 | << "createCommentOnlyIddObject));" << '\n' | ||
| 328 | << '\n' | ||
| 329 | << " // instantiate IddObjectType to IddFileType multimap" << '\n' | ||
| 330 | ✗ | << '\n'; | |
| 331 | // register IddObjectTypes with IddFileTypes | ||
| 332 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 333 | ✗ | std::string fileName = idd.fileName(); | |
| 334 | |||
| 335 | // register local objects | ||
| 336 | ✗ | for (const StringPair& objectName : idd.objectNames()) { | |
| 337 | ✗ | outFiles.iddFactoryCxx.tempFile << " m_sourceFileMap.insert(IddObjectSourceFileMap::value_type(IddObjectType::" << objectName.first | |
| 338 | ✗ | << ",IddFileType::" << fileName << "));" << '\n'; | |
| 339 | ✗ | } | |
| 340 | |||
| 341 | // register imported objects | ||
| 342 | ✗ | for (unsigned i = 0, ni = idd.numIncludedFiles(); i < ni; ++i) { | |
| 343 | /* Included files are identified by name. Optionally, there may be a list of removed objects | ||
| 344 | that should not be inherited by the composite file. */ | ||
| 345 | ✗ | IddFileFactoryData::FileNameRemovedObjectsPair includedFileData = idd.includedFile(i); | |
| 346 | // Get the included file by name. Will throw if there is no match. | ||
| 347 | ✗ | IddFileFactoryData includedFile = getFile(includedFileData.first, iddFiles); | |
| 348 | |||
| 349 | ✗ | std::vector<std::string> excludedObjects; | |
| 350 | ✗ | for (const StringPair& objectName : includedFile.objectNames()) { | |
| 351 | |||
| 352 | // If objectName is in list of removed objects, do not add it to m_sourceFileMap, | ||
| 353 | ✗ | if (std::find(includedFileData.second.begin(), includedFileData.second.end(), objectName.first) != includedFileData.second.end()) { | |
| 354 | // and keep its name in case we need to write a warning. | ||
| 355 | ✗ | excludedObjects.push_back(objectName.first); | |
| 356 | ✗ | continue; | |
| 357 | } | ||
| 358 | |||
| 359 | // objectName is not to be removed, so add it to the composite file. | ||
| 360 | ✗ | outFiles.iddFactoryCxx.tempFile << " m_sourceFileMap.insert(IddObjectSourceFileMap::value_type(IddObjectType::" << objectName.first | |
| 361 | ✗ | << ",IddFileType::" << fileName << "));" << '\n'; | |
| 362 | |||
| 363 | ✗ | } // foreach | |
| 364 | |||
| 365 | // Write warning if we did not encounter all of the objects that were to be removed. | ||
| 366 | ✗ | if (excludedObjects.size() != includedFileData.second.size()) { | |
| 367 | std::cout << "Warning: Did not encounter all 'objects to remove' while including file " << '\n' | ||
| 368 | << "'" << includedFileData.first << "' in file '" << fileName << "'." << '\n' | ||
| 369 | << "\\remove-object Tags Objects Actually Removed " << '\n' | ||
| 370 | ✗ | << "------------------------- -------------------------" << '\n'; | |
| 371 | ✗ | for (int x = 0, y = 0, nx = includedFileData.second.size(), ny = excludedObjects.size(); (x < nx) || (y < ny); ++x, ++y) { | |
| 372 | ✗ | if (x < nx) { | |
| 373 | ✗ | std::cout << std::setw(25) << includedFileData.second[x] << " "; | |
| 374 | } else { | ||
| 375 | ✗ | std::cout << std::setw(25) << " " << " "; | |
| 376 | } | ||
| 377 | ✗ | if (y < ny) { | |
| 378 | ✗ | std::cout << std::setw(25) << excludedObjects[y] << '\n'; | |
| 379 | } else { | ||
| 380 | ✗ | std::cout << std::setw(25) << " " << '\n'; | |
| 381 | } | ||
| 382 | } // for | ||
| 383 | } // if | ||
| 384 | |||
| 385 | ✗ | } // for | |
| 386 | |||
| 387 | // Register CommentOnly object for all files. | ||
| 388 | outFiles.iddFactoryCxx.tempFile << " m_sourceFileMap.insert(IddObjectSourceFileMap::value_type(IddObjectType::CommentOnly" | ||
| 389 | ✗ | << ",IddFileType::" << fileName << "));" << '\n'; | |
| 390 | ✗ | } | |
| 391 | ✗ | outFiles.iddFactoryCxx.tempFile << '\n' << "}" << '\n'; | |
| 392 | |||
| 393 | // version and header getters | ||
| 394 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 395 | << "std::string IddFactory::getVersion(IddFileType fileType) const {" << '\n' | ||
| 396 | << " std::string result;" << '\n' | ||
| 397 | << '\n' | ||
| 398 | ✗ | << " switch (fileType.value()) {" << '\n'; | |
| 399 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 400 | ✗ | outFiles.iddFactoryCxx.tempFile << " case IddFileType::" << idd.fileName() << " :" << '\n' | |
| 401 | ✗ | << " result = \"" << idd.version() << "\";" << '\n' | |
| 402 | ✗ | << " break;" << '\n'; | |
| 403 | } | ||
| 404 | outFiles.iddFactoryCxx.tempFile << " default :" << '\n' | ||
| 405 | << " LOG_AND_THROW(\"No version to return for IddFileType \" << fileType.valueDescription() << \".\");" << '\n' | ||
| 406 | << " } // switch" << '\n' | ||
| 407 | << '\n' | ||
| 408 | << " return result;" << '\n' | ||
| 409 | << "}" << '\n' | ||
| 410 | << '\n' | ||
| 411 | << "std::string IddFactory::getHeader(IddFileType fileType) const {" << '\n' | ||
| 412 | << " std::stringstream result;" << '\n' | ||
| 413 | ✗ | << " switch (fileType.value()) {" << '\n'; | |
| 414 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 415 | ✗ | outFiles.iddFactoryCxx.tempFile << " case IddFileType::" << idd.fileName() << " :" << '\n' << " result"; | |
| 416 | ✗ | std::stringstream headerStream(idd.header()); | |
| 417 | ✗ | std::string line; | |
| 418 | ✗ | while (std::getline(headerStream, line)) { | |
| 419 | ✗ | outFiles.iddFactoryCxx.tempFile << '\n' << " << \"" << line << "\" << '\\n'"; | |
| 420 | } | ||
| 421 | // print information about included files | ||
| 422 | ✗ | for (unsigned i = 0, ni = idd.numIncludedFiles(); i < ni; ++i) { | |
| 423 | ✗ | IddFileFactoryData::FileNameRemovedObjectsPair includedFileData = idd.includedFile(i); | |
| 424 | ✗ | IddFileFactoryData includedFile = getFile(includedFileData.first, iddFiles); | |
| 425 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 426 | << " << \"!\\n\"" << '\n' | ||
| 427 | << " << \"! **************************************************************************\\n\"" << '\n' | ||
| 428 | ✗ | << " << \"! Includes File: '" << includedFile.fileName() << "'\\n\"" << '\n' | |
| 429 | << " << \"!\\n\"" << '\n' | ||
| 430 | ✗ | << " << \"! Contains all objects from " << includedFile.fileName() << " IDD_Version " | |
| 431 | ✗ | << includedFile.version() << ", except: \\n\"" << '\n'; | |
| 432 | ✗ | for (const std::string& objectName : includedFileData.second) { | |
| 433 | ✗ | outFiles.iddFactoryCxx.tempFile << " << \"! " << objectName << "\\n\"" << '\n'; | |
| 434 | } | ||
| 435 | ✗ | outFiles.iddFactoryCxx.tempFile << " << \"! **************************************************************************\\n\""; | |
| 436 | ✗ | } | |
| 437 | ✗ | outFiles.iddFactoryCxx.tempFile << ";" << '\n' << '\n' << " break;" << '\n'; | |
| 438 | ✗ | } | |
| 439 | outFiles.iddFactoryCxx.tempFile << " default :" << '\n' | ||
| 440 | << " LOG_AND_THROW(\"No header to return for IddFileType \" << fileType.valueDescription() << \".\");" << '\n' | ||
| 441 | << " } // switch" << '\n' | ||
| 442 | << " return result.str();" << '\n' | ||
| 443 | ✗ | << "}" << '\n'; | |
| 444 | |||
| 445 | // object getters | ||
| 446 | outFiles.iddFactoryCxx.tempFile | ||
| 447 | << '\n' | ||
| 448 | << "std::vector<IddObject> IddFactory::objects() const {" << '\n' | ||
| 449 | << " IddObjectVector result;" << '\n' | ||
| 450 | << '\n' | ||
| 451 | << " for (IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 452 | << " itEnd = m_callbackMap.end(); it != itEnd; ++it) {" << '\n' | ||
| 453 | << " result.push_back(it->second());" << '\n' | ||
| 454 | << " }" << '\n' | ||
| 455 | << '\n' | ||
| 456 | << " return result;" << '\n' | ||
| 457 | << "}" << '\n' | ||
| 458 | << '\n' | ||
| 459 | << "std::vector<IddObject> IddFactory::getObjects(IddFileType fileType) const {" << '\n' | ||
| 460 | << " IddObjectVector result;" << '\n' | ||
| 461 | << '\n' | ||
| 462 | << " for(IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 463 | << " itend = m_callbackMap.end(); it != itend; ++it) {" << '\n' | ||
| 464 | << " if (isInFile(it->first,fileType)) { " << '\n' | ||
| 465 | << " result.push_back(it->second()); " << '\n' | ||
| 466 | << " }" << '\n' | ||
| 467 | << " }" << '\n' | ||
| 468 | << '\n' | ||
| 469 | << " return result;" << '\n' | ||
| 470 | << "}" << '\n' | ||
| 471 | << '\n' | ||
| 472 | << "std::vector<std::string> IddFactory::groups() const {" << '\n' | ||
| 473 | << " StringSet result;" << '\n' | ||
| 474 | << " for (const IddObject& object : objects()) {" << '\n' | ||
| 475 | << " result.insert(object.group());" << '\n' | ||
| 476 | << " }" << '\n' | ||
| 477 | << " return StringVector(result.begin(),result.end());" << '\n' | ||
| 478 | << "}" << '\n' | ||
| 479 | << '\n' | ||
| 480 | << "std::vector<std::string> IddFactory::getGroups(IddFileType fileType) const {" << '\n' | ||
| 481 | << " StringSet result;" << '\n' | ||
| 482 | << " for (const IddObject& object : getObjects(fileType)) {" << '\n' | ||
| 483 | << " result.insert(object.group());" << '\n' | ||
| 484 | << " }" << '\n' | ||
| 485 | << " return StringVector(result.begin(),result.end());" << '\n' | ||
| 486 | << "}" << '\n' | ||
| 487 | << '\n' | ||
| 488 | << "std::vector<IddObject> IddFactory::getObjectsInGroup(const std::string& group) const {" << '\n' | ||
| 489 | << " IddObjectVector result;" << '\n' | ||
| 490 | << " for (const IddObject& object : objects()) {" << '\n' | ||
| 491 | << " if (istringEqual(object.group(),group)) {" << '\n' | ||
| 492 | << " result.push_back(object);" << '\n' | ||
| 493 | << " }" << '\n' | ||
| 494 | << " }" << '\n' | ||
| 495 | << " return result;" << '\n' | ||
| 496 | << "}" << '\n' | ||
| 497 | << '\n' | ||
| 498 | << "std::vector<IddObject> IddFactory::getObjectsInGroup(const std::string& group, IddFileType fileType) const {" << '\n' | ||
| 499 | << " IddObjectVector result;" << '\n' | ||
| 500 | << " for (const IddObject& object : getObjects(fileType)) {" << '\n' | ||
| 501 | << " if (istringEqual(object.group(),group)) {" << '\n' | ||
| 502 | << " result.push_back(object);" << '\n' | ||
| 503 | << " }" << '\n' | ||
| 504 | << " }" << '\n' | ||
| 505 | << " return result;" << '\n' | ||
| 506 | << "}" << '\n' | ||
| 507 | << '\n' | ||
| 508 | << "std::vector<IddObject> IddFactory::getObjects(const boost::regex& objectRegex) const {" << '\n' | ||
| 509 | << " IddObjectVector result;" << '\n' | ||
| 510 | << '\n' | ||
| 511 | << " for (int value : IddObjectType::getValues()) {" << '\n' | ||
| 512 | << " IddObjectType candidate(value);" << '\n' | ||
| 513 | << " if (boost::regex_match(candidate.valueName(),objectRegex) || " << '\n' | ||
| 514 | << " boost::regex_match(candidate.valueDescription(),objectRegex))" << '\n' | ||
| 515 | << " {" << '\n' | ||
| 516 | << " if (OptionalIddObject object = getObject(candidate)) {" << '\n' | ||
| 517 | << " result.push_back(*object);" << '\n' | ||
| 518 | << " }" << '\n' | ||
| 519 | << " }" << '\n' | ||
| 520 | << " }" << '\n' | ||
| 521 | << '\n' | ||
| 522 | << " return result;" << '\n' | ||
| 523 | << "}" << '\n' | ||
| 524 | << '\n' | ||
| 525 | << "std::vector<IddObject> IddFactory::getObjects(const boost::regex& objectRegex," << '\n' | ||
| 526 | << " IddFileType fileType) const " << '\n' | ||
| 527 | << "{" << '\n' | ||
| 528 | << " IddObjectVector result;" << '\n' | ||
| 529 | << '\n' | ||
| 530 | << " for (int value : IddObjectType::getValues()) {" << '\n' | ||
| 531 | << " IddObjectType candidate(value);" << '\n' | ||
| 532 | << " if (isInFile(candidate,fileType) && " << '\n' | ||
| 533 | << " (boost::regex_match(candidate.valueName(),objectRegex) || " << '\n' | ||
| 534 | << " boost::regex_match(candidate.valueDescription(),objectRegex)))" << '\n' | ||
| 535 | << " {" << '\n' | ||
| 536 | << " if (OptionalIddObject object = getObject(candidate)) {" << '\n' | ||
| 537 | << " result.push_back(*object);" << '\n' | ||
| 538 | << " }" << '\n' | ||
| 539 | << " }" << '\n' | ||
| 540 | << " }" << '\n' | ||
| 541 | << '\n' | ||
| 542 | << " return result;" << '\n' | ||
| 543 | << "}" << '\n' | ||
| 544 | << '\n' | ||
| 545 | << "IddObject IddFactory::getVersionObject(IddFileType fileType) const {" << '\n' | ||
| 546 | << " if (fileType == IddFileType::EnergyPlus) {" << '\n' | ||
| 547 | << " return getObject(IddObjectType(IddObjectType::Version)).get();" << '\n' | ||
| 548 | << " }" << '\n' | ||
| 549 | << '\n' | ||
| 550 | << " if (fileType == IddFileType::OpenStudio) {" << '\n' | ||
| 551 | << " return getObject(IddObjectType(IddObjectType::OS_Version)).get();" << '\n' | ||
| 552 | << " }" << '\n' | ||
| 553 | << '\n' | ||
| 554 | << " LOG_AND_THROW(\"Unable to identify unique version object for IddFileType \" << fileType.valueName() << \".\");" << '\n' | ||
| 555 | << " return IddObject();" << '\n' | ||
| 556 | << "}" << '\n' | ||
| 557 | << '\n' | ||
| 558 | << "boost::optional<IddObject> IddFactory::getObject(const std::string& objectName) const" << '\n' | ||
| 559 | << "{" << '\n' | ||
| 560 | << " OptionalIddObject result;" << '\n' | ||
| 561 | << '\n' | ||
| 562 | << " // let IddObjectType OPENSTUDIO_ENUM handle the string processing" << '\n' | ||
| 563 | << " try {" << '\n' | ||
| 564 | << " IddObjectType objectType(objectName);" << '\n' | ||
| 565 | << " result = getObject(objectType);" << '\n' | ||
| 566 | << " }" << '\n' | ||
| 567 | << " catch (...) {}" << '\n' | ||
| 568 | << '\n' | ||
| 569 | << " return result;" << '\n' | ||
| 570 | << "}" << '\n' | ||
| 571 | << '\n' | ||
| 572 | << "boost::optional<IddObject> IddFactory::getObject(IddObjectType objectType) const" << '\n' | ||
| 573 | << "{" << '\n' | ||
| 574 | << " OptionalIddObject result;" << '\n' | ||
| 575 | << '\n' | ||
| 576 | << " IddObjectCallbackMap::const_iterator lookupPair;" << '\n' | ||
| 577 | << " lookupPair = m_callbackMap.find(objectType);" << '\n' | ||
| 578 | << " if (lookupPair != m_callbackMap.end()) { " << '\n' | ||
| 579 | << " result = lookupPair->second(); " << '\n' | ||
| 580 | << " }" << '\n' | ||
| 581 | << " else { " << '\n' | ||
| 582 | << " OS_ASSERT(objectType == IddObjectType::UserCustom); " << '\n' | ||
| 583 | << " LOG(Info,\"UserCustom objects are not available through the IddFactory. Please query your IddFile by IddObject.name().\");" << '\n' | ||
| 584 | << " }" << '\n' | ||
| 585 | << '\n' | ||
| 586 | << " return result;" << '\n' | ||
| 587 | ✗ | << "}" << '\n'; | |
| 588 | |||
| 589 | // required, unique, and required or unique objects | ||
| 590 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 591 | << "std::vector<IddObject> IddFactory::requiredObjects() const {" << '\n' | ||
| 592 | << '\n' | ||
| 593 | << " IddObjectVector result;" << '\n' | ||
| 594 | << '\n' | ||
| 595 | << " for (IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 596 | << " itEnd = m_callbackMap.end(); it != itEnd; ++it) {" << '\n' | ||
| 597 | << " const auto candidate = it->second();" << '\n' | ||
| 598 | << " if (candidate.properties().required) {" << '\n' | ||
| 599 | << " result.push_back(candidate);" << '\n' | ||
| 600 | << " }" << '\n' | ||
| 601 | << " }" << '\n' | ||
| 602 | << '\n' | ||
| 603 | << " return result;" << '\n' | ||
| 604 | << "}" << '\n' | ||
| 605 | << '\n' | ||
| 606 | << "std::vector<IddObject> IddFactory::getRequiredObjects(IddFileType fileType) const {" << '\n' | ||
| 607 | << '\n' | ||
| 608 | << " IddObjectVector result; " << '\n' | ||
| 609 | << '\n' | ||
| 610 | << " for(IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 611 | << " itEnd = m_callbackMap.end(); it != itEnd; ++it) {" << '\n' | ||
| 612 | << " if (isInFile(it->first,fileType)) {" << '\n' | ||
| 613 | << " OptionalIddObject candidate = getObject(it->first);" << '\n' | ||
| 614 | << " if (candidate->properties().required) {" << '\n' | ||
| 615 | << " result.push_back(*candidate);" << '\n' | ||
| 616 | << " }" << '\n' | ||
| 617 | << " }" << '\n' | ||
| 618 | << " }" << '\n' | ||
| 619 | << '\n' | ||
| 620 | << " return result;" << '\n' | ||
| 621 | << "}" << '\n' | ||
| 622 | << '\n' | ||
| 623 | << "std::vector<IddObject> IddFactory::uniqueObjects() const {" << '\n' | ||
| 624 | << '\n' | ||
| 625 | << " IddObjectVector result;" << '\n' | ||
| 626 | << '\n' | ||
| 627 | << " for (IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 628 | << " itEnd = m_callbackMap.end(); it != itEnd; ++it) {" << '\n' | ||
| 629 | << " const auto candidate = it->second();" << '\n' | ||
| 630 | << " if (candidate.properties().unique) {" << '\n' | ||
| 631 | << " result.push_back(candidate);" << '\n' | ||
| 632 | << " }" << '\n' | ||
| 633 | << " }" << '\n' | ||
| 634 | << '\n' | ||
| 635 | << " return result;" << '\n' | ||
| 636 | << "}" << '\n' | ||
| 637 | << '\n' | ||
| 638 | << "std::vector<IddObject> IddFactory::getUniqueObjects(IddFileType fileType) const {" << '\n' | ||
| 639 | << '\n' | ||
| 640 | << " IddObjectVector result; " << '\n' | ||
| 641 | << '\n' | ||
| 642 | << " for(IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 643 | << " itEnd = m_callbackMap.end(); it != itEnd; ++it) {" << '\n' | ||
| 644 | << " if (isInFile(it->first,fileType)) {" << '\n' | ||
| 645 | << " OptionalIddObject candidate = getObject(it->first);" << '\n' | ||
| 646 | << " if (candidate->properties().unique) {" << '\n' | ||
| 647 | << " result.push_back(*candidate);" << '\n' | ||
| 648 | << " }" << '\n' | ||
| 649 | << " }" << '\n' | ||
| 650 | << " }" << '\n' | ||
| 651 | << '\n' | ||
| 652 | << " return result;" << '\n' | ||
| 653 | << '\n' | ||
| 654 | ✗ | << "}" << '\n'; | |
| 655 | |||
| 656 | // iddFile getters | ||
| 657 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 658 | << "IddFile IddFactory::getIddFile(IddFileType fileType) const {" << '\n' | ||
| 659 | << " IddFile result;" << '\n' | ||
| 660 | << '\n' | ||
| 661 | << " if (fileType == IddFileType::UserCustom) {" << '\n' | ||
| 662 | << " return result; " << '\n' | ||
| 663 | << " }" << '\n' | ||
| 664 | << '\n' | ||
| 665 | << " // Add the IddObjects." << '\n' | ||
| 666 | << " for(IddObjectCallbackMap::const_iterator it = m_callbackMap.begin()," << '\n' | ||
| 667 | << " itend = m_callbackMap.end(); it != itend; ++it) {" << '\n' | ||
| 668 | << " if (isInFile(it->first,fileType)) {" << '\n' | ||
| 669 | << " result.addObject(it->second());" << '\n' | ||
| 670 | << " }" << '\n' | ||
| 671 | << " }" << '\n' | ||
| 672 | << '\n' | ||
| 673 | << " // Set the file version and header." << '\n' | ||
| 674 | << " try {" << '\n' | ||
| 675 | << " result.setVersion(getVersion(fileType));" << '\n' | ||
| 676 | << " result.setHeader(getHeader(fileType));" << '\n' | ||
| 677 | << " }" << '\n' | ||
| 678 | << " catch (...) {}" << '\n' | ||
| 679 | << '\n' | ||
| 680 | << " return result;" << '\n' | ||
| 681 | << "}" << '\n' | ||
| 682 | << '\n' | ||
| 683 | << "boost::optional<IddFile> IddFactory::getIddFile(IddFileType fileType, const VersionString& version) const {" | ||
| 684 | << '\n' | ||
| 685 | << " OptionalIddFile result;" << '\n' | ||
| 686 | << '\n' | ||
| 687 | << " if (fileType == IddFileType::UserCustom) {" << '\n' | ||
| 688 | << " return result; " << '\n' | ||
| 689 | << " }" << '\n' | ||
| 690 | << '\n' | ||
| 691 | << " if (fileType == IddFileType::WholeFactory) {" << '\n' | ||
| 692 | << " LOG(Warn,\"Cannot return the WholeFactory IddFile by version.\");" << '\n' | ||
| 693 | << " return result;" << '\n' | ||
| 694 | << " }" << '\n' | ||
| 695 | << '\n' | ||
| 696 | << " if (fileType == IddFileType::EnergyPlus) {" << '\n' | ||
| 697 | << " LOG(Warn,\"At this time, OpenStudio cannot return EnergyPlus IDD files by version.\");" << '\n' | ||
| 698 | << " return result;" << '\n' | ||
| 699 | << " }" << '\n' | ||
| 700 | << '\n' | ||
| 701 | << " VersionString currentVersion(openStudioVersion());" << '\n' | ||
| 702 | << " OS_ASSERT(fileType == IddFileType::OpenStudio);" << '\n' | ||
| 703 | << " if (version == currentVersion) {" << '\n' | ||
| 704 | << " return getIddFile(fileType);" << '\n' | ||
| 705 | << " }" << '\n' | ||
| 706 | << " else {" << '\n' | ||
| 707 | << " std::map<VersionString, IddFile>::const_iterator it = m_osIddFiles.find(version);" << '\n' | ||
| 708 | << " if (it != m_osIddFiles.end()) {" << '\n' | ||
| 709 | << " return it->second;" << '\n' | ||
| 710 | << " }" << '\n' | ||
| 711 | << " std::string iddPath = \":/idd/versions\";" << '\n' | ||
| 712 | << " std::stringstream folderString;" << '\n' | ||
| 713 | << " folderString << version.major() << \"_\" << version.minor() << \"_\" << version.patch().get();" << '\n' | ||
| 714 | << " iddPath += \"/\" + folderString.str() + \"/OpenStudio.idd\";" << '\n' | ||
| 715 | << " if (::openstudio::embedded_files::hasFile(iddPath) && (version < currentVersion)) {" << '\n' | ||
| 716 | << " std::stringstream ss;" << '\n' | ||
| 717 | << " ss << ::openstudio::embedded_files::getFileAsString(iddPath);" << '\n' | ||
| 718 | << " result = IddFile::load(ss);" << '\n' | ||
| 719 | << " }" << '\n' | ||
| 720 | << " if (result) {" << '\n' | ||
| 721 | << " m_osIddFiles[version] = *result;" << '\n' | ||
| 722 | << " }" << '\n' | ||
| 723 | << " }" << '\n' | ||
| 724 | << " return result;" << '\n' | ||
| 725 | ✗ | << "}" << '\n'; | |
| 726 | |||
| 727 | // query whether object is in file | ||
| 728 | outFiles.iddFactoryCxx.tempFile << '\n' | ||
| 729 | << "bool IddFactory::isInFile(IddObjectType objectType, IddFileType fileType) const {" << '\n' | ||
| 730 | << " typedef IddObjectSourceFileMap::const_iterator const_iterator;" << '\n' | ||
| 731 | << " std::pair<const_iterator,const_iterator> range;" << '\n' | ||
| 732 | << " range = m_sourceFileMap.equal_range(objectType);" << '\n' | ||
| 733 | << " for (const_iterator it = range.first; it != range.second; ++it) {" << '\n' | ||
| 734 | << " if ((it->second == fileType) || (fileType == IddFileType::WholeFactory)) {" << '\n' | ||
| 735 | << " return true;" << '\n' | ||
| 736 | << " }" << '\n' | ||
| 737 | << " }" << '\n' | ||
| 738 | << '\n' | ||
| 739 | << " return false;" << '\n' | ||
| 740 | ✗ | << "}" << '\n'; | |
| 741 | |||
| 742 | // Implementation for IddObjectType and IddFileType | ||
| 743 | ✗ | writeBuildStringVec(outFiles.iddFactoryCxx.tempFile, "IddObjectType", objtypes, false); | |
| 744 | ✗ | writeBuildStringVec(outFiles.iddFactoryCxx.tempFile, "IddFileType", filetypes, false); | |
| 745 | |||
| 746 | // close out file | ||
| 747 | ✗ | outFiles.iddFactoryCxx.tempFile << '\n' << "} // openstudio" << '\n'; | |
| 748 | |||
| 749 | // close out other IddFactory cxx files | ||
| 750 | ✗ | for (const std::shared_ptr<IddFactoryOutFile>& cxxFile : outFiles.iddFactoryIddFileCxxs) { | |
| 751 | ✗ | cxxFile->tempFile << '\n' << "} // openstudio" << '\n'; | |
| 752 | } | ||
| 753 | |||
| 754 | ✗ | outFiles.finalize(); | |
| 755 | |||
| 756 | ✗ | std::cout << "IddFactory files generated." << '\n'; | |
| 757 | ✗ | } | |
| 758 | |||
| 759 | ✗ | IddFileFactoryData getFile(const std::string& fileName, const IddFileFactoryDataVector& iddFiles) { | |
| 760 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 761 | ✗ | if (idd.fileName() == fileName) { | |
| 762 | ✗ | return idd; | |
| 763 | } | ||
| 764 | } | ||
| 765 | |||
| 766 | // unsuccessful search, throw an informative message | ||
| 767 | ✗ | std::stringstream ss; | |
| 768 | ✗ | ss << "Unable to located included Idd file '" << fileName << "' in list of Idd files. " << "The available files are named:" << '\n'; | |
| 769 | ✗ | for (const IddFileFactoryData& idd : iddFiles) { | |
| 770 | ✗ | ss << " " << idd.fileName() << '\n'; | |
| 771 | } | ||
| 772 | ✗ | throw std::runtime_error(ss.str().c_str()); | |
| 773 | ✗ | } | |
| 774 | |||
| 775 | } // namespace openstudio | ||
| 776 |