casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef CASA_COMPARE_H
27#define CASA_COMPARE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Utilities/DataType.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary> signature of comparison functions </summary>
36// <use visibility=export>
37// <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
38
39// <synopsis>
40// This typedef defines the signature of the comparison functions used
41// in, for instance, the <linkto class="Sort">Sort</linkto> class: functions
42// with two <src>const void*</src> arguments returning an
43// <src>int</src> value. One such function is defined in the
44// <linkto class="ObjCompare">ObjCompare</linkto> class.
45// </synopsis>
46
47// <group name=ObjCompareFunc>
48typedef int ObjCompareFunc(const void*, const void*);
49// </group>
50
51// <summary> abstract base class for comparing two objects </summary>
52// <use visibility=export>
53// <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
54//
55// <synopsis>
56// The abstract class <src>BaseCompare<T></src> is used for comparisons
57// in sorting or iterating. One can derive a concrete comparison class
58// from it.
59// </synopsis>
60
62 public:
63 virtual ~BaseCompare() {}
64
65 // Compare two objects, and return.
66 // <ul>
67 // <li> -1 if obj1 < obj2;
68 // <li> 0 if obj1 == obj2;
69 // <li> 1 otherwise.
70 // </ul>
71 virtual int comp(const void* obj1, const void* obj2) const = 0;
72
73 // Get the data type of a straight-forward sort comparison in ObjCompare.
74 // It is used to test if a the faster GenSortIndirect can be used.
75 // By default it returns TpOther.
76 virtual DataType dataType() const { return TpOther; }
77};
78
79// <summary> compare two objects </summary>
80// <use visibility=export>
81// <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
82
83// <synopsis>
84// The templated class <src>ObjCompare<T></src> really is only a place
85// holder for the static function <src>compare</src> which compares two
86// objects of type T.
87// </synopsis>
88
89// <templating arg=T>
90// <li> operator==
91// <li> operator<
92// </templating>
93
94template <class T>
95class ObjCompare : public BaseCompare {
96 public:
97 virtual ~ObjCompare();
98
99 // Compare two objects, and return
100 // <ul>
101 // <li> -1 if obj1 < obj2;
102 // <li> 0 if obj1 == obj2;
103 // <li> 1 otherwise.
104 // </ul>
105 // The static function is not inlined allowing one to take the address of
106 // it. Furthermore, the function's signature agrees with
107 // <linkto group="Compare.h#ObjCompareFunc">ObjCompareFunc</linkto>.
108 static int compare(const void* obj1, const void* obj2);
109 virtual int comp(const void* obj1, const void* obj2) const;
110
111 // Get the data type of the sort comparison.
112 virtual DataType dataType() const;
113};
114
115// <summary>Integer comparison class with intervals</summary>
116// <use visibility=export>
117// <reviewed reviewer="" date="" tests="tTableIter" demos="">
118
119// <synopsis>
120// This class is meant for comparison in the TableIterator class.
121// It does not compare on the value itself, but compares intervals.
122// In that way it is possible to iterate through a table in, for example,
123// time chunks of N seconds. The start value X gives the start value of
124// the base interval. Lower intervals are still possible.
125// So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
126// </synopsis>
127template <typename T>
129 public:
130 // Construct from the given interval values.
132
134
135 // Compare the interval the left and right value belong to.
136 virtual int comp(const void* obj1, const void* obj2) const;
137
138 private:
141};
142
143// <summary>Real comparison class with intervals</summary>
144// <use visibility=export>
145// <reviewed reviewer="" date="" tests="tTableIter" demos="">
146
147// <synopsis>
148// This class is meant for comparison in the TableIterator class.
149// It does not compare on the value itself, but compares intervals.
150// In that way it is possible to iterate through a table in, for example,
151// time chunks of N seconds. The start value X gives the start value of
152// the base interval. Lower intervals are still possible.
153// So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
154// </synopsis>
155template <typename T>
157 public:
158 // Construct from the given interval values.
160
162
163 // Compare the interval the left and right value belong to.
164 virtual int comp(const void* obj1, const void* obj2) const;
165
166 private:
169};
170
171// <summary>Case-insensitive string comparison class </summary>
172// <use visibility=export>
173// <reviewed reviewer="" date="" tests="tTableIter" demos="">
174
175// <synopsis>
176// This class is meant for an case-insensitive comparison in a sort
177// or table iteration.
178// </synopsis>
180 public:
181 virtual ~CompareNoCase();
182
183 // Compare the left and right string value in a case-insensitive way.
184 virtual int comp(const void* obj1, const void* obj2) const;
185};
186
187// <summary>Comparison class that is always true</summary>
188
189// <synopsis>
190// This class is meant to always give true and can be used to ensure
191// that all the values of a given column are grouped together.
192// </synopsis>
194 public:
196
197 // Comparison function that gives always true
198 virtual int comp(const void* obj1, const void* obj2) const;
199};
200
201} // namespace casacore
202
203#ifndef CASACORE_NO_AUTO_TEMPLATES
204#include <casacore/casa/Utilities/Compare.tcc>
205#endif // # CASACORE_NO_AUTO_TEMPLATES
206#endif
abstract base class for comparing two objects
Definition Compare.h:61
virtual int comp(const void *obj1, const void *obj2) const =0
Compare two objects, and return.
virtual DataType dataType() const
Get the data type of a straight-forward sort comparison in ObjCompare.
Definition Compare.h:76
virtual ~BaseCompare()
Definition Compare.h:63
Comparison class that is always true.
Definition Compare.h:193
virtual int comp(const void *obj1, const void *obj2) const
Comparison function that gives always true.
CompareIntervalInt(Int64 interval, Int64 start)
Construct from the given interval values.
virtual int comp(const void *obj1, const void *obj2) const
Compare the interval the left and right value belong to.
virtual int comp(const void *obj1, const void *obj2) const
Compare the interval the left and right value belong to.
CompareIntervalReal(Double interval, Double start)
Construct from the given interval values.
Case-insensitive string comparison class.
Definition Compare.h:179
virtual int comp(const void *obj1, const void *obj2) const
Compare the left and right string value in a case-insensitive way.
compare two objects
Definition Compare.h:95
virtual int comp(const void *obj1, const void *obj2) const
Compare two objects, and return.
virtual DataType dataType() const
Get the data type of the sort comparison.
static int compare(const void *obj1, const void *obj2)
Compare two objects, and return.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
double Double
Definition aipstype.h:53
int ObjCompareFunc(const void *, const void *)
Definition Compare.h:49