~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/constrained_value.h

  • Committer: Lee Bieber
  • Date: 2010-12-02 02:03:01 UTC
  • mfrom: (1966.1.2 build)
  • Revision ID: kalebral@gmail.com-20101202020301-l6uel9i517aohjiy
Merge Monty - more sys_var clean up work
Merge Shrews - fix bug 682799: Multiple queries sharing same GPB Statement msg not recorded when using --replicate-query

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef DRIZZLED_CONSTRAINED_VALUE_H
21
21
#define DRIZZLED_CONSTRAINED_VALUE_H
22
22
 
 
23
#include <boost/exception/info.hpp>
23
24
#include <boost/program_options.hpp>
24
25
#include <boost/program_options/errors.hpp>
25
26
#include <iostream>
27
28
namespace drizzled
28
29
{
29
30
 
 
31
/* We have to make this mixin exception class because boost program_option
 
32
  exceptions don't derive from f-ing boost::exception. FAIL
 
33
*/
 
34
class invalid_option_value :
 
35
  public boost::exception,
 
36
  public boost::program_options::invalid_option_value
 
37
{
 
38
public:
 
39
  invalid_option_value(const std::string &option_value) :
 
40
    boost::exception(),
 
41
    boost::program_options::invalid_option_value(option_value)
 
42
  {}
 
43
};
 
44
 
30
45
template<class T> class constrained_value;
31
46
template<class T>
32
47
std::istream& operator>>(std::istream& is, constrained_value<T>& bound_val);
144
159
}
145
160
146
161
 
 
162
typedef boost::error_info<struct tag_invalid_max,uint64_t> invalid_max_info;
 
163
typedef boost::error_info<struct tag_invalid_min,int64_t> invalid_min_info;
 
164
 
147
165
template<class T,
148
166
  T MAXVAL,
149
167
  T MINVAL, unsigned int ALIGN= 1>
163
181
 
164
182
  constrained_value<T>& set_value(T rhs)
165
183
  {
166
 
    if (greater_than_max<T,MAXVAL>(rhs) || less_than_min<T,MINVAL>(rhs))
167
 
    {
168
 
      boost::throw_exception(boost::program_options::invalid_option_value(boost::lexical_cast<std::string>(rhs)));
 
184
    if (greater_than_max<T,MAXVAL>(rhs))
 
185
    {
 
186
      boost::throw_exception(invalid_option_value(boost::lexical_cast<std::string>(rhs)) << invalid_max_info(MAXVAL));
 
187
    }
 
188
      
 
189
    if (less_than_min<T,MINVAL>(rhs))
 
190
    {
 
191
      boost::throw_exception(invalid_option_value(boost::lexical_cast<std::string>(rhs)) << invalid_min_info(MINVAL));
169
192
    }
170
193
    rhs-= rhs % ALIGN;
171
194
    this->setVal(rhs);