1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Monty Taylor
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_CONSTRAINED_VALUE_H
21
#define DRIZZLED_CONSTRAINED_VALUE_H
23
#include <boost/program_options.hpp>
24
#include <boost/program_options/errors.hpp>
30
template<class T> class constrained_value;
32
std::istream& operator>>(std::istream& is, constrained_value<T>& bound_val);
34
std::ostream& operator<<(std::ostream& os, const constrained_value<T>& v);
37
class constrained_value
42
virtual constrained_value<T>& set_value(const constrained_value<T>& rhs)= 0;
43
virtual constrained_value<T>& set_value(T rhs)= 0;
46
explicit constrained_value<T>(T in_value= 0) :
50
virtual ~constrained_value<T>()
58
constrained_value<T>& operator=(const constrained_value<T>& rhs)
60
return set_value(rhs);
63
constrained_value<T>& operator=(T rhs)
65
return set_value(rhs);
79
operator>>(std::istream& is,
80
constrained_value<T>& bound_val)
89
std::ostream& operator<<(std::ostream& os, const constrained_value<T>& v)
98
T MINVAL, unsigned int ALIGN= 1>
99
class constrained_check :
100
public constrained_value<T>
103
constrained_check<T,MAXVAL,MINVAL,ALIGN>(T in_value= 0) :
104
constrained_value<T>(in_value)
108
constrained_value<T>& set_value(const constrained_value<T>& rhs)
110
return set_value(rhs.getVal());
113
constrained_value<T>& set_value(T rhs)
115
if ((rhs > MAXVAL) || (rhs < MINVAL))
117
boost::throw_exception(boost::program_options::invalid_option_value(boost::lexical_cast<std::string>(rhs)));
127
typedef constrained_check<uint32_t,65535,1> back_log_constraints;
129
} /* namespace drizzled */
132
void validate(boost::any& v,
133
const std::vector<std::string>& values,
134
drizzled::constrained_value<T> val, int)
136
boost::program_options::validators::check_first_occurrence(v);
137
const std::string& s= boost::program_options::validators::get_single_string(values);
139
val= boost::lexical_cast<T>(s);
144
#endif /* DRIZZLED_CONSTRAINED_VALUE_H */