CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_util_Equators_ 00008 #define _lucene_util_Equators_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 CL_NS_DEF(util) 00015 00016 00017 // Equators 00019 00020 class Equals{ 00021 public: 00022 class Int32:public CL_NS_STD(binary_function)<const int32_t*,const int32_t*,bool> 00023 { 00024 public: 00025 bool operator()( const int32_t val1, const int32_t val2 ) const; 00026 }; 00027 00028 class Char:public CL_NS_STD(binary_function)<const char*,const char*,bool> 00029 { 00030 public: 00031 bool operator()( const char* val1, const char* val2 ) const; 00032 }; 00033 #ifdef _UCS2 00034 class WChar: public CL_NS_STD(binary_function)<const wchar_t*,const wchar_t*,bool> 00035 { 00036 public: 00037 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const; 00038 }; 00039 class TChar: public WChar{ 00040 }; 00041 #else 00042 class TChar: public Char{ 00043 }; 00044 #endif 00045 00046 00047 template<typename _cl> 00048 class Void:public CL_NS_STD(binary_function)<const void*,const void*,bool> 00049 { 00050 public: 00051 bool operator()( _cl* val1, _cl* val2 ) const{ 00052 return val1==val2; 00053 } 00054 }; 00055 }; 00056 00057 00059 // Comparors 00061 00062 class Comparable:LUCENE_BASE{ 00063 public: 00064 virtual ~Comparable(){ 00065 } 00066 00067 virtual int32_t compareTo(void* o) = 0; 00068 }; 00069 00071 class Compare{ 00072 public: 00073 class _base 00074 { // traits class for hash containers 00075 public: 00076 enum 00077 { // parameters for hash table 00078 bucket_size = 4, // 0 < bucket_size 00079 min_buckets = 8 00080 }; // min_buckets = 2 ^^ N, 0 < N 00081 00082 _base() 00083 { 00084 } 00085 }; 00086 00087 class Int32:public _base, public Comparable{ 00088 int32_t value; 00089 public: 00090 int32_t getValue() const; 00091 Int32(int32_t val); 00092 Int32(); 00093 int32_t compareTo(void* o); 00094 bool operator()( int32_t t1, int32_t t2 ) const; 00095 size_t operator()( int32_t t ) const; 00096 }; 00097 00098 00099 class Float:public Comparable{ 00100 float_t value; 00101 public: 00102 float_t getValue() const; 00103 Float(float_t val); 00104 int32_t compareTo(void* o); 00105 }; 00106 00107 00108 class Char: public _base //<char*> 00109 { 00110 public: 00111 bool operator()( const char* val1, const char* val2 ) const; 00112 size_t operator()( const char* val1) const; 00113 }; 00114 00115 #ifdef _UCS2 00116 class WChar: public _base //<wchar_t*> 00117 { 00118 public: 00119 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const; 00120 size_t operator()( const wchar_t* val1) const; 00121 }; 00122 #endif 00123 00124 class TChar: public _base, public Comparable{ 00125 const TCHAR* s; 00126 public: 00127 const TCHAR* getValue() const; 00128 00129 TChar(); 00130 TChar(const TCHAR* str); 00131 int32_t compareTo(void* o); 00132 bool operator()( const TCHAR* val1, const TCHAR* val2 ) const; 00133 size_t operator()( const TCHAR* val1) const; 00134 }; 00135 00136 00137 template<typename _cl> 00138 class Void:public _base //<const void*,const void*,bool> 00139 { 00140 public: 00141 int32_t compareTo(_cl* o){ 00142 if ( this == o ) 00143 return o; 00144 else 00145 return this > o ? 1 : -1; 00146 } 00147 bool operator()( _cl* t1, _cl* t2 ) const{ 00148 return t1 > t2 ? true : false; 00149 } 00150 size_t operator()( _cl* t ) const{ 00151 return (size_t)t; 00152 } 00153 }; 00154 }; 00155 00157 // allocators 00159 00160 class Deletor{ 00161 public: 00162 00163 template<typename _kt> 00164 class Array{ 00165 public: 00166 static void doDelete(_kt* arr){ 00167 _CLDELETE_LARRAY(arr); 00168 } 00169 }; 00170 class tcArray{ 00171 public: 00172 static void doDelete(const TCHAR* arr){ 00173 _CLDELETE_CARRAY(arr); 00174 } 00175 }; 00176 class acArray{ 00177 public: 00178 static void doDelete(const char* arr){ 00179 _CLDELETE_CaARRAY(arr); 00180 } 00181 }; 00182 00183 class Unintern{ 00184 public: 00185 static void doDelete(TCHAR* arr); 00186 }; 00187 template<typename _kt> 00188 class Object{ 00189 public: 00190 static void doDelete(_kt* obj){ 00191 _CLLDELETE(obj); 00192 } 00193 }; 00194 template<typename _kt> 00195 class Void{ 00196 public: 00197 static void doDelete(_kt* obj){ 00198 _CLVDELETE(obj); 00199 } 00200 }; 00201 class Dummy{ 00202 public: 00203 static void doDelete(const void* nothing){ 00204 //todo: remove all occurances where it hits this point 00205 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00206 } 00207 }; 00208 class DummyInt32{ 00209 public: 00210 static void doDelete(const int32_t nothing){ 00211 } 00212 }; 00213 class DummyFloat{ 00214 public: 00215 static void doDelete(const float_t nothing){ 00216 } 00217 }; 00218 template <typename _type> 00219 class ConstNullVal{ 00220 public: 00221 static void doDelete(const _type nothing){ 00222 //todo: remove all occurances where it hits this point 00223 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00224 } 00225 }; 00226 00227 template <typename _type> 00228 class NullVal{ 00229 public: 00230 static void doDelete(_type nothing){ 00231 //todo: remove all occurances where it hits this point 00232 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00233 } 00234 }; 00235 }; 00237 00238 CL_NS_END 00239 #endif