X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d625e80d62fc8b98c18a95c65e6fa329b7fcc85b..72797a0baa15ce75663a8dc662a132a6dd1a0de1:/projects/sgconf/options.h diff --git a/projects/sgconf/options.h b/projects/sgconf/options.h index 3d4bdd64..012b5167 100644 --- a/projects/sgconf/options.h +++ b/projects/sgconf/options.h @@ -18,13 +18,13 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONF_OPTIONS_H__ -#define __STG_SGCONF_OPTIONS_H__ +#pragma once #include #include -#include +#include #include +#include #include // size_t namespace SGCONF @@ -38,31 +38,31 @@ class OPTION public: OPTION(const std::string & shortName, const std::string & longName, - ACTION * action, + std::unique_ptr action, const std::string & description); OPTION(const std::string & longName, - ACTION * action, + std::unique_ptr action, const std::string & description); - OPTION(const OPTION & rhs); - ~OPTION(); - OPTION & operator=(const OPTION & rhs); + OPTION(OPTION&& rhs) = default; + OPTION& operator=(OPTION& rhs) = default; void Help(size_t level = 0) const; - PARSER_STATE Parse(int argc, char ** argv); + PARSER_STATE Parse(int argc, char ** argv, void * data); + void ParseValue(const std::string & value); bool Check(const char * arg) const; + const std::string & Name() const { return m_longName; } - class ERROR : public std::runtime_error + struct ERROR : std::runtime_error { - public: - ERROR(const std::string & message) - : std::runtime_error(message.c_str()) {} + explicit ERROR(const std::string & message) + : std::runtime_error(message.c_str()) {} }; private: std::string m_shortName; std::string m_longName; - ACTION * m_action; + std::unique_ptr m_action; std::string m_description; }; @@ -70,23 +70,36 @@ class OPTION_BLOCK { public: OPTION_BLOCK() {} - OPTION_BLOCK(const std::string & description) + explicit OPTION_BLOCK(const std::string & description) : m_description(description) {} + + OPTION_BLOCK(OPTION_BLOCK&&) = default; + OPTION_BLOCK& operator=(OPTION_BLOCK&&) = default; + OPTION_BLOCK & Add(const std::string & shortName, const std::string & longName, - ACTION * action, + std::unique_ptr action, const std::string & description); OPTION_BLOCK & Add(const std::string & longName, - ACTION * action, + std::unique_ptr action, const std::string & description); void Help(size_t level) const; - PARSER_STATE Parse(int argc, char ** argv); + PARSER_STATE Parse(int argc, char ** argv, void * data = NULL); + void ParseFile(const std::string & filePath); + + struct ERROR : std::runtime_error + { + explicit ERROR(const std::string & message) + : std::runtime_error(message.c_str()) {} + }; private: std::vector