diff --git a/action_skel_code/CMakeLists.txt b/action_skel_code/CMakeLists.txt index 446ea78..7459e82 100644 --- a/action_skel_code/CMakeLists.txt +++ b/action_skel_code/CMakeLists.txt @@ -1,4 +1,4 @@ -project(${bare_name}- CXX C) +project(${bare_name}- CXX) add_executable(${PROJECT_NAME} main.cpp @@ -18,4 +18,3 @@ string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}") target_compile_definitions(${PROJECT_NAME} PRIVATE ACTION_NAME="${ACTION_NAME}" ) - diff --git a/action_skel_code/commandline.cpp b/action_skel_code/commandline.cpp index bce640c..dc47ca3 100644 --- a/action_skel_code/commandline.cpp +++ b/action_skel_code/commandline.cpp @@ -23,16 +23,6 @@ namespace po = boost::program_options; namespace din { - ValidationError::ValidationError (const po::validation_error& parOther) : - po::validation_error(parOther) - { - } - - const std::string& ValidationError::raw_value() const { - auto it_ret = m_substitutions.find("value"); - return it_ret->second; - } - bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) { po::options_description set_options(ACTION_NAME " options"); //set_options.add_options() @@ -55,7 +45,7 @@ namespace din { po::store(po::command_line_parser(parArgc, parArgv).options(all)/*.positional(pd)*/.run(), parVarMap); } catch (const po::validation_error& err) { - throw ValidationError(err); + throw dinlib::ValidationError(err); } po::notify(parVarMap); diff --git a/action_skel_code/commandline.hpp b/action_skel_code/commandline.hpp index 9311c0d..979ca65 100644 --- a/action_skel_code/commandline.hpp +++ b/action_skel_code/commandline.hpp @@ -18,19 +18,11 @@ #ifndef id1B7A42F6E46547A6AB0F914E2A91399F #define id1B7A42F6E46547A6AB0F914E2A91399F -#include -#include +#include "dindexer-common/validationerror.hpp" #include "dindexer-common/mediatypes.hpp" +#include namespace din { - class ValidationError : boost::program_options::validation_error { - public: - explicit ValidationError ( const boost::program_options::validation_error& parOther ); - ~ValidationError ( void ) noexcept = default; - - const std::string& raw_value ( void ) const; - }; - bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap ); } //namespace din diff --git a/include/dindexer-common/validationerror.hpp b/include/dindexer-common/validationerror.hpp new file mode 100644 index 0000000..b09e9cf --- /dev/null +++ b/include/dindexer-common/validationerror.hpp @@ -0,0 +1,34 @@ +/* Copyright 2015, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id12815ADC9F024C85B9BBC65C5FA50959 +#define id12815ADC9F024C85B9BBC65C5FA50959 + +#include +#include + +namespace dinlib { + class ValidationError : boost::program_options::validation_error { + public: + explicit ValidationError ( const boost::program_options::validation_error& parOther ); + ~ValidationError ( void ) noexcept = default; + + const std::string& raw_value ( void ) const; + }; +} //namespace dinlib + +#endif diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 7bc533e..765a2ac 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -4,6 +4,7 @@ add_library(${PROJECT_NAME} commandline.cpp mediatypes.cpp settings.cpp + validationerror.cpp ) target_include_directories(${PROJECT_NAME} diff --git a/src/common/validationerror.cpp b/src/common/validationerror.cpp new file mode 100644 index 0000000..ee7acf4 --- /dev/null +++ b/src/common/validationerror.cpp @@ -0,0 +1,33 @@ +/* Copyright 2015, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "dindexer-common/validationerror.hpp" +#include + +namespace po = boost::program_options; + +namespace dinlib { + ValidationError::ValidationError (const po::validation_error& parOther) : + po::validation_error(parOther) + { + } + + const std::string& ValidationError::raw_value() const { + auto it_ret = m_substitutions.find("value"); + return it_ret->second; + } +} //namespace dinlib diff --git a/src/delete/CMakeLists.txt b/src/delete/CMakeLists.txt index 7a59ab5..b15b2aa 100644 --- a/src/delete/CMakeLists.txt +++ b/src/delete/CMakeLists.txt @@ -1,4 +1,4 @@ -project(${bare_name}-delete CXX C) +project(${bare_name}-delete CXX) add_executable(${PROJECT_NAME} main.cpp @@ -19,4 +19,3 @@ string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}") target_compile_definitions(${PROJECT_NAME} PRIVATE ACTION_NAME="${ACTION_NAME}" ) - diff --git a/src/delete/commandline.cpp b/src/delete/commandline.cpp index 83668cc..471af42 100644 --- a/src/delete/commandline.cpp +++ b/src/delete/commandline.cpp @@ -25,16 +25,6 @@ namespace po = boost::program_options; namespace din { - ValidationError::ValidationError (const po::validation_error& parOther) : - po::validation_error(parOther) - { - } - - const std::string& ValidationError::raw_value() const { - auto it_ret = m_substitutions.find("value"); - return it_ret->second; - } - bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) { po::options_description set_options(ACTION_NAME " options"); set_options.add_options() @@ -56,7 +46,7 @@ namespace din { po::store(po::command_line_parser(parArgc, parArgv).options(all).positional(pd).run(), parVarMap); } catch (const po::validation_error& err) { - throw ValidationError(err); + throw dinlib::ValidationError(err); } po::notify(parVarMap); diff --git a/src/delete/commandline.hpp b/src/delete/commandline.hpp index 7298c5f..7092947 100644 --- a/src/delete/commandline.hpp +++ b/src/delete/commandline.hpp @@ -18,19 +18,11 @@ #ifndef idB6191389C4AD4EE5862CCF1591BE6CE5 #define idB6191389C4AD4EE5862CCF1591BE6CE5 -#include -#include +#include "dindexer-common/validationerror.hpp" #include "dindexer-common/mediatypes.hpp" +#include namespace din { - class ValidationError : boost::program_options::validation_error { - public: - explicit ValidationError ( const boost::program_options::validation_error& parOther ); - ~ValidationError ( void ) noexcept = default; - - const std::string& raw_value ( void ) const; - }; - bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap ); } //namespace din diff --git a/src/delete/main.cpp b/src/delete/main.cpp index 9f83777..3c28bc5 100644 --- a/src/delete/main.cpp +++ b/src/delete/main.cpp @@ -56,7 +56,7 @@ int main (int parArgc, char* parArgv[]) { std::cerr << err.what() << "\nUse --help for help" << std::endl; return 2; } - catch (const din::ValidationError& err) { + catch (const dinlib::ValidationError& err) { std::cerr << "Unrecognized id \"" << err.raw_value() << "\", see --help for usage details\n"; return 2; }