00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifndef VTK_STRING_STRING_MAP_H_
00017
# define VTK_STRING_STRING_MAP_H_
00018
# include "vtkExtensionsObject.h"
00019
# include "vtkStringOps.h"
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 ;
00067
00072
int IsEmpty (
void)
const ;
00073
00078
void Clear (
void) ;
00079
00084
vtkIdType GetCapacity (
void)
const ;
00085
00103
const vtkUTF16ChType* Find (
const vtkUTF16ChType* key)
const
00104 ;
00105
const vtkUTF16ChType* Find (
const vtkUTF8ChType* key)
const
00106 ;
00107
const vtkUTF16ChType* Find (
const char* key)
const
00108 ;
00125
int Insert (
const vtkUTF16ChType* key,
00126
const vtkUTF16ChType* value)
00127 ;
00128
int Insert (
const vtkUTF8ChType* key,
00129
const vtkUTF8ChType* value)
00130 ;
00131
int Insert (
const char* key,
00132
const char* value)
00133 ;
00154
int Erase (
const vtkUTF16ChType* key)
00155 ;
00156
int Erase (
const vtkUTF8ChType* key)
00157 ;
00158
int Erase (
const char* key)
00159 ;
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
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
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
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
00345 {
00346
return this->Find(
UTF8_TO_UTF16(aKey));
00347 }
00348
00349
inline const vtkUTF16ChType*
00350 vtkStringStringMap::Find (
const char* aKey)
const
00351
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
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
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
00377 {
00378
return this->
Erase(
UTF8_TO_UTF16(aKey));
00379 }
00380
00381
inline int
00382 vtkStringStringMap::Erase (
const char* aKey)
00383
00384 {
00385
return this->
Erase(
LATIN1_TO_UTF16(aKey));
00386 }
00387
00388
VTK_EXTENSIONS_NAMESPACE_END
00389
00390
#endif
00391
00392
00393
00394