Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Examples  

StringPool Class Reference

A StringPool allows the sharing of identical strings. More...

#include <stringpool.h>

List of all members.

Public Types

typedef set< const string *,
compare
PtrSet
typedef PtrSet::const_iterator iterator

Public Methods

 StringPool ()
 Constructor. More...

 ~StringPool ()
 Destructor. More...

const string * operator() (const string &s) const
 Try to retrieve a string from the pool. More...

const string * operator[] (const string &s)
 Try to retrieve a string from the pool, add it (a copy will be made) if not found. More...

void remove (const string &s)
 Remove a string from the stringpool. More...

iterator begin () const
iterator end () const
size_t size () const


Detailed Description

A StringPool allows the sharing of identical strings.

Also, comparison can be done on the pointers (much faster).

 StringPool pool;
 string* s = pool["abc"];
 if (t = pool("abc"))
   cout << *t << " already in pool";
Examples:

test-stringpool.C.

Definition at line 19 of file stringpool.h.


Member Typedef Documentation

typedef set<const string*, compare> StringPool::PtrSet
 

Definition at line 56 of file stringpool.h.

Referenced by size().

typedef PtrSet::const_iterator StringPool::iterator
 

Definition at line 57 of file stringpool.h.

Referenced by begin(), and end().


Constructor & Destructor Documentation

StringPool::StringPool  
 

Constructor.

Definition at line 4 of file stringpool.C.

00004                        {
00005 }

StringPool::~StringPool  
 

Destructor.

Definition at line 7 of file stringpool.C.

00007                         {
00008 for (PtrSet::const_iterator i=pool_.begin(); i!=pool_.end(); ++i)
00009   delete (*i);
00010 }


Member Function Documentation

const string * StringPool::operator() const string &    s const
 

Try to retrieve a string from the pool.

Parameters:
s  string to look for.
Returns:
pointer to the pool's copy or 0 if not found
Warning:
Never delete a pointer returned by this function.

Definition at line 13 of file stringpool.C.

00013                                             {
00014 PtrSet::const_iterator i = pool_.find(&s);
00015 return (i==pool_.end() ? 0 : *i);
00016 }

const string * StringPool::operator[] const string &    s
 

Try to retrieve a string from the pool, add it (a copy will be made) if not found.

Parameters:
s  string to find/add.
Returns:
pointer to the pool's copy os a.
Warning:
Never delete a pointer returned by this function.

Definition at line 19 of file stringpool.C.

00019                                       {
00020 return *(pool_.insert(new string(s)).first);
00021 }

void StringPool::remove const string &    s
 

Remove a string from the stringpool.

Parameters:
s  string to remove.
Warning:
Only use when you are certain there are no references to this string. Does not complain if the string is not in the pool.

Definition at line 32 of file stringpool.C.

Referenced by Index::remove().

00032                                   {
00033 const string* ps((*this)(s));
00034 if (ps)
00035   pool_.erase(ps);
00036 }

iterator StringPool::begin   const [inline]
 

Definition at line 59 of file stringpool.h.

References iterator.

00059 { return pool_.begin(); }

iterator StringPool::end   const [inline]
 

Definition at line 60 of file stringpool.h.

References iterator.

00060 { return pool_.end(); }

size_t StringPool::size   const [inline]
 

Definition at line 61 of file stringpool.h.

References PtrSet.

00061 { return pool_.size(); }


The documentation for this class was generated from the following files:
textindexer-0.2 [27 March, 2002]