Commit b78f1cb8 authored by Davis King's avatar Davis King

Added the check_sub_option() method to the command line parser check

object.
parent 13269d7f
......@@ -3,7 +3,7 @@
#ifndef DLIB_CMD_LINE_PARSER_CHECk_1_
#define DLIB_CMD_LINE_PARSER_CHECk_1_
#include "cmd_line_parser_kernel_abstract.h"
#include "cmd_line_parser_check_abstract.h"
#include <sstream>
#include <string>
#include "../string.h"
......@@ -191,6 +191,11 @@ namespace dlib
const string_type& option_name2
) const;
void check_sub_option (
const string_type& parent_option,
const string_type& sub_option
) const;
template <
size_t length
>
......@@ -423,6 +428,27 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template <typename clp_base>
void cmd_line_parser_check_1<clp_base>::
check_sub_option (
const string_type& parent_option,
const string_type& sub_option
) const
{
if (this->option(parent_option).count() == 0)
{
if (this->option(sub_option).count() != 0)
{
std::vector<string_type> vect;
vect.resize(1);
vect[0] = parent_option;
throw cmd_line_check_error( EMISSING_REQUIRED_OPTION, sub_option, vect);
}
}
}
// ----------------------------------------------------------------------------------------
template <typename clp_base>
......
......@@ -217,6 +217,28 @@ namespace dlib
- opt2 == The next incompatible option found.
!*/
void check_sub_option (
const string_type& parent_option,
const string_type& sub_option
) const;
/*!
requires
- parsed_line() == true
- option_is_defined(parent_option) == true
- option_is_defined(sub_option) == true
ensures
- if (option(parent_option).count() == 0) then
- option(sub_option).count() == 0
throws
- std::bad_alloc
- cmd_line_check_error
This exception is thrown if the ensures clause could not be satisfied.
The exception's members will be set as follows:
- type == EMISSING_REQUIRED_OPTION
- opt == sub_option.
- required_opts == a vector that contains only parent_option.
!*/
template <
size_t length
>
......
......@@ -75,6 +75,11 @@ namespace dlib
const string_type& option_name2
) const;
void check_sub_option (
const string_type& parent_option,
const string_type& sub_option
) const;
template <
size_t length
>
......@@ -266,6 +271,30 @@ namespace dlib
clp_check::check_incompatible_options(option_name1,option_name2);
}
// ----------------------------------------------------------------------------------------
template <typename clp_check>
void cmd_line_parser_check_c<clp_check>::
check_sub_option (
const string_type& parent_option,
const string_type& sub_option
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->parsed_line() == true && this->option_is_defined(parent_option) &&
this->option_is_defined(sub_option),
"\tvoid cmd_line_parser_check::check_sub_option()"
<< "\n\tSee the requires clause for this function."
<< "\n\tthis: " << this
<< "\n\tparsed_line(): " << this->parsed_line()
<< "\n\toption_is_defined(parent_option): " << this->option_is_defined(parent_option)
<< "\n\toption_is_defined(sub_option): " << this->option_is_defined(sub_option)
<< "\n\tparent_option: " << parent_option
<< "\n\tsub_option: " << sub_option
);
clp_check::check_sub_option(parent_option,sub_option);
}
// ----------------------------------------------------------------------------------------
template <typename clp_check>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment