Program Listing for File Options.hpp

Return to documentation for file (src/mimir/program/Options.hpp)

#pragma once

#include <cinttypes>
#include <functional>
#include <string>

#include <boost/program_options.hpp>

namespace mimir {

  class Options
  {
  protected:
    template<typename T>
    static std::function<void(T)> check_range(
        char const * const opt_name,
        const T& min,
        const T& max)
    {
      return [opt_name, min, max](T value)
             {
               if ( value < min || value > max)
               {
                 throw boost::program_options::validation_error(
                     boost::program_options::validation_error::invalid_option_value,
                     opt_name,
                     std::to_string(value));
               }
             };
    }

  public:
    Options(const std::string& program_descriptor);
    bool parse(int argc , char *argv[]);

  private:
    std::string make_usage_string(
        const std::string& program_name,
        const boost::program_options::options_description& desc,
        boost::program_options::positional_options_description& p);

  public:
    std::string filename;
    std::uint16_t severity,
      log_severity;
  private:
    const std::string m_progDesc;
  };


}