src/generateiddfactory/main.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 | |||
| 8 | #include "GeneratorApplicationPathHelpers.hpp" | ||
| 9 | |||
| 10 | #include <boost/program_options.hpp> | ||
| 11 | |||
| 12 | #include <iostream> | ||
| 13 | #include <exception> | ||
| 14 | |||
| 15 | ✗ | int main(int argc, char* argv[]) { | |
| 16 | try { | ||
| 17 | // set up program options | ||
| 18 | ✗ | std::string outdir; | |
| 19 | ✗ | boost::program_options::options_description opts("Options", 100); | |
| 20 | ✗ | opts.add_options()("help,h", | |
| 21 | ✗ | "prints help message")("outdir,o", boost::program_options::value<std::string>(&outdir)->default_value(std::string(".")), | |
| 22 | ✗ | "specify the output directory")("idd,i", boost::program_options::value<std::vector<std::string>>(), | |
| 23 | "name,path of an IDD file; ex. EnergyPlus,C:\\EnergyPlus\\Energy+.idd; " | ||
| 24 | "if no name provided, will use file name"); | ||
| 25 | ✗ | boost::program_options::positional_options_description posOpts; | |
| 26 | ✗ | posOpts.add("idd", -1); | |
| 27 | |||
| 28 | // parse command line | ||
| 29 | ✗ | boost::program_options::variables_map vm; | |
| 30 | ✗ | boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(opts).positional(posOpts).run(), vm); | |
| 31 | ✗ | boost::program_options::notify(vm); | |
| 32 | |||
| 33 | // provide help message | ||
| 34 | ✗ | if (vm.count("help") != 0u) { | |
| 35 | ✗ | std::cout << opts; | |
| 36 | ✗ | std::cout << "In addition to an outdir, at least one name,path IDD pair is required." << '\n'; | |
| 37 | ✗ | return 0; | |
| 38 | } | ||
| 39 | |||
| 40 | // get valid output directory, if possible (otherwise throws) | ||
| 41 | ✗ | openstudio::filesystem::path outPath = openstudio::getApplicationOutputDirectory(outdir); | |
| 42 | |||
| 43 | // get the idd file information, if possible (otherwise throws) | ||
| 44 | ✗ | openstudio::IddFileFactoryDataVector iddFiles = openstudio::constructIddFileObjects(vm["idd"].as<std::vector<std::string>>()); | |
| 45 | |||
| 46 | // data common to the start of each file | ||
| 47 | ✗ | std::stringstream fileHeader; | |
| 48 | fileHeader << "/***********************************************************************************************************************" << '\n' | ||
| 49 | << "* OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC." << '\n' | ||
| 50 | << "* See also https://openstudio.net/license" << '\n' | ||
| 51 | ✗ | << "***********************************************************************************************************************/" << '\n'; | |
| 52 | |||
| 53 | // create and initialize output files | ||
| 54 | ✗ | openstudio::GenerateIddFactoryOutFiles outFiles(outPath, fileHeader.str(), iddFiles); | |
| 55 | ✗ | openstudio::initializeOutFiles(outFiles, iddFiles); | |
| 56 | |||
| 57 | // parse input files and write pieces of output files that require object text | ||
| 58 | ✗ | int i(0); | |
| 59 | ✗ | for (openstudio::IddFileFactoryData& idd : iddFiles) { | |
| 60 | ✗ | idd.parseFile(outPath, fileHeader.str(), outFiles, i); | |
| 61 | ✗ | ++i; | |
| 62 | } | ||
| 63 | |||
| 64 | // complete writing and close output files | ||
| 65 | ✗ | openstudio::completeOutFiles(iddFiles, outFiles); | |
| 66 | |||
| 67 | ✗ | } catch (std::runtime_error& e) { | |
| 68 | ✗ | std::cout << e.what() << '\n'; | |
| 69 | ✗ | return 1; | |
| 70 | ✗ | } | |
| 71 | ✗ | return 0; | |
| 72 | } | ||
| 73 |