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
52// <summary> abstract base class for comparing two objects </summary>
53// <use visibility=export>
54// <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
55//
56// <synopsis>
57// The abstract class <src>BaseCompare<T></src> is used for comparisons
58// in sorting or iterating. One can derive a concrete comparison class
59// from it.
60// </synopsis>
61
63{
64public:
65 virtual ~BaseCompare()
66 {}
67
68 // Compare two objects, and return.
69 // <ul>
70 // <li> -1 if obj1 < obj2;
71 // <li> 0 if obj1 == obj2;
72 // <li> 1 otherwise.
73 // </ul>
74 virtual int comp (const void* obj1, const void* obj2) const = 0;
75
76 // Get the data type of a straight-forward sort comparison in ObjCompare.
77 // It is used to test if a the faster GenSortIndirect can be used.
78 // By default it returns TpOther.
79 virtual DataType dataType() const
80 { return TpOther; }
81};
82
83// <summary> compare two objects </summary>
84// <use visibility=export>
85// <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
86
87// <synopsis>
88// The templated class <src>ObjCompare<T></src> really is only a place
89// holder for the static function <src>compare</src> which compares two
90// objects of type T.
91// </synopsis>
92
93// <templating arg=T>
94// <li> operator==
95// <li> operator<
96// </templating>
97
98template<class T> class ObjCompare: public BaseCompare
99{
100public:
101 virtual ~ObjCompare();
102
103 // Compare two objects, and return
104 // <ul>
105 // <li> -1 if obj1 < obj2;
106 // <li> 0 if obj1 == obj2;
107 // <li> 1 otherwise.
108 // </ul>
109 // The static function is not inlined allowing one to take the address of
110 // it. Furthermore, the function's signature agrees with
111 // <linkto group="Compare.h#ObjCompareFunc">ObjCompareFunc</linkto>.
112 static int compare (const void* obj1, const void* obj2);
113 virtual int comp (const void* obj1, const void* obj2) const;
114
115 // Get the data type of the sort comparison.
116 virtual DataType dataType() const;
117};
118
119
120
121// <summary>Integer comparison class with intervals</summary>
122// <use visibility=export>
123// <reviewed reviewer="" date="" tests="tTableIter" demos="">
124
125// <synopsis>
126// This class is meant for comparison in the TableIterator class.
127// It does not compare on the value itself, but compares intervals.
128// In that way it is possible to iterate through a table in, for example,
129// time chunks of N seconds. The start value X gives the start value of
130// the base interval. Lower intervals are still possible.
131// So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
132// </synopsis>
133template<typename T>
135{
136public:
137 // Construct from the given interval values.
139
141
142 // Compare the interval the left and right value belong to.
143 virtual int comp(const void * obj1, const void * obj2) const;
144
145private:
148};
149
150
151// <summary>Real comparison class with intervals</summary>
152// <use visibility=export>
153// <reviewed reviewer="" date="" tests="tTableIter" demos="">
154
155// <synopsis>
156// This class is meant for comparison in the TableIterator class.
157// It does not compare on the value itself, but compares intervals.
158// In that way it is possible to iterate through a table in, for example,
159// time chunks of N seconds. The start value X gives the start value of
160// the base interval. Lower intervals are still possible.
161// So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
162// </synopsis>
163template<typename T>
165{
166public:
167 // Construct from the given interval values.
169
171
172 // Compare the interval the left and right value belong to.
173 virtual int comp(const void * obj1, const void * obj2) const;
174
175private:
178};
179
180
181// <summary>Case-insensitive string comparison class </summary>
182// <use visibility=export>
183// <reviewed reviewer="" date="" tests="tTableIter" demos="">
184
185// <synopsis>
186// This class is meant for an case-insensitive comparison in a sort
187// or table iteration.
188// </synopsis>
190{
191public:
192 virtual ~CompareNoCase();
193
194 // Compare the left and right string value in a case-insensitive way.
195 virtual int comp(const void * obj1, const void * obj2) const;
196};
197
198// <summary>Comparison class that is always true</summary>
199
200// <synopsis>
201// This class is meant to always give true and can be used to ensure
202// that all the values of a given column are grouped together.
203// </synopsis>
205{
206public:
208
209 // Comparison function that gives always true
210 virtual int comp(const void * obj1, const void * obj2) const;
211};
212
213
214} //# NAMESPACE CASACORE - END
215
216#ifndef CASACORE_NO_AUTO_TEMPLATES
217#include <casacore/casa/Utilities/Compare.tcc>
218#endif //# CASACORE_NO_AUTO_TEMPLATES
219#endif
abstract base class for comparing two objects
Definition Compare.h:63
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:79
virtual ~BaseCompare()
Definition Compare.h:65
Comparison class that is always true.
Definition Compare.h:205
virtual int comp(const void *obj1, const void *obj2) const
Comparison function that gives always true.
Integer comparison class with intervals.
Definition Compare.h:135
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.
Real comparison class with intervals.
Definition Compare.h:165
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:190
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:99
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.
this file contains all the compiler specific defines
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