summaryrefslogtreecommitdiff
path: root/src/options/base_handlers.h
blob: 0f1d735d10d48fc6e10dcff2d55330d8c1280b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*********************                                                        */
/*! \file base_handlers.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Tim King
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief [[ Add one-line brief description here ]]
 **
 ** [[ Add lengthier description here ]]
 ** \todo document this file
 **/

#include "cvc4_private.h"

#ifndef __CVC4__BASE_HANDLERS_H
#define __CVC4__BASE_HANDLERS_H

#include <iostream>
#include <string>
#include <sstream>

#include "options/option_exception.h"

namespace CVC4 {
namespace options {

template <template <class U> class Cmp>
class comparator {
  long d_lbound;
  double d_dbound;
  bool d_hasLbound;

 public:
  comparator(int i) : d_lbound(i), d_dbound(0.0), d_hasLbound(true) {}
  comparator(long l) : d_lbound(l), d_dbound(0.0), d_hasLbound(true) {}
  comparator(double d) : d_lbound(0), d_dbound(d), d_hasLbound(false) {}
  template <class T>
  void operator()(std::string option, const T& value) {
    if((d_hasLbound && !(Cmp<T>()(value, T(d_lbound)))) ||
       (!d_hasLbound && !(Cmp<T>()(value, T(d_dbound))))) {
      std::stringstream ss;
      ss << option << ": " << value << " is not a legal setting";
      throw OptionException(ss.str());
    }
  }
};/* class comparator */

struct greater : public comparator<std::greater> {
  greater(int i) : comparator<std::greater>(i) {}
  greater(long l) : comparator<std::greater>(l) {}
  greater(double d) : comparator<std::greater>(d) {}
};/* struct greater */

struct greater_equal : public comparator<std::greater_equal> {
  greater_equal(int i) : comparator<std::greater_equal>(i) {}
  greater_equal(long l) : comparator<std::greater_equal>(l) {}
  greater_equal(double d) : comparator<std::greater_equal>(d) {}
};/* struct greater_equal */

struct less : public comparator<std::less> {
  less(int i) : comparator<std::less>(i) {}
  less(long l) : comparator<std::less>(l) {}
  less(double d) : comparator<std::less>(d) {}
};/* struct less */

struct less_equal : public comparator<std::less_equal> {
  less_equal(int i) : comparator<std::less_equal>(i) {}
  less_equal(long l) : comparator<std::less_equal>(l) {}
  less_equal(double d) : comparator<std::less_equal>(d) {}
};/* struct less_equal */

struct not_equal : public comparator<std::not_equal_to> {
  not_equal(int i) : comparator<std::not_equal_to>(i) {}
  not_equal(long l) : comparator<std::not_equal_to>(l) {}
  not_equal(double d) : comparator<std::not_equal_to>(d) {}
};/* struct not_equal_to */

}/* CVC4::options namespace */
}/* CVC4 namespace */

#endif /* __CVC4__BASE_HANDLERS_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback