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)
96
template<class T, uint64_t MAXVAL=UINT64_MAX, int64_t MINVAL=INT64_MIN, int ALIGN=1>
97
class constrained_check :
98
public constrained_value<T>
101
constrained_check<T,MAXVAL,MINVAL,ALIGN>(T in_value= 0) :
102
constrained_value<T>(in_value)
106
constrained_value<T>& set_value(const constrained_value<T>& rhs)
108
return set_value(rhs.getVal());
111
constrained_value<T>& set_value(T rhs)
113
if ((rhs > MAXVAL) || (rhs < MINVAL))
115
boost::throw_exception(boost::program_options::invalid_option_value(boost::lexical_cast<std::string>(rhs)));
125
typedef constrained_check<uint32_t,65535,1> back_log_constraints;
127
} /* namespace drizzled */
130
void validate(boost::any& v,
131
const std::vector<std::string>& values,
132
drizzled::constrained_value<T> val, int)
134
boost::program_options::validators::check_first_occurrence(v);
135
const std::string& s= boost::program_options::validators::get_single_string(values);
137
val= boost::lexical_cast<T>(s);
142
#endif /* DRIZZLED_CONSTRAINED_VALUE_H */