Compare.h

Go to the documentation of this file.
00001 //# Compare.h: compare two objects of the same type
00002 //# Copyright (C) 1994,1995,1999
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef CASA_COMPARE_H
00029 #define CASA_COMPARE_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/Utilities/DataType.h>
00034 
00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00036 
00037 // <summary> signature of comparison functions </summary>
00038 // <use visibility=export>
00039 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
00040 
00041 // <synopsis>
00042 // This typedef defines the signature of the comparison functions used
00043 // in, for instance, the <linkto class="Sort">Sort</linkto> class: functions
00044 // with two <src>const void*</src> arguments returning an
00045 // <src>int</src> value. One such function is defined in the
00046 // <linkto class="ObjCompare">ObjCompare</linkto> class.
00047 // </synopsis>
00048 
00049 // <group name=ObjCompareFunc>
00050 typedef int ObjCompareFunc (const void*, const void*);
00051 // </group>
00052 
00053 
00054 // <summary> abstract base class for comparing two objects </summary>
00055 // <use visibility=export>
00056 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
00057 //
00058 // <synopsis> 
00059 // The abstract class <src>BaseCompare<T></src> is used for comparisons
00060 // in sorting or iterating. One can derive a concrete comparison class
00061 // from it.
00062 // </synopsis>
00063 
00064 class BaseCompare
00065 {
00066 public:
00067     virtual ~BaseCompare()
00068       {}
00069 
00070     // Compare two objects, and return.
00071     // <ul>
00072     //  <li> -1  if obj1 < obj2;
00073     //  <li>  0  if obj1 == obj2;
00074     //  <li>  1  otherwise.
00075     // </ul>
00076     virtual int comp (const void* obj1, const void* obj2) const = 0;
00077 
00078     // Get the data type of a straight-forward sort comparison in ObjCompare.
00079     // It is used to test if a the faster GenSortIndirect can be used.
00080     // By default it returns TpOther.
00081     virtual DataType dataType() const
00082       { return TpOther; }
00083 };
00084 
00085 // <summary> compare two objects </summary>
00086 // <use visibility=export>
00087 // <reviewed reviewer="Friso Olnon" date="1995/02/24" tests="" demos="">
00088 
00089 // <synopsis> 
00090 // The templated class <src>ObjCompare<T></src> really is only a place
00091 // holder for the static function <src>compare</src> which compares two
00092 // objects of type T.
00093 // </synopsis>
00094 
00095 // <templating arg=T>
00096 // <li> operator==
00097 // <li> operator<
00098 // </templating>
00099 
00100 template<class T> class ObjCompare: public BaseCompare
00101 {
00102 public:
00103     virtual ~ObjCompare();
00104 
00105     // Compare two objects, and return
00106     // <ul>
00107     //  <li> -1  if obj1 < obj2;
00108     //  <li>  0  if obj1 == obj2;
00109     //  <li>  1  otherwise.
00110     // </ul>
00111     // The static function is not inlined allowing one to take the address of
00112     // it. Furthermore, the function's signature agrees with
00113     // <linkto group="Compare.h#ObjCompareFunc">ObjCompareFunc</linkto>.
00114     static int compare (const void* obj1, const void* obj2);
00115     virtual int comp (const void* obj1, const void* obj2) const;
00116 
00117     // Get the data type of the sort comparison.
00118     virtual DataType dataType() const;
00119 };
00120 
00121 
00122 
00123 // <summary>Integer comparison class with intervals</summary>
00124 // <use visibility=export>
00125 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
00126 
00127 // <synopsis>
00128 // This class is meant for comparison in the TableIterator class.
00129 // It does not compare on the value itself, but compares intervals.
00130 // In that way it is possible to iterate through a table in, for example,
00131 // time chunks of N seconds. The start value X gives the start value of
00132 // the base interval. Lower intervals are still possible.
00133 // So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
00134 // </synopsis>
00135 template<typename T>
00136 class CompareIntervalInt : public BaseCompare
00137 {
00138 public:
00139   // Construct from the given interval values.
00140   CompareIntervalInt(Int64 interval, Int64 start);
00141 
00142   virtual ~CompareIntervalInt();
00143 
00144   // Compare the interval the left and right value belong to.
00145   virtual int comp(const void * obj1, const void * obj2) const;
00146 
00147 private:
00148   Int64 itsInterval;
00149   Int64 itsStart;
00150 };
00151 
00152 
00153 // <summary>Real comparison class with intervals</summary>
00154 // <use visibility=export>
00155 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
00156 
00157 // <synopsis>
00158 // This class is meant for comparison in the TableIterator class.
00159 // It does not compare on the value itself, but compares intervals.
00160 // In that way it is possible to iterate through a table in, for example,
00161 // time chunks of N seconds. The start value X gives the start value of
00162 // the base interval. Lower intervals are still possible.
00163 // So the intervals will be ..., X-2N:X-N, X-N:N, X:X+N, X+N:X+2N, ...
00164 // </synopsis>
00165 template<typename T>
00166 class CompareIntervalReal : public BaseCompare
00167 {
00168 public:
00169   // Construct from the given interval values.
00170   CompareIntervalReal(Double interval, Double start);
00171 
00172   virtual ~CompareIntervalReal();
00173 
00174   // Compare the interval the left and right value belong to.
00175   virtual int comp(const void * obj1, const void * obj2) const;
00176 
00177 private:
00178   Double itsInterval;
00179   Double itsStart;
00180 };
00181 
00182 
00183 // <summary>Case-insensitive string comparison class </summary>
00184 // <use visibility=export>
00185 // <reviewed reviewer="" date="" tests="tTableIter" demos="">
00186 
00187 // <synopsis>
00188 // This class is meant for an case-insensitive comparison in a sort
00189 // or table iteration.
00190 // </synopsis>
00191 class CompareNoCase : public BaseCompare
00192 {
00193 public:
00194   virtual ~CompareNoCase();
00195 
00196   // Compare the left and right string value in a case-insensitive way.
00197   virtual int comp(const void * obj1, const void * obj2) const;
00198 };
00199 
00200 
00201 } //# NAMESPACE CASACORE - END
00202 
00203 #ifndef CASACORE_NO_AUTO_TEMPLATES
00204 #include <casacore/casa/Utilities/Compare.tcc>
00205 #endif //# CASACORE_NO_AUTO_TEMPLATES
00206 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1