src/utilities/idf/ImfFile.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_IDF_IMFFILE_HPP | ||
| 7 | #define UTILITIES_IDF_IMFFILE_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | |||
| 11 | #include "IdfObject.hpp" | ||
| 12 | |||
| 13 | #include "../idd/IddObject.hpp" | ||
| 14 | #include "../idd/IddFileAndFactoryWrapper.hpp" | ||
| 15 | |||
| 16 | #include "../core/Path.hpp" | ||
| 17 | #include "../core/Containers.hpp" | ||
| 18 | |||
| 19 | #include <string> | ||
| 20 | #include <ostream> | ||
| 21 | #include <vector> | ||
| 22 | #include <map> | ||
| 23 | |||
| 24 | namespace openstudio { | ||
| 25 | |||
| 26 | /** ImfFile represents an Imf file. ImfFile does not have any copy | ||
| 27 | * or assignment operators so it is not a shared object. ImfFile | ||
| 28 | * does not support advanced imf syntax, only sectioning by | ||
| 29 | * \code | ||
| 30 | * ##def Schedules[] | ||
| 31 | * \endcode | ||
| 32 | * , etc. | ||
| 33 | */ | ||
| 34 | class UTILITIES_API ImfFile | ||
| 35 | { | ||
| 36 | public: | ||
| 37 | /** @name Constructors */ | ||
| 38 | //@{ | ||
| 39 | |||
| 40 | /// default constructor | ||
| 41 | ImfFile(IddFileType iddFileType = IddFileType("EnergyPlus")); | ||
| 42 | |||
| 43 | //@} | ||
| 44 | /** @name Getters */ | ||
| 45 | //@{ | ||
| 46 | |||
| 47 | /** Get the IddFile. If one is not explicitly held by this object, returns one from | ||
| 48 | * IddFactory per the documentation for this class. */ | ||
| 49 | IddFile iddFile() const; | ||
| 50 | |||
| 51 | /** Get the IddFile's IddFileType. */ | ||
| 52 | IddFileType iddFileType() const; | ||
| 53 | |||
| 54 | /** Return the names of all sections. */ | ||
| 55 | StringVector sectionNames() const; | ||
| 56 | |||
| 57 | /** Get a section by name */ | ||
| 58 | IdfObjectVector section(const std::string& section) const; | ||
| 59 | |||
| 60 | //@} | ||
| 61 | /** @name Queries */ | ||
| 62 | //@{ | ||
| 63 | |||
| 64 | /** Return the number of sections in the ImfFile */ | ||
| 65 | unsigned numSections() const; | ||
| 66 | |||
| 67 | //@} | ||
| 68 | /** @name Serialization */ | ||
| 69 | //@{ | ||
| 70 | |||
| 71 | /// load file from std::istream. assumes objects are in sub-idd file fileType of IddFactory. | ||
| 72 | static boost::optional<ImfFile> load(std::istream& is, IddFileType iddFileType); | ||
| 73 | |||
| 74 | /// load file from std::istream. use user-supplied IddFile. | ||
| 75 | static boost::optional<ImfFile> load(std::istream& is, const IddFile& iddFile); | ||
| 76 | |||
| 77 | /// load from file path | ||
| 78 | static boost::optional<ImfFile> load(const openstudio::path& p, IddFileType iddFileType); | ||
| 79 | |||
| 80 | /// load from file path | ||
| 81 | static boost::optional<ImfFile> load(const openstudio::path& p, const IddFile& iddFile); | ||
| 82 | |||
| 83 | /// print file to std::stream | ||
| 84 | std::ostream& print(std::ostream& os) const; | ||
| 85 | |||
| 86 | /** Save IddFile to path. Will construct parent folder, but no further up the chain. Will | ||
| 87 | * only overwrite an existing file if overwrite==true. If no extension is provided will use | ||
| 88 | * 'imf'. */ | ||
| 89 | // cppcheck-suppress functionConst | ||
| 90 | bool save(const openstudio::path& p, bool overwrite = false); | ||
| 91 | |||
| 92 | //@} | ||
| 93 | |||
| 94 | private: | ||
| 95 | // store all idf objects in a map by section | ||
| 96 | using SectionMapType = std::map<std::string, IdfObjectVector>; | ||
| 97 | SectionMapType m_sectionMap; | ||
| 98 | IddFileAndFactoryWrapper m_iddFileAndFactoryWrapper; | ||
| 99 | |||
| 100 | bool m_load(std::istream& is); | ||
| 101 | |||
| 102 | // configure logging | ||
| 103 | − | REGISTER_LOGGER("utilities.idf.ImfFile"); | |
| 104 | }; | ||
| 105 | |||
| 106 | /// optional imf file | ||
| 107 | using OptionalImfFile = boost::optional<ImfFile>; | ||
| 108 | |||
| 109 | /// vector of imf file | ||
| 110 | using ImfFileVector = std::vector<ImfFile>; | ||
| 111 | |||
| 112 | // ostream operator<< | ||
| 113 | UTILITIES_API std::ostream& operator<<(std::ostream& os, const ImfFile& imfFile); | ||
| 114 | |||
| 115 | } // namespace openstudio | ||
| 116 | |||
| 117 | #endif //UTILITIES_IDF_IMFFILE_HPP | ||
| 118 |