1 #if !defined(_PARAMETER_HH_)
12 #include "boost/program_options/options_description.hpp"
27 virtual std::istream&
Read(std::istream& is = std::cin) = 0;
30 virtual std::ostream&
Write(std::ostream& os = std::cout)
const = 0;
39 virtual std::string
ToString()
const = 0;
102 template <
typename T>
105 template <
typename _T>
107 template <
typename _T>
117 virtual std::ostream&
Write(std::ostream& os = std::cout) const throw (
ParameterNotSet, ParameterNotValid);
120 virtual std::
string ToString() const throw (ParameterNotSet, ParameterNotValid)
126 std::stringstream ss;
143 const T& operator=(const T&) throw (ParameterNotValid);
150 template <typename T>
167 parameters.push_back(
this);
169 (flag.c_str(), boost::program_options::value<T>(&this->
value)->notifier([
this](
const T&){ this->
is_set =
true; }), description.c_str());
177 parameters.push_back(
this);
179 (this->cmdline_flag.c_str(), boost::program_options::value<T>(&this->
value)->notifier([
this](
const T&){ this->
is_set =
true; }), description.c_str());
183 const T&
operator=(
const T& v)
throw (ParameterNotValid)
208 ((
"enable-" + flag).c_str(), boost::program_options::value<std::string>()->implicit_value(
"true")->zero_tokens()->notifier([
this](
const std::string& v){ this->
is_set =
true; this->value =
true; }),
"")
209 ((
"disable-" + flag).c_str(), boost::program_options::value<std::string>()->implicit_value(
"false")->zero_tokens()->notifier([
this](
const std::string & v){ this->
is_set =
true; this->value =
false; }),
210 (
"[enable/disable] " + description).c_str());
217 parameters.push_back(
this);
219 ((
"enable-" +
cmdline_flag).c_str(), boost::program_options::value<std::string>()->implicit_value(
"true")->zero_tokens()->notifier([
this](
const std::string& v){ this->
is_set =
true; this->value =
true; }),
"")
220 ((
"disable-" +
cmdline_flag).c_str(), boost::program_options::value<std::string>()->implicit_value(
"false")->zero_tokens()->notifier([
this](
const std::string & v){ this->
is_set =
true; this->value =
false; }),
221 (
"[enable/disable] " + description).c_str());
225 const bool&
operator=(
const bool& v)
throw (ParameterNotValid)
236 :
public std::logic_error
239 template <
typename T>
241 virtual const char* what()
const throw();
247 template <
typename T>
257 template <
typename T>
263 std::getline(is, in);
267 std::stringstream ss;
279 template <
typename T>
290 template <
typename T>
301 template <
typename T>
304 return t1.value == t2;
307 bool operator==(
const BaseParameter<std::string>& s1,
const char* s2)
throw (ParameterNotSet, ParameterNotValid);
309 template <
typename T>
311 : std::logic_error(
"Incorrect parameter value")
313 std::ostringstream os;
314 os <<
"Parameter " << p.
cmdline_flag <<
" set to incorrect value " << p.
value <<
" (" << desc <<
")";
321 static bool Parse(
int argc,
const char* argv[],
bool check_unregistered =
true,
bool silent =
false);
340 virtual void ReadParameters(std::istream& is = std::cin, std::ostream& os = std::cout)
350 }
while (!p->
IsSet());
355 virtual void Print(std::ostream& os = std::cout)
const
360 p->
Write(os) << std::endl;
365 template <
typename T>
374 throw std::logic_error(
"Parameter " + p->
cmdline_flag +
" value of an incorrect type");
380 throw std::logic_error(
"Parameter " + flag +
" not in the list");
387 std::string f1 =
split(p1->cmdline_flag, boost::regex(
"::"))[1];
390 std::string f2 =
split(p2->cmdline_flag, boost::regex(
"::"))[1];
402 template <
typename T>
412 throw std::logic_error(
"Parameter " + p->
cmdline_flag +
" value of an incorrect type");
419 throw std::logic_error(
"Parameter " + flag +
" not in the list");
443 #endif // !defined(_PARAMETER_HH_)
virtual std::istream & Read(std::istream &is=std::cin)=0
CFtype max(const std::vector< CFtype > &values)
virtual void RegisterParameters()=0
static std::list< const ParameterBox * > overall_parameters
virtual void operator()(const std::string &cmdline_flag, const std::string &description, ParameterBox ¶meters)
virtual void operator()(const std::string &cmdline_flag, const std::string &description, ParameterBox ¶meters)
virtual std::ostream & Write(std::ostream &os=std::cout) const
void CopyParameterValues(const Parametrized &p)
ParameterNotSet(const AbstractParameter &p)
virtual void CopyValue(const AbstractParameter &ap)
virtual void ReadParameters(std::istream &is=std::cin, std::ostream &os=std::cout)
virtual std::ostream & Write(std::ostream &os=std::cout) const =0
boost::program_options::options_description cl_options
friend class ParameterNotValid
virtual std::istream & Read(std::istream &is=std::cin)
virtual std::string ToString() const =0
bool IsRegistered() const
friend std::istream & operator>>(std::istream &is, BaseParameter< _T > &p)
friend class IncorrectParameterValue
const bool & operator=(const bool &v)
friend class ParameterNotSet
virtual void CopyValue(const AbstractParameter &ap)=0
Parametrized(const std::string &prefix, const std::string &description)
ParameterBox(const std::string &prefix, const std::string &description)
friend bool operator==(const BaseParameter< _T > &, const _T &)
static bool Parse(int argc, const char *argv[], bool check_unregistered=true, bool silent=false)
ParameterNotValid(const AbstractParameter &p)
void SetParameter(std::string flag, const T &value)
static std::list< Parametrized * > overall_parametrized
IncorrectParameterValue(const Parameter< T > &p, std::string desc)
void GetParameterValue(std::string flag, T &value)
Parameter(const std::string &cmdline_flag, const std::string &description, ParameterBox ¶meters)
const T & operator=(const T &v)
std::vector< std::string > split(const std::string &input, const boost::regex ®ex)
virtual void Print(std::ostream &os=std::cout) const
Parameter(const std::string &cmdline_flag, const std::string &description, ParameterBox ¶meters)
virtual std::string ToString() const