00001 // Filename: nameUniquifier.h 00002 // Created by: drose (16Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef NAMEUNIQUIFIER_H 00016 #define NAMEUNIQUIFIER_H 00017 00018 #include "pandabase.h" 00019 00020 #include <string> 00021 #include "pset.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : NameUniquifier 00025 // Description : A handy class for converting a list of arbitrary 00026 // names (strings) so that each name is guaranteed to be 00027 // unique in the list. Useful for writing egg files 00028 // with unique vertex pool names, or for file converters 00029 // to file formats that require unique node names, etc. 00030 //////////////////////////////////////////////////////////////////// 00031 class EXPCL_PANDA_PUTIL NameUniquifier { 00032 public: 00033 NameUniquifier(const string &separator = string(), 00034 const string &empty = string()); 00035 ~NameUniquifier(); 00036 00037 INLINE string add_name(const string &name); 00038 INLINE string add_name(const string &name, const string &prefix); 00039 00040 private: 00041 string add_name_body(const string &name, const string &prefix); 00042 00043 typedef pset<string, string_hash> Names; 00044 Names _names; 00045 string _separator; 00046 string _empty; 00047 int _counter; 00048 }; 00049 00050 #include "nameUniquifier.I" 00051 00052 #endif