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 #include <map> 00011 #include <list> 00012 #include <set> 00013 #include <vector> 00014 #ifdef HAVE_WINDOWS_H 00015 #include <windef.h> 00016 #endif 00017 //#include "CLucene/LuceneThreads.h" 00018 00019 CL_NS_DEF(util) 00020 00021 00022 // Equators 00024 00025 class Equals{ 00026 public: 00027 class Int32:public CL_NS_STD(binary_function)<const int32_t*,const int32_t*,bool> 00028 { 00029 public: 00030 bool operator()( const int32_t val1, const int32_t val2 ) const; 00031 }; 00032 00033 class Char:public CL_NS_STD(binary_function)<const char*,const char*,bool> 00034 { 00035 public: 00036 bool operator()( const char* val1, const char* val2 ) const; 00037 }; 00038 #ifdef _UCS2 00039 class WChar: public CL_NS_STD(binary_function)<const wchar_t*,const wchar_t*,bool> 00040 { 00041 public: 00042 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const; 00043 }; 00044 class TChar: public WChar{ 00045 }; 00046 #else 00047 class TChar: public Char{ 00048 }; 00049 #endif 00050 00051 00052 template<typename _cl> 00053 class Void:public CL_NS_STD(binary_function)<const void*,const void*,bool> 00054 { 00055 public: 00056 bool operator()( _cl* val1, _cl* val2 ) const{ 00057 return val1==val2; 00058 } 00059 }; 00060 }; 00061 00062 00064 // Comparors 00066 00067 class Comparable:LUCENE_BASE{ 00068 public: 00069 virtual ~Comparable(){ 00070 } 00071 00072 virtual int32_t compareTo(void* o) = 0; 00073 }; 00074 00076 class Compare{ 00077 public: 00078 class _base 00079 { // traits class for hash containers 00080 public: 00081 enum 00082 { // parameters for hash table 00083 bucket_size = 4, // 0 < bucket_size 00084 min_buckets = 8 00085 }; // min_buckets = 2 ^^ N, 0 < N 00086 00087 _base() 00088 { 00089 } 00090 }; 00091 00092 class Int32:public _base, public Comparable{ 00093 int32_t value; 00094 public: 00095 int32_t getValue() const; 00096 Int32(int32_t val); 00097 Int32(); 00098 int32_t compareTo(void* o); 00099 bool operator()( int32_t t1, int32_t t2 ) const; 00100 size_t operator()( int32_t t ) const; 00101 }; 00102 00103 00104 class Float:public Comparable{ 00105 float_t value; 00106 public: 00107 float_t getValue() const; 00108 Float(float_t val); 00109 int32_t compareTo(void* o); 00110 }; 00111 00112 00113 class Char: public _base //<char*> 00114 { 00115 public: 00116 bool operator()( const char* val1, const char* val2 ) const; 00117 size_t operator()( const char* val1) const; 00118 }; 00119 00120 #ifdef _UCS2 00121 class WChar: public _base //<wchar_t*> 00122 { 00123 public: 00124 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const; 00125 size_t operator()( const wchar_t* val1) const; 00126 }; 00127 #endif 00128 00129 class TChar: public _base, public Comparable{ 00130 const TCHAR* s; 00131 public: 00132 const TCHAR* getValue() const; 00133 TChar(); 00134 TChar(const TCHAR* str); 00135 int32_t compareTo(void* o); 00136 bool operator()( const TCHAR* val1, const TCHAR* val2 ) const; 00137 size_t operator()( const TCHAR* val1) const; 00138 }; 00139 00140 00141 template<typename _cl> 00142 class Void:public _base //<const void*,const void*,bool> 00143 { 00144 public: 00145 int32_t compareTo(_cl* o){ 00146 if ( this == o ) 00147 return o; 00148 else 00149 return this > o ? 1 : -1; 00150 } 00151 bool operator()( _cl* t1, _cl* t2 ) const{ 00152 return t1 > t2 ? true : false; 00153 } 00154 size_t operator()( _cl* t ) const{ 00155 return (size_t)t; 00156 } 00157 }; 00158 }; 00159 00161 // allocators 00163 00164 class AbstractDeletor{ 00165 public: 00166 virtual void Delete(void*) = 0; 00167 }; 00168 class Deletor{ 00169 public: 00170 class tcArray: public AbstractDeletor{ 00171 public: 00172 void Delete(void* _arr){ 00173 doDelete((const TCHAR*)_arr); 00174 } 00175 static void doDelete(const TCHAR* arr){ 00176 _CLDELETE_CARRAY(arr); 00177 } 00178 }; 00179 00180 template<typename _kt> 00181 class Array: public AbstractDeletor{ 00182 public: 00183 void Delete(void* arr){ 00184 doDelete((_kt*)arr); 00185 } 00186 static void doDelete(_kt* arr){ 00187 _CLDELETE_LARRAY(arr); 00188 } 00189 }; 00190 class acArray: public AbstractDeletor{ 00191 public: 00192 void Delete(void* arr){ 00193 doDelete((const char*)arr); 00194 } 00195 static void doDelete(const char* arr){ 00196 _CLDELETE_CaARRAY(arr); 00197 } 00198 }; 00199 00200 template<typename _kt> 00201 class Object: public AbstractDeletor{ 00202 public: 00203 void Delete(void* obj){ 00204 doDelete((_kt*)obj); 00205 } 00206 static void doDelete(_kt* obj){ 00207 _CLLDELETE(obj); 00208 } 00209 }; 00210 template<typename _kt> 00211 class Void: public AbstractDeletor{ 00212 public: 00213 void Delete(void* obj){ 00214 doDelete((_kt*)obj); 00215 } 00216 static void doDelete(_kt* obj){ 00217 _CLVDELETE(obj); 00218 } 00219 }; 00220 class Dummy: public AbstractDeletor{ 00221 public: 00222 void Delete(void* nothing){} 00223 static void doDelete(const void* nothing){ 00224 //todo: remove all occurances where it hits this point 00225 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00226 } 00227 }; 00228 class DummyInt32: public AbstractDeletor{ 00229 public: 00230 void Delete(void* nothing){} 00231 static void doDelete(const int32_t nothing){ 00232 } 00233 }; 00234 class DummyFloat: public AbstractDeletor{ 00235 public: 00236 void Delete(void* nothing){} 00237 static void doDelete(const float_t nothing){ 00238 } 00239 }; 00240 template <typename _type> 00241 class ConstNullVal: public AbstractDeletor{ 00242 public: 00243 void Delete(void* nothing){} 00244 static void doDelete(const _type nothing){ 00245 //todo: remove all occurances where it hits this point 00246 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00247 } 00248 }; 00249 00250 template <typename _type> 00251 class NullVal: public AbstractDeletor{ 00252 public: 00253 void Delete(void* nothing){} 00254 static void doDelete(_type nothing){ 00255 //todo: remove all occurances where it hits this point 00256 //CND_WARNING(false,"Deletor::Dummy::doDelete run, set deleteKey or deleteValue to false"); 00257 } 00258 }; 00259 }; 00261 00262 CL_NS_END 00263 #endif