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

NameUniquifier Class Reference

A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to be unique in the list. More...

#include <nameUniquifier.h>

List of all members.

Public Member Functions

 NameUniquifier (const string &separator=string(), const string &empty=string())
 Creates a new NameUniquifier.

 ~NameUniquifier ()
string add_name (const string &name)
 If name is nonempty and so far unique, returns it unchanged.

string add_name (const string &name, const string &prefix)
 If name is nonempty and so far unique, returns it unchanged.


Private Types

typedef pset< string > Names

Private Member Functions

string add_name_body (const string &name, const string &prefix)
 The actual implementation of the two flavors of add_name().


Private Attributes

Names _names
string _separator
string _empty
int _counter


Detailed Description

A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to be unique in the list.

Useful for writing egg files with unique vertex pool names, or for file converters to file formats that require unique node names, etc.

Definition at line 45 of file nameUniquifier.h.


Member Typedef Documentation

typedef pset<string> NameUniquifier::Names [private]
 

Definition at line 57 of file nameUniquifier.h.


Constructor & Destructor Documentation

NameUniquifier::NameUniquifier const string &  separator = string(),
const string &  empty = string()
 

Creates a new NameUniquifier.

The separator string is used to separate the original name (or supplied prefix) and the generated number when a name must be generated.

If the original name is empty, the empty string is used, followed by the generated number.

Definition at line 52 of file nameUniquifier.cxx.

NameUniquifier::~NameUniquifier  ) 
 

Definition at line 72 of file nameUniquifier.cxx.

References _counter, _empty, _names, _separator, and nassertr.


Member Function Documentation

string NameUniquifier::add_name const string &  name,
const string &  prefix
[inline]
 

If name is nonempty and so far unique, returns it unchanged.

Otherwise, generates and returns a new name according to the following rules:

If the prefix is empty, the new name is the NameUniquifier's "empty" string followed by a number, or the "separator" string if the "empty" string is empty.

If the prefix is nonempty, the new name is the prefix, followed by the NameUniquifier's "separator" string, followed by a number.

Definition at line 97 of file nameUniquifier.I.

string NameUniquifier::add_name const string &  name  )  [inline]
 

If name is nonempty and so far unique, returns it unchanged.

Otherwise, generates and returns a new name according to the following rules:

If the name is empty, the new name is the NameUniquifier's "empty" string followed by a number, or the "separator" string if the "empty" string is empty.

If the name is nonempty, the new name is the original name, followed by the NameUniquifier's "separator" string, followed by a number.

Definition at line 58 of file nameUniquifier.I.

References add_name_body(), and INLINE.

string NameUniquifier::add_name_body const string &  name,
const string &  prefix
[private]
 

The actual implementation of the two flavors of add_name().

If name is nonempty and so far unique, returns it unchanged.

Otherwise, generates and returns a new name according to the following rules:

If the prefix is empty, the new name is the NameUniquifier's "empty" string followed by a number, or the "separator" string if the "empty" string is empty.

If the prefix is nonempty, the new name is the prefix, followed by the NameUniquifier's "separator" string, followed by a number.

Definition at line 116 of file nameUniquifier.cxx.

Referenced by add_name().


Member Data Documentation

int NameUniquifier::_counter [private]
 

Definition at line 61 of file nameUniquifier.h.

Referenced by ~NameUniquifier().

string NameUniquifier::_empty [private]
 

Definition at line 60 of file nameUniquifier.h.

Referenced by ~NameUniquifier().

Names NameUniquifier::_names [private]
 

Definition at line 58 of file nameUniquifier.h.

Referenced by ~NameUniquifier().

string NameUniquifier::_separator [private]
 

Definition at line 59 of file nameUniquifier.h.

Referenced by ~NameUniquifier().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:52:31 2003 for Panda by doxygen1.3