casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Compare.h
Go to the documentation of this file.
1 //# Compare.h: compare two objects of the same type
2 //# Copyright (C) 1994,1995,1999
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_COMPARE_H
29 #define CASA_COMPARE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 // <summary> signature of comparison functions </summary>
38 // <use visibility=export>
39 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
40 
41 // <synopsis>
42 // This typedef defines the signature of the comparison functions used
43 // in, for instance, the <linkto class="Sort">Sort</linkto> class: functions
44 // with two <src>const void*</src> arguments returning an
45 // <src>int</src> value. One such function is defined in the
46 // <linkto class="ObjCompare">ObjCompare</linkto> class.
47 // </synopsis>
48 
49 // <group name=ObjCompareFunc>
50 typedef int ObjCompareFunc (const void*, const void*);
51 // </group>
52 
53 
54 // <summary> abstract base class for comparing two objects </summary>
55 // <use visibility=export>
56 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
57 //
58 // <synopsis>
59 // The abstract class <src>BaseCompare<T></src> is used for comparisons
60 // in sorting or iterating. One can derive a concrete comparison class
61 // from it.
62 // </synopsis>
63 
65 {
66 public:
67  virtual ~BaseCompare()
68  {}
69 
70  // Compare two objects, and return.
71  // <ul>
72  // <li> -1 if obj1 < obj2;
73  // <li> 0 if obj1 == obj2;
74  // <li> 1 otherwise.
75  // </ul>
76  virtual int comp (const void* obj1, const void* obj2) const = 0;
77 
78  // Get the data type of a straight-forward sort comparison in ObjCompare.
79  // It is used to test if a the faster GenSortIndirect can be used.
80  // By default it returns TpOther.
81  virtual DataType dataType() const
82  { return TpOther; }
83 };
84 
85 // <summary> compare two objects </summary>
86 // <use visibility=export>
87 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
88 
89 // <synopsis>
90 // The templated class <src>ObjCompare<T></src> really is only a place
91 // holder for the static function <src>compare</src> which compares two
92 // objects of type T.
93 // </synopsis>
94 
95 // <templating arg=T>
96 // <li> operator==
97 // <li> operator<
98 // </templating>
99 
100 template<class T> class ObjCompare: public BaseCompare
101 {
102 public:
103  virtual ~ObjCompare();
104 
105  // Compare two objects, and return
106  // <ul>
107  // <li> -1 if obj1 < obj2;
108  // <li> 0 if obj1 == obj2;
109  // <li> 1 otherwise.
110  // </ul>
111  // The static function is not inlined allowing one to take the address of
112  // it. Furthermore, the function's signature agrees with
113  // <linkto group="Compare.h#ObjCompareFunc">ObjCompareFunc</linkto>.
114  static int compare (const void* obj1, const void* obj2);
115  virtual int comp (const void* obj1, const void* obj2) const;
116 
117  // Get the data type of the sort comparison.
118  virtual DataType dataType() const;
119 };
120 
121 
122 
123 // <summary>Integer comparison class with intervals</summary>
124 // <use visibility=export>
125 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
126 
127 // <synopsis>
128 // This class is meant for comparison in the TableIterator class.
129 // It does not compare on the value itself, but compares intervals.
130 // In that way it is possible to iterate through a table in, for example,
131 // time chunks of N seconds. The start value X gives the start value of
132 // the base interval. Lower intervals are still possible.
133 // So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
134 // </synopsis>
135 template<typename T>
137 {
138 public:
139  // Construct from the given interval values.
140  CompareIntervalInt(Int64 interval, Int64 start);
141 
142  virtual ~CompareIntervalInt();
143 
144  // Compare the interval the left and right value belong to.
145  virtual int comp(const void * obj1, const void * obj2) const;
146 
147 private:
150 };
151 
152 
153 // <summary>Real comparison class with intervals</summary>
154 // <use visibility=export>
155 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
156 
157 // <synopsis>
158 // This class is meant for comparison in the TableIterator class.
159 // It does not compare on the value itself, but compares intervals.
160 // In that way it is possible to iterate through a table in, for example,
161 // time chunks of N seconds. The start value X gives the start value of
162 // the base interval. Lower intervals are still possible.
163 // So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
164 // </synopsis>
165 template<typename T>
167 {
168 public:
169  // Construct from the given interval values.
170  CompareIntervalReal(Double interval, Double start);
171 
172  virtual ~CompareIntervalReal();
173 
174  // Compare the interval the left and right value belong to.
175  virtual int comp(const void * obj1, const void * obj2) const;
176 
177 private:
180 };
181 
182 
183 // <summary>Case-insensitive string comparison class </summary>
184 // <use visibility=export>
185 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
186 
187 // <synopsis>
188 // This class is meant for an case-insensitive comparison in a sort
189 // or table iteration.
190 // </synopsis>
192 {
193 public:
194  virtual ~CompareNoCase();
195 
196  // Compare the left and right string value in a case-insensitive way.
197  virtual int comp(const void * obj1, const void * obj2) const;
198 };
199 
200 // <summary>Comparison class that is always true</summary>
201 
202 // <synopsis>
203 // This class is meant to always give true and can be used to ensure
204 // that all the values of a given column are grouped together.
205 // </synopsis>
207 {
208 public:
209  virtual ~CompareAlwaysTrue();
210 
211  // Comparison function that gives always true
212  virtual int comp(const void * obj1, const void * obj2) const;
213 };
214 
215 
216 } //# NAMESPACE CASACORE - END
217 
218 #ifndef CASACORE_NO_AUTO_TEMPLATES
219 #include <casacore/casa/Utilities/Compare.tcc>
220 #endif //# CASACORE_NO_AUTO_TEMPLATES
221 #endif
virtual int comp(const void *obj1, const void *obj2) const
Compare the interval the left and right value belong to.
Comparison class that is always true.
Definition: Compare.h:206
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
virtual DataType dataType() const
Get the data type of the sort comparison.
virtual int comp(const void *obj1, const void *obj2) const =0
Compare two objects, and return.
Case-insensitive string comparison class.
Definition: Compare.h:191
Real comparison class with intervals.
Definition: Compare.h:166
static int compare(const void *obj1, const void *obj2)
Compare two objects, and return.
CompareIntervalReal(Double interval, Double start)
Construct from the given interval values.
virtual DataType dataType() const
Get the data type of a straight-forward sort comparison in ObjCompare.
Definition: Compare.h:81
double Double
Definition: aipstype.h:55
Integer comparison class with intervals.
Definition: Compare.h:136
virtual int comp(const void *obj1, const void *obj2) const
Comparison function that gives always true.
virtual int comp(const void *obj1, const void *obj2) const
Compare the left and right string value in a case-insensitive way.
abstract base class for comparing two objects
Definition: Compare.h:64
virtual int comp(const void *obj1, const void *obj2) const
Compare two objects, and return.
virtual ~BaseCompare()
Definition: Compare.h:67
virtual int comp(const void *obj1, const void *obj2) const
Compare the interval the left and right value belong to.
CompareIntervalInt(Int64 interval, Int64 start)
Construct from the given interval values.
compare two objects
Definition: Compare.h:100