rasdaman API
sinterval.hh
Go to the documentation of this file.
1 /*
2  * This file is part of rasdaman community.
3  *
4  * Rasdaman community is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Rasdaman community is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Copyright 2003 - 2010 Peter Baumann / rasdaman GmbH.
18  *
19  * For more information please see <http://www.rasdaman.org>
20  * or contact Peter Baumann via <baumann@rasdaman.com>.
21 */
22 
33 #ifndef _D_SINTERVAL_
34 #define _D_SINTERVAL_
35 
36 #ifdef __VISUALC__
37 // Disable warning about exception specification.
38 #pragma warning( disable : 4290 )
39 #endif
40 
41 class r_Error;
42 class r_Eno_interval;
43 
44 #include <iostream>
45 
46 #include "raslib/point.hh"
47 
48 //@ManMemo: Module: {\bf raslib}
49 
50 /*@Doc:
51 
52  The class represents an interval with lower and upper bound.
53  Operations on the interval are defined according to the
54  ODMG-93 standard.
55  The operations union, difference, and intersection are
56  defined according to the following table:
57 
58  | ... fixed bound \\
59  * ... open bound
60 
61 
62  \begin{verbatim}
63 
64  class orientation union difference intersection
65  -----------------------------------------------------------
66  1 |-a-| |-b-| error a error
67 
68  2 |-a-| [a1,b2] [a1,b1] [b1,a2]
69  |-b-|
70 
71  3 |--a--| a error b
72  |-b-|
73 
74  4 |-b-| [b1,a2] [b2,a2] [a1,b2]
75  |-a-|
76 
77  5 |--b--| b error a
78  |-a-|
79 
80  6 |-b-| |-a-| error a error
81 
82  7 |-a-|-b-| [a1,b2] a [a2,a2]
83 
84  8 |-b-|-a-| [b1,a2] a [b2,b2]
85 
86  9 |--a--| a [a1,b1] b
87  |-b-|
88 
89  10 |--a--| a [b2,a2] b
90  |-b-|
91 
92  11 |-a-| a error a
93  |-b-|
94 
95  12 |--b--| b error a
96  |-a-|
97 
98  13 |--b--| b error a
99  |-a-|
100 
101  -----------------------------------------------------
102 
103  14 |--a--* a error b
104  |-b-|
105 
106  15 |--a--* a [b2,a2] b
107  |-b-|
108 
109  16 |-b-| |-a-* error a error
110 
111  17 |-b-|-a-* [b1,a2] a [b2,b2]
112 
113  18 |--a--* [b1,a2] [b2,a2] [a1,b2]
114  |-b-|
115 
116  -----------------------------------------------------
117 
118  19 *--a--| a error b
119  |-b-|
120 
121  20 *--a--| a [a1,b1] b
122  |-b-|
123 
124  21 *-a-| |-b-| error a error
125 
126  22 *-a-|-b-| [a1,b2] a [a2,a2]
127 
128  23 *--a--| [a1,b2] [a1,b1] [b1,a2]
129  |-b-|
130 
131  -----------------------------------------------------
132 
133  24 |--b--* b error a
134  |-a-|
135 
136  25 |--b--* b error a
137  |-a-|
138 
139  26 |-a-| |-b-* error a error
140 
141  27 |-a-|-b-* [a1,b2] a [a2,a2]
142 
143  28 |--b--* [a1,b2] [a1,b1] [b1,a2]
144  |-a-|
145 
146  -----------------------------------------------------
147 
148  29 *--b--| b error a
149  |-a-|
150 
151  30 *--b--| b error a
152  |-a-|
153 
154  31 *-b-| |-a-| error a error
155 
156  32 *-b-|-a-| [b1,a2] a [b2,b2]
157 
158  33 *--b--| [b1,a2] [b2,a2] [a1,b2]
159  |-a-|
160 
161  -----------------------------------------------------
162 
163  34 *-a-| |-b-* error a error
164 
165  35 *-a-|-b-* [a1,b2] a [a2,a2]
166 
167  36 *-a-| [a1,b2] [a1,b1] [b1,a2]
168  |-b-*
169 
170  -----------------------------------------------------
171 
172  37 *-b-| |-a-* error a error
173 
174  38 *-b-|-a-* [b1,a2] a [b2,b2]
175 
176  39 *-b-| [b1,a2] [a1,b1] [a1,b2]
177  |-a-*
178 
179  -----------------------------------------------------
180 
181  40 *-a-| b error a
182  *-b-|
183 
184  41 *-a-| a error a
185  *-b-|
186 
187  42 *-b-| a [b2,a2] b
188  *-a-|
189 
190  -----------------------------------------------------
191 
192  43 |-a-* a [a1,b1] b
193  |-b-*
194 
195  44 |-a-* a error a
196  |-b-*
197 
198  45 |-b-* b error a
199  |-a-*
200 
201  -----------------------------------------------------
202  46 *-a-* |-b-| a error b
203 
204  47 *-b-* |-a-| b error a
205 
206  48 *-a-* a [b2,a2] b
207  *-b-|
208 
209  49 *-a-* a [a1,b1] b
210  |-b-*
211 
212  50 *-b-* b error a
213  *-a-|
214 
215  51 *-b-* b error a
216  |-a-*
217 
218  52 *-a-* a error a
219  *-b-*
220 
221  \end{verbatim}
222 
223  Attention: The difference operation has to be reconsidered in future
224  concerning a discrete interpretation of the intervals.
225 
226  The closure operation defines an interval which is the smallest
227  interval containing the two operands.
228  The method {\tt intersects_with()} returns 0 in the error cases of the
229  intersection operation and 1 otherwise.
230 
231 */
232 
234 {
235 public:
237  r_Sinterval();
238 
240  r_Sinterval( char* ) throw(r_Eno_interval);
241 
244 
245  //@Man: Constructors for intervals with at least one open bound.
247  r_Sinterval( char, r_Range high );
250  r_Sinterval( r_Range low, char );
252  r_Sinterval( char, char );
254 
255 
257  bool operator==( const r_Sinterval& ) const;
258 
263  bool operator!=( const r_Sinterval& ) const;
265 
266  //@Man: Read/Write methods:
268  inline r_Range low () const;
271  inline r_Range high() const;
273  inline bool is_low_fixed() const;
275  inline bool is_high_fixed() const;
276 
278  void set_low ( r_Range low ) throw( r_Eno_interval );
280  void set_high ( r_Range high ) throw( r_Eno_interval );
282  inline void set_low ( char );
284  inline void set_high( char );
285 
287  r_Range get_extent() const throw(r_Error);
288  /*@Doc:
289  Returns a range with high() - low() + 1 of this interval.
290  */
291 
293  void set_interval( r_Range low, r_Range high ) throw( r_Eno_interval );
295  void set_interval( char, r_Range high );
297  void set_interval( r_Range low, char );
299  void set_interval( char, char );
301 
302 
304  bool intersects_with( const r_Sinterval& ) const;
305 
306  //@Man: Methods/Operators for the union operation:
308  r_Sinterval& union_of ( const r_Sinterval&, const r_Sinterval& )
310  throw( r_Eno_interval );
313  throw( r_Eno_interval );
316  throw( r_Eno_interval );
318  r_Sinterval create_union ( const r_Sinterval& ) const
319  throw( r_Eno_interval );
321  r_Sinterval operator+ ( const r_Sinterval& ) const
322  throw( r_Eno_interval );
324 
325 
326  //@Man: Methods/Operators for the difference operation:
330  throw( r_Eno_interval );
333  throw( r_Eno_interval );
336  throw( r_Eno_interval );
338  r_Sinterval create_difference ( const r_Sinterval& ) const
339  throw( r_Eno_interval );
341  r_Sinterval operator- ( const r_Sinterval& ) const
342  throw( r_Eno_interval );
344 
345 
346  //@Man: Methods/Operators for the intersection operation:
350  throw( r_Eno_interval );
353  throw( r_Eno_interval );
356  throw( r_Eno_interval);
359  throw( r_Eno_interval );
361  r_Sinterval operator* ( const r_Sinterval& ) const
362  throw( r_Eno_interval );
364 
365 
366  //@Man: Methods/Operators for the closure operation:
368  r_Sinterval& closure_of ( const r_Sinterval&, const r_Sinterval& )
370  throw( r_Eno_interval );
373  throw( r_Eno_interval );
375  r_Sinterval create_closure ( const r_Sinterval& ) const
376  throw( r_Eno_interval );
378 
379 
381  void print_status( std::ostream& s = std::cout ) const;
382 
384  char* get_string_representation() const;
392  //@Man: Methods for internal use only:
394  r_Bytes get_storage_size( ) const;
397 
398 
399 private:
400 
401  //@Man: Calculation methods for the operations:
403  r_Sinterval calc_union ( const r_Sinterval& a, const r_Sinterval& b ) const
405  throw( r_Eno_interval );
407  r_Sinterval calc_difference ( const r_Sinterval& a, const r_Sinterval& b ) const
408  throw( r_Eno_interval );
410  r_Sinterval calc_intersection( const r_Sinterval& a, const r_Sinterval& b ) const
411  throw( r_Eno_interval );
413  r_Sinterval calc_closure ( const r_Sinterval& a, const r_Sinterval& b ) const
414  throw( r_Eno_interval );
416 
417 
419  int classify( const r_Sinterval& a, const r_Sinterval& b ) const;
420 
421  //@Man: Attributes storing the bounds:
423  r_Range lower_bound;
426  r_Range upper_bound;
428 
429 
430  //@Man: Attributes specifying wheter the lower/upper bound is fixed or not:
432  bool low_fixed;
435  bool high_fixed;
437 
438 };
439 
440 
441 
442 
443 //@ManMemo: Module: {\bf raslib}
447 extern std::ostream& operator<<( std::ostream& s, const r_Sinterval& d );
448 
449 #include "raslib/sinterval.icc"
450 
451 #endif
std::ostream & operator<<(std::ostream &s, const r_Sinterval &d)
r_Sinterval & difference_of(const r_Sinterval &, const r_Sinterval &)
r_Sinterval operator-(const r_Sinterval &) const
r_Range high() const
r_Sinterval & union_of(const r_Sinterval &, const r_Sinterval &)
Definition: sinterval.hh:233
void set_low(r_Range low)
Definition: error.hh:88
r_Sinterval & operator+=(const r_Sinterval &)
int r_Range
Definition: mddtypes.hh:100
r_Sinterval & intersection_with(const r_Sinterval &)
r_Sinterval & operator*=(const r_Sinterval &)
r_Sinterval()
default constructor creates an interval with open bounds
bool is_low_fixed() const
r_Range low() const
r_Sinterval create_intersection(const r_Sinterval &) const
r_Sinterval create_union(const r_Sinterval &) const
r_Sinterval & difference_with(const r_Sinterval &)
bool operator!=(const r_Sinterval &) const
non equal operator - negation of equal operator
void set_interval(r_Range low, r_Range high)
r_Range get_extent() const
get the size of one dimensional interval as range.
r_Sinterval operator+(const r_Sinterval &) const
r_Sinterval operator*(const r_Sinterval &) const
r_Sinterval & closure_of(const r_Sinterval &, const r_Sinterval &)
void set_high(r_Range high)
r_Bytes get_storage_size() const
calculate the size of the storage space occupied
void print_status(std::ostream &s=std::cout) const
writes the state of the object to the specified stream
char * get_string_representation() const
gives back the string representation
r_Sinterval create_closure(const r_Sinterval &) const
r_Sinterval create_difference(const r_Sinterval &) const
unsigned int r_Bytes
Definition: mddtypes.hh:56
bool operator==(const r_Sinterval &) const
equal operator
r_Sinterval & intersection_of(const r_Sinterval &, const r_Sinterval &)
r_Sinterval & union_with(const r_Sinterval &)
Definition: error.hh:262
r_Sinterval & closure_with(const r_Sinterval &)
bool intersects_with(const r_Sinterval &) const
determines if the self interval intersects with the delivered one
bool is_high_fixed() const
r_Sinterval & operator-=(const r_Sinterval &)