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

vtkStringStringMap.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: vtkStringStringMap.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_STRING_MAP_H_ 00017 # define VTK_STRING_STRING_MAP_H_ 00018 # include "vtkExtensionsObject.h" 00019 # include "vtkStringOps.h" // inline string operations 00020 00021 VTK_EXTENSIONS_NAMESPACE_BEGIN 00022 00023 class vtkStringStringPair; 00024 00040 class VTK_EXTENSIONS_COMMON_EXPORT vtkStringStringMap 00041 : public vtkExtensionsObject 00042 { 00043 public: 00044 static vtkStringStringMap* New (void); 00045 vtkTypeRevisionMacro (vtkStringStringMap, 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 const vtkUTF16ChType* Find (const vtkUTF16ChType* key) const 00104 /*THROW_SPEC()*/; 00105 const vtkUTF16ChType* Find (const vtkUTF8ChType* key) const 00106 /*THROW_SPEC1(vtkBadAlloc)*/; 00107 const vtkUTF16ChType* Find (const char* key) const 00108 /*THROW_SPEC1(vtkBadAlloc)*/; 00125 int Insert (const vtkUTF16ChType* key, 00126 const vtkUTF16ChType* value) 00127 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00128 int Insert (const vtkUTF8ChType* key, 00129 const vtkUTF8ChType* value) 00130 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00131 int Insert (const char* key, 00132 const char* value) 00133 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/; 00154 int Erase (const vtkUTF16ChType* key) 00155 /*THROW_SPEC()*/; 00156 int Erase (const vtkUTF8ChType* key) 00157 /*THROW_SPEC1(vtkBadAlloc)*/; 00158 int Erase (const char* key) 00159 /*THROW_SPEC1(vtkBadAlloc)*/; 00163 virtual void Swap (vtkStringStringMap* object); 00164 00169 virtual const vtkUTF16ChType* FindKey (const vtkUTF16ChType* other); 00170 00177 const vtkUTF16ChType* FindNextKey (void); 00178 00179 protected: 00189 vtkStringStringMap (void); 00190 ~vtkStringStringMap(); 00191 00192 private: 00193 int CheckUnique; 00194 int CheckCase; 00195 00197 vtkIdType CapacityIndex; 00198 00200 vtkIdType Capacity; 00201 00203 vtkIdType EnteredSize; 00204 00206 vtkIdType ErasedSize; 00207 00209 vtkIdType MaxSize; 00210 00212 vtkIdType MinSize; 00213 00219 vtkStringStringPair** Table; 00220 00222 vtkIdType SearchIndex; 00223 00225 vtkIdType TraversalIndex; 00226 00227 //BTX 00229 void EraseAll (void); 00230 00239 void GrowTable (void) THROW_SPEC2(vtkBadAlloc, vtkOverflowError); 00240 00247 void ShrinkTable (void) THROW_SPEC1(vtkBadAlloc); 00248 00256 vtkUint32Type Hash (const vtkUTF16ChType* const& key) const THROW_SPEC(); 00257 void Rehash (vtkUint32Type const& initial, 00258 vtkUint32Type & current) const THROW_SPEC(); 00262 int IsOccupied (const vtkIdType index) const THROW_SPEC(); 00263 00268 int Equals (const vtkUTF16ChType* const& str1, 00269 const vtkUTF16ChType* const& str2) const THROW_SPEC(); 00270 00272 int Find (vtkIdType const& index, 00273 vtkStringStringPair* & slot) const THROW_SPEC(); 00274 00276 void Insert (vtkStringStringPair* const& pair) THROW_SPEC(); 00277 00283 int Erase (vtkIdType const& index, 00284 vtkStringStringPair* & slot) THROW_SPEC(); 00285 //ETX 00286 00287 private: 00293 vtkStringStringMap (const vtkStringStringMap&); 00294 void operator= (const vtkStringStringMap&); 00296 }; 00297 00298 // ---------------------------------------------------------------------------- 00299 inline vtkUint32Type 00300 vtkStringStringMap::Hash (const vtkUTF16ChType* const& aKey) const THROW_SPEC() 00301 { 00302 // (0 < initial hash value < table size). 00303 return vtkUint32Type(1 + vtkStringOps::Hash(aKey, this->Capacity - 1)); 00304 } 00305 00306 inline void 00307 vtkStringStringMap::Rehash (vtkUint32Type const& aInitial, 00308 vtkUint32Type & aCurrent) const THROW_SPEC() 00309 { 00310 if ((aCurrent += aInitial) >= this->Capacity) 00311 { 00312 aCurrent %= this->Capacity; 00313 } 00314 } 00315 00316 // ---------------------------------------------------------------------------- 00317 inline int 00318 vtkStringStringMap::Equals (const vtkUTF16ChType* const& aStr1, 00319 const vtkUTF16ChType* const& aStr2) const 00320 THROW_SPEC() 00321 { 00322 return ( this->CheckCase ? 00323 vtkStringOps::Equals(aStr1, aStr2) : 00324 vtkStringOps::EqualsI(aStr1, aStr2) ); 00325 } 00326 00327 // ---------------------------------------------------------------------------- 00328 inline int 00329 vtkStringStringMap::IsOccupied (const vtkIdType aIndex) const THROW_SPEC() 00330 { 00331 if ( aIndex >= this->Capacity || 00332 (this->Table[aIndex] == (vtkStringStringPair *) 0) || 00333 (this->Table[aIndex] == (vtkStringStringPair *) -1) ) 00334 { 00335 return VTK_FALSE; 00336 } 00337 00338 return VTK_TRUE; 00339 } 00340 00341 // ---------------------------------------------------------------------------- 00342 inline const vtkUTF16ChType* 00343 vtkStringStringMap::Find (const vtkUTF8ChType* aKey) const 00344 /*THROW_SPEC1(vtkBadAlloc)*/ 00345 { 00346 return this->Find(UTF8_TO_UTF16(aKey)); 00347 } 00348 00349 inline const vtkUTF16ChType* 00350 vtkStringStringMap::Find (const char* aKey) const 00351 /*THROW_SPEC1(vtkBadAlloc)*/ 00352 { 00353 return this->Find(LATIN1_TO_UTF16(aKey)); 00354 } 00355 00356 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00357 inline int 00358 vtkStringStringMap::Insert (const vtkUTF8ChType* aKey, 00359 const vtkUTF8ChType* aValue) 00360 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00361 { 00362 return this->Insert(UTF8_TO_UTF16(aKey), UTF8_TO_UTF16(aValue)); 00363 } 00364 00365 inline int 00366 vtkStringStringMap::Insert (const char* aKey, 00367 const char* aValue) 00368 /*THROW_SPEC2(vtkBadAlloc, vtkOverflowError)*/ 00369 { 00370 return this->Insert(LATIN1_TO_UTF16(aKey), LATIN1_TO_UTF16(aValue)); 00371 } 00372 00373 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00374 inline int 00375 vtkStringStringMap::Erase (const vtkUTF8ChType* aKey) 00376 /*THROW_SPEC1(vtkBadAlloc)*/ 00377 { 00378 return this->Erase(UTF8_TO_UTF16(aKey)); 00379 } 00380 00381 inline int 00382 vtkStringStringMap::Erase (const char* aKey) 00383 /*THROW_SPEC1(vtkBadAlloc)*/ 00384 { 00385 return this->Erase(LATIN1_TO_UTF16(aKey)); 00386 } 00387 00388 VTK_EXTENSIONS_NAMESPACE_END 00389 00390 #endif /* VTK_STRING_STRING_MAP_H_ */ 00391 /* 00392 * End of: $Id: vtkStringStringMap.h,v 1.5 2004/08/10 07:37:21 xpxqx Exp $. 00393 * 00394 */

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