OSDN Git Service

first
[psychlops/cpp.git] / psychlops / core / math / psychlops_m_interval.h
1 /*
2  *  psychlops_math_range.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/07/04 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_MATH_RANGE
10 #define HEADER_PSYCHLOPS_MATH_RANGE
11
12 #include <iostream>
13
14 #include "../ApplicationInterfaces/psychlops_code.h"
15
16 namespace Psychlops {
17
18         class Interval;
19         class Interval_acc;
20         typedef Interval Range;
21
22         class Interval {
23                 public:
24                 enum TYPES { NaN, NORMAL, INF, NINF };
25                 enum OPERATOR { CLOSE, OPEN };
26                 struct INTERVAL_ {
27                         private:
28                         public:
29                         TYPES type;
30                         OPERATOR op;
31                         double value;
32                         INTERVAL_() : type(INF), op(CLOSE), value(0.0) {}
33                         INTERVAL_(TYPES val) : type(val), op(CLOSE), value(0.0) {}
34                         INTERVAL_(double val) : type(NORMAL), op(CLOSE), value(val) {}
35                         INTERVAL_(double val, OPERATOR op) : type(NORMAL), op(op), value(val) {}
36                         INTERVAL_& set(TYPES mm, OPERATOR cop) { type=mm; op=cop; value=0.0; return *this; }
37                         INTERVAL_& set(double value_, OPERATOR cop) { type=NORMAL; op=cop; value=value_; return *this; }
38                         operator double() { if(type==NORMAL){return value;} else {throw type;return 0.0;} }
39                 };
40                 INTERVAL_ begin, end;
41
42                 public:
43                 Interval();
44                 Interval(double floor_val, double ceil_val);
45                 Interval(double floor_val, OPERATOR floor_op, double ceil_val, OPERATOR ceil_op);
46                 virtual ~Interval();
47                 Interval& operator <(double value);
48                 Interval& operator <=(double value);
49                 Interval& operator >(double value);
50                 Interval& operator >=(double value);
51                 Interval& operator <(TYPES value);
52                 Interval& operator <=(TYPES value);
53                 Interval& operator >(TYPES value);
54                 Interval& operator >=(TYPES value);
55                 int int_floor() const;
56                 int int_floor(int minval) const;
57                 int int_ceil() const;
58                 int int_ceil(int maxval) const;
59                 bool includes(double val) const;
60                 bool bounded() const;
61
62
63                 friend class Interval_acc;
64                 friend Interval_acc operator <(double val, Interval &rng);
65                 friend Interval_acc operator <=(double val, Interval &rng);
66                 friend Interval_acc operator >(double val, Interval &rng);
67                 friend Interval_acc operator >=(double val, Interval &rng);
68                 friend Interval_acc operator <(TYPES val, Interval &rng);
69                 friend Interval_acc operator <=(TYPES val, Interval &rng);
70                 friend Interval_acc operator >(TYPES val, Interval &rng);
71                 friend Interval_acc operator >=(TYPES val, Interval &rng);
72         };
73
74
75         class Interval_acc : public Interval {
76                 private:
77                 Interval &_range;
78                 public:
79                 Interval_acc(Interval &rng);
80                 ~Interval_acc();
81                 Interval& operator <(double value);
82                 Interval& operator <=(double value);
83                 Interval& operator >(double value);
84                 Interval& operator >=(double value);
85                 Interval& operator <(TYPES value);
86                 Interval& operator <=(TYPES value);
87                 Interval& operator >(TYPES value);
88                 Interval& operator >=(TYPES value);
89         };
90
91         Interval_acc operator <(double val, Interval &rng);
92         Interval_acc operator <=(double val, Interval &rng);
93         Interval_acc operator >(double val, Interval &rng);
94         Interval_acc operator >=(double val, Interval &rng);
95         Interval_acc operator <(Interval::TYPES val, Interval &rng);
96         Interval_acc operator <=(Interval::TYPES val, Interval &rng);
97         Interval_acc operator >(Interval::TYPES val, Interval &rng);
98         Interval_acc operator >=(Interval::TYPES val, Interval &rng);
99
100
101 }       /*      <- namespace Psycholops         */
102
103 #endif
104