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_VoidList_ 00008 #define _lucene_util_VoidList_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "Equators.h" 00015 00016 CL_NS_DEF(util) 00017 00018 00022 template<typename _kt,typename _base,typename _valueDeletor> 00023 class __CLList:public _base,LUCENE_BASE { 00024 private: 00025 bool dv; 00026 typedef _base base; 00027 public: 00028 DEFINE_MUTEX(THIS_LOCK) 00029 00030 typedef typename _base::const_iterator const_iterator; 00031 typedef typename _base::iterator iterator; 00032 00033 virtual ~__CLList(){ 00034 clear(); 00035 } 00036 00037 __CLList ( const bool deleteValue ): 00038 dv(deleteValue) 00039 { 00040 } 00041 00042 void setDoDelete(bool val){ dv=val; } 00043 00044 //sets array to the contents of this array. 00045 //array must be size+1, otherwise memory may be overwritten 00046 void toArray(_kt* into) const{ 00047 int i=0; 00048 for ( const_iterator itr=base::begin();itr!=base::end();itr++ ){ 00049 into[i] = *itr; 00050 i++; 00051 } 00052 into[i] = NULL; 00053 } 00054 00055 void set(int32_t i, _kt val) { 00056 if ( dv ) 00057 _valueDeletor::doDelete((*this)[i]); 00058 (*this)[i] = val; 00059 } 00060 00061 //todo: check this 00062 void delete_back(){ 00063 if ( base::size() > 0 ){ 00064 iterator itr = base::end(); 00065 if ( itr != base::begin()) 00066 itr --; 00067 _kt key = *itr; 00068 base::erase(itr); 00069 if ( dv ) 00070 _valueDeletor::doDelete(key); 00071 } 00072 } 00073 00074 void delete_front(){ 00075 if ( base::size() > 0 ){ 00076 iterator itr = base::begin(); 00077 _kt key = *itr; 00078 base::erase(itr); 00079 if ( dv ) 00080 _valueDeletor::doDelete(key); 00081 } 00082 } 00083 00084 void clear(){ 00085 if ( dv ){ 00086 iterator itr = base::begin(); 00087 while ( itr != base::end() ){ 00088 _valueDeletor::doDelete(*itr); 00089 ++itr; 00090 } 00091 } 00092 base::clear(); 00093 } 00094 00095 void remove(int32_t i, bool dontDelete=false){ 00096 iterator itr=base::begin(); 00097 itr+=i; 00098 _kt key = *itr; 00099 base::erase( itr ); 00100 if ( dv && !dontDelete ) 00101 _valueDeletor::doDelete(key); 00102 } 00103 void remove(iterator itr, bool dontDelete=false){ 00104 _kt key = *itr; 00105 base::erase( itr ); 00106 if ( dv && !dontDelete ) 00107 _valueDeletor::doDelete(key); 00108 } 00109 00110 }; 00111 00112 //growable arrays of Objects (like a collection or list) 00113 //a list, so can contain duplicates 00114 //it grows in chunks... todo: check jlucene for initial size of array, and growfactors 00115 template<typename _kt, typename _valueDeletor=CL_NS(util)::Deletor::Dummy> 00116 class CLVector:public __CLList<_kt, CL_NS_STD(vector)<_kt> , _valueDeletor> 00117 { 00118 public: 00119 CLVector ( const bool deleteValue=true ): 00120 __CLList<_kt, CL_NS_STD(vector)<_kt> , _valueDeletor>(deleteValue) 00121 { 00122 } 00123 }; 00124 00125 //An array-backed implementation of the List interface 00126 //a list, so can contain duplicates 00127 //*** a very simple list - use <valarray> 00128 //(This class is roughly equivalent to Vector, except that it is unsynchronized.) 00129 #define CLArrayList CLVector 00130 #define CLHashSet CLHashList 00131 00132 //implementation of the List interface, provides access to the first and last list elements in O(1) 00133 //no comparator is required... and so can contain duplicates 00134 //a simple list with no comparator 00135 //*** a very simple list - use <list> 00136 #ifdef LUCENE_DISABLE_HASHING 00137 #define CLHashList CLSetList 00138 #else 00139 00140 template<typename _kt, 00141 typename _Comparator=CL_NS(util)::Compare::TChar, 00142 typename _valueDeletor=CL_NS(util)::Deletor::Dummy> 00143 class CLHashList:public __CLList<_kt, CL_NS_HASHING(hash_set)<_kt,_Comparator> , _valueDeletor> 00144 { 00145 public: 00146 CLHashList ( const bool deleteValue=true ): 00147 __CLList<_kt, CL_NS_HASHING(hash_set)<_kt,_Comparator> , _valueDeletor>(deleteValue) 00148 { 00149 } 00150 }; 00151 #endif 00152 00153 template<typename _kt, typename _valueDeletor=CL_NS(util)::Deletor::Dummy> 00154 class CLLinkedList:public __CLList<_kt, CL_NS_STD(list)<_kt> , _valueDeletor> 00155 { 00156 public: 00157 CLLinkedList ( const bool deleteValue=true ): 00158 __CLList<_kt, CL_NS_STD(list)<_kt> , _valueDeletor>(deleteValue) 00159 { 00160 } 00161 }; 00162 template<typename _kt, 00163 typename _Comparator=CL_NS(util)::Compare::TChar, 00164 typename _valueDeletor=CL_NS(util)::Deletor::Dummy> 00165 class CLSetList:public __CLList<_kt, CL_NS_STD(set)<_kt,_Comparator> , _valueDeletor> 00166 { 00167 public: 00168 CLSetList ( const bool deleteValue=true ): 00169 __CLList<_kt, CL_NS_STD(set)<_kt,_Comparator> , _valueDeletor>(deleteValue) 00170 { 00171 } 00172 }; 00173 00174 CL_NS_END 00175 #endif