casacore
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>
33#include <casacore/casa/Utilities/DataType.h>
34
35namespace 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>
50typedef 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{
66public:
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
100template<class T> class ObjCompare: public BaseCompare
101{
102public:
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>
135template<typename T>
137{
138public:
139 // Construct from the given interval values.
141
143
144 // Compare the interval the left and right value belong to.
145 virtual int comp(const void * obj1, const void * obj2) const;
146
147private:
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>
165template<typename T>
167{
168public:
169 // Construct from the given interval values.
171
173
174 // Compare the interval the left and right value belong to.
175 virtual int comp(const void * obj1, const void * obj2) const;
176
177private:
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{
193public:
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{
208public:
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
abstract base class for comparing two objects
Definition: Compare.h:65
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:81
virtual ~BaseCompare()
Definition: Compare.h:67
Comparison class that is always true.
Definition: Compare.h:207
virtual int comp(const void *obj1, const void *obj2) const
Comparison function that gives always true.
Integer comparison class with intervals.
Definition: Compare.h:137
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:167
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:192
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:101
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:38
double Double
Definition: aipstype.h:55
int ObjCompareFunc(const void *, const void *)
Definition: Compare.h:51