Program Listing for File Configurator.hpp¶
↰ Return to documentation for file (src/include/Configurator.hpp)
#ifndef SRC_INCLUDE_CONFIGURATOR_HPP
#define SRC_INCLUDE_CONFIGURATOR_HPP
#include <boost/program_options.hpp>
#include <fstream>
#include <istream>
#include <memory>
#include <string>
#include <vector>
namespace Nextsim {
class Configurator {
public:
Configurator() = default;
virtual ~Configurator() = default;
inline static void addFile(const std::string& filename)
{
addStream(std::unique_ptr<std::istream>(new std::fstream(filename)));
}
template <typename C> static void addFiles(const C& container)
{
for (auto& filename : container)
addFile(filename);
}
inline static void addStream(std::unique_ptr<std::istream> pis)
{
sources.push_back(std::move(pis));
}
template <typename C> static void addStreams(const C& container)
{
for (auto& stream : container) {
addStream(stream);
}
}
inline static void clearStreams() { sources.clear(); }
inline static void clear()
{
clearStreams();
setCommandLine(0, nullptr);
}
inline static void setCommandLine(int argc, char* argv[])
{
m_argc = argc;
m_argv = argv;
}
static boost::program_options::variables_map parse(
const boost::program_options::options_description& opt);
private:
static std::vector<std::unique_ptr<std::istream>> sources;
static int m_argc;
static char** m_argv;
};
} /* namespace Nextsim */
#endif /* SRC_INCLUDE_CONFIGURATOR_HPP */