DiaDes  0.1
DIAgnosis of Discrete-Event System
Interval.hh
Go to the documentation of this file.
1 #ifndef __DIADES__UTILS__INTERVAL_HH_
2 #define __DIADES__UTILS__INTERVAL_HH_
3 
4 #include <stdexcept>
5 #include <iostream>
6 #include "Assertion.hh"
7 
8 using namespace std;
9 namespace Diades
10 {
11 namespace Utils {
12 
16 class IntervalInvalid : public runtime_error, public domain_error
17 {
18 
19 public:
23  IntervalInvalid(const string& whatArg) : runtime_error(whatArg), domain_error(whatArg)
24  {
25  cerr << "EXCEPTION Interval -> " << whatArg << endl;
26  }
27 };
28 
29 class Interval
30 {
31 
32 private:
33  int _min;
34  int _max;
37  bool _minOpen;
38  bool _maxOpen;
39 public:
40  Interval();
41  Interval(const string & minusInfinity, const string & plusInfinity);
42  Interval(int min, const string & plusInfinity, bool open = false);
43  Interval(const string & minusInfinity, int max, bool open = false);
44  Interval(const Interval & interval);
45  Interval(const Interval & i1, const Interval & i2);
46  Interval(int min, int max);
47  Interval(int min, int max, bool openMin, bool openMax);
48  Interval & operator=(const Interval & interval);
49  bool operator==(const Interval & interval) const;
50  virtual ~Interval();
51  void setMin(int min, bool open);
52  void setMinusInfinity();
53  void setPlusInfinity();
54  void setMax(int max,bool open);
55  bool isIn(int x) const;
56  string toTina() const;
57  bool isValid() const { return _min <= _max; }
58  int lower() const { return _min; }
59  int upper() const { return _max; }
60  bool isOpen() const { return _minOpen && _maxOpen; }
61  bool isHalfOpen() const { return _minOpen || _maxOpen; }
62  bool isClosed() const { return !_maxOpen && !_minOpen; }
63  bool isLbOpen() const { return _minOpen; }
64  bool isUbOpen() const { return _maxOpen; }
65  bool isBounded() const { return !_minInfinity && !_maxInfinity; }
66  bool isLbBounded() const { return !_minInfinity; }
67  bool isUbBounded() const { return !_maxInfinity; }
68  bool isUnBounded() const { return _minInfinity || _maxInfinity; }
69  bool isLbUnBounded() const { return _minInfinity; }
70  bool isUbUnBounded() const { return _maxInfinity; }
71  friend ostream & operator << (ostream & os, const Interval & interval);
72 };
73 
74 };
75 };
76 
77 #endif /*INTERVAL_HH_*/
bool isUbUnBounded() const
Definition: Interval.hh:70
STL namespace.
IntervalInvalid(const string &whatArg)
Definition: Interval.hh:23
bool isOpen() const
Definition: Interval.hh:60
bool isBounded() const
Definition: Interval.hh:65
IsIn< InputIterator > isIn(InputIterator first, InputIterator last)
Definition: Functors.hh:141
Namespace of the Diades project.
bool isLbUnBounded() const
Definition: Interval.hh:69
std::ostream & operator<<(std::ostream &os, const Identifier &identifier)
Definition: Identifier.hh:501
bool isHalfOpen() const
Definition: Interval.hh:61
bool isValid() const
Definition: Interval.hh:57
bool isLbBounded() const
Definition: Interval.hh:66
bool isUnBounded() const
Definition: Interval.hh:68
bool isUbBounded() const
Definition: Interval.hh:67
bool isUbOpen() const
Definition: Interval.hh:64
bool isClosed() const
Definition: Interval.hh:62
bool isLbOpen() const
Definition: Interval.hh:63