Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

vtkStringEnumerator.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * $Id: vtkStringEnumerator.h,v 1.5 2004/08/10 07:37:21 xpxqx Exp $ 00004 * 00005 * Copyright (c) 2004 Sean McInerney 00006 * All rights reserved. 00007 * 00008 * See Copyright.txt or http://vtkextensions.sourceforge.net/Copyright.html 00009 * for details. 00010 * 00011 * This software is distributed WITHOUT ANY WARRANTY; without even 00012 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the above copyright notice for more information. 00014 * 00015 */ 00016 #ifndef VTK_STRING_ENUMERATOR_H_ 00017 # define VTK_STRING_ENUMERATOR_H_ 00018 # include "vtkExtensionsObject.h" 00019 # include "vtkStringOps.h" // inline string operations 00020 00021 VTK_EXTENSIONS_NAMESPACE_BEGIN 00022 00023 class vtkStringKVPair; 00024 00040 class VTK_EXTENSIONS_COMMON_EXPORT vtkStringEnumerator 00041 : public vtkExtensionsObject 00042 { 00043 public: 00044 static vtkStringEnumerator* New (void); 00045 vtkTypeRevisionMacro (vtkStringEnumerator, vtkExtensionsObject); 00046 void PrintSelf (ostream&, vtkIndent); 00047 00050 vtkGetMacro (CheckUnique, int); 00051 vtkSetMacro (CheckUnique, int); 00052 vtkBooleanMacro (CheckUnique, int); 00057 vtkGetMacro (CheckCase, int); 00058 vtkSetMacro (CheckCase, int); 00059 vtkBooleanMacro (CheckCase, int); 00066 vtkIdType GetSize (void) const /*THROW_SPEC()*/; 00067 00072 int IsEmpty (void) const /*THROW_SPEC()*/; 00073 00078 void Clear (void) /*THROW_SPEC1(vtkBadAlloc)*/; 00079 00084 vtkIdType GetCapacity (void) const /*THROW_SPEC()*/; 00085 00103 vtkIdType Find (const vtkUTF16ChType* key) const 00104 /*THROW_SPEC()*/; 00105 vtkIdType Find (const vtkUTF8ChType* key) const 00106 /*THROW_SPEC1(vtkBadAlloc)*/; 00107 vtkIdType Find (const char* key) const 00108 /*THROW_SPEC1(vtkBadAlloc)*/; 00125 int Insert (const vtkUTF16ChType* key, 00126 vtkIdType value) 00127 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00128 int Insert (const vtkUTF8ChType* key, 00129 vtkIdType value) 00130 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00131 int Insert (const char* key, 00132 vtkIdType value) 00133 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00158 int Insert (const vtkUTF16ChType* key) 00159 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00160 int Insert (const vtkUTF8ChType* key) 00161 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00162 int Insert (const char* key) 00163 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00184 int Erase (const vtkUTF16ChType* key) 00185 /*THROW_SPEC()*/; 00186 int Erase (const vtkUTF8ChType* key) 00187 /*THROW_SPEC1(vtkBadAlloc)*/; 00188 int Erase (const char* key) 00189 /*THROW_SPEC1(vtkBadAlloc)*/; 00193 virtual void Swap (vtkStringEnumerator* object); 00194 00199 virtual const vtkUTF16ChType* FindKey (const vtkIdType value); 00200 00207 const vtkUTF16ChType* FindNextKey (void); 00208 00209 protected: 00219 vtkStringEnumerator (void); 00220 ~vtkStringEnumerator(); 00221 00222 private: 00223 int CheckUnique; 00224 int CheckCase; 00225 00227 vtkIdType CapacityIndex; 00228 00230 vtkIdType Capacity; 00231 00233 vtkIdType EnteredSize; 00234 00236 vtkIdType ErasedSize; 00237 00239 vtkIdType MaxSize; 00240 00242 vtkIdType MinSize; 00243 00249 vtkStringKVPair** Table; 00250 00252 vtkIdType SearchIndex; 00253 00255 vtkIdType TraversalIndex; 00256 00257 //BTX 00259 void EraseAll (void); 00260 00269 void GrowTable (void) THROW_SPEC2(vtkBadAlloc, vtkOverflowError); 00270 00277 void ShrinkTable (void) THROW_SPEC1(vtkBadAlloc); 00278 00286 vtkUint32Type Hash (const vtkUTF16ChType* const& key) const THROW_SPEC(); 00287 void Rehash (vtkUint32Type const& initial, 00288 vtkUint32Type & current) const THROW_SPEC(); 00292 int IsOccupied (const vtkIdType index) const THROW_SPEC(); 00293 00298 int Equals (const vtkUTF16ChType* const& str1, 00299 const vtkUTF16ChType* const& str2) const THROW_SPEC(); 00300 00302 int Find (vtkIdType const& index, 00303 vtkStringKVPair* & slot) const THROW_SPEC(); 00304 00306 void Insert (vtkStringKVPair* const& pair) THROW_SPEC(); 00307 00313 int Erase (vtkIdType const& index, 00314 vtkStringKVPair* & slot) THROW_SPEC(); 00315 //ETX 00316 00317 private: 00323 vtkStringEnumerator (const vtkStringEnumerator&); 00324 void operator= (const vtkStringEnumerator&); 00326 }; 00327 00328 // ---------------------------------------------------------------------------- 00329 inline vtkUint32Type 00330 vtkStringEnumerator::Hash (const vtkUTF16ChType* const& aKey) const 00331 THROW_SPEC() 00332 { 00333 // (0 < initial hash value < table size). 00334 return vtkUint32Type(1 + vtkStringOps::Hash(aKey, this->Capacity - 1)); 00335 } 00336 00337 inline void 00338 vtkStringEnumerator::Rehash (vtkUint32Type const& aInitial, 00339 vtkUint32Type & aCurrent) const 00340 THROW_SPEC() 00341 { 00342 if ((aCurrent += aInitial) >= this->Capacity) 00343 { 00344 aCurrent %= this->Capacity; 00345 } 00346 } 00347 00348 // ---------------------------------------------------------------------------- 00349 inline int 00350 vtkStringEnumerator::Equals (const vtkUTF16ChType* const& aStr1, 00351 const vtkUTF16ChType* const& aStr2) const 00352 THROW_SPEC() 00353 { 00354 return ( this->CheckCase ? 00355 vtkStringOps::Equals(aStr1, aStr2) : 00356 vtkStringOps::EqualsI(aStr1, aStr2) ); 00357 } 00358 00359 // ---------------------------------------------------------------------------- 00360 inline int 00361 vtkStringEnumerator::IsOccupied (const vtkIdType aIndex) const THROW_SPEC() 00362 { 00363 if ( aIndex >= this->Capacity || 00364 (this->Table[aIndex] == (vtkStringKVPair *) 0) || 00365 (this->Table[aIndex] == (vtkStringKVPair *) -1) ) 00366 { 00367 return VTK_FALSE; 00368 } 00369 00370 return VTK_TRUE; 00371 } 00372 00373 // ---------------------------------------------------------------------------- 00374 inline vtkIdType 00375 vtkStringEnumerator::Find (const vtkUTF8ChType* aKey) const 00376 /*THROW_SPEC1(vtkBadAlloc)*/ 00377 { 00378 return this->Find(UTF8_TO_UTF16(aKey)); 00379 } 00380 00381 inline vtkIdType 00382 vtkStringEnumerator::Find (const char* aKey) const 00383 /*THROW_SPEC1(vtkBadAlloc)*/ 00384 { 00385 return this->Find(LATIN1_TO_UTF16(aKey)); 00386 } 00387 00388 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00389 inline int 00390 vtkStringEnumerator::Insert (const vtkUTF8ChType* aKey, vtkIdType aData) 00391 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00392 { 00393 return this->Insert(UTF8_TO_UTF16(aKey), aData); 00394 } 00395 00396 inline int 00397 vtkStringEnumerator::Insert (const char* aKey, vtkIdType aData) 00398 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00399 { 00400 return this->Insert(LATIN1_TO_UTF16(aKey), aData); 00401 } 00402 00403 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00404 inline int 00405 vtkStringEnumerator::Insert (const vtkUTF8ChType* aKey) 00406 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00407 { 00408 return this->Insert(UTF8_TO_UTF16(aKey)); 00409 } 00410 00411 inline int 00412 vtkStringEnumerator::Insert (const char* aKey) 00413 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00414 { 00415 return this->Insert(LATIN1_TO_UTF16(aKey)); 00416 } 00417 00418 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00419 inline int 00420 vtkStringEnumerator::Erase (const vtkUTF8ChType* aKey) 00421 /*THROW_SPEC1(vtkBadAlloc)*/ 00422 { 00423 return this->Erase(UTF8_TO_UTF16(aKey)); 00424 } 00425 00426 inline int 00427 vtkStringEnumerator::Erase (const char* aKey) 00428 /*THROW_SPEC1(vtkBadAlloc)*/ 00429 { 00430 return this->Erase(LATIN1_TO_UTF16(aKey)); 00431 } 00432 00433 VTK_EXTENSIONS_NAMESPACE_END 00434 00435 #endif /* VTK_STRING_ENUMERATOR_H_ */ 00436 /* 00437 * End of: $Id: vtkStringEnumerator.h,v 1.5 2004/08/10 07:37:21 xpxqx Exp $. 00438 * 00439 */

Generated on Tue Aug 10 03:38:40 2004 for vtkExtensions by doxygen 1.3.7