Panda3D
 All Classes Functions Variables Enumerations
eggNameUniquifier.h
1 // Filename: eggNameUniquifier.h
2 // Created by: drose (09Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGNAMEUNIQUIFIER_H
16 #define EGGNAMEUNIQUIFIER_H
17 
18 ////////////////////////////////////////////////////////////////////
19 //
20 // EggNameUniquifier
21 //
22 // This is a utility class for renaming nodes in an egg hierarchy so
23 // that no two nodes share the same name. It's useful, for instance,
24 // as a preprocess before translating the egg hierarchy to a scene
25 // graph format that doesn't tolerate two identically-named nodes;
26 // it's also particularly useful for guaranteeing that VertexPools and
27 // Textures do not have conflicting names.
28 //
29 // This is actually an abstract class; in order to use it, you must
30 // derive your own class and redefine some key functions (but see
31 // EggPoolUniquifier and EggGroupUniquifier).
32 //
33 // You must define at least the following function:
34 //
35 // virtual string get_category(EggNode *node);
36 //
37 // This function defines the particular category that the
38 // particular node should be grouped into. All nodes that share
39 // the same category name will be considered in the same name pool
40 // and may not have the same name; two nodes that have different
41 // categories will be allowed to keep the same name.
42 //
43 // If the category is the empty string, the node will not be
44 // considered for uniquification.
45 //
46 //
47 // You may also define the following function:
48 //
49 // virtual string filter_name(EggNode *node);
50 //
51 // This returns the name of the node, or at least the name it ought
52 // to be. This provides a hook for, for instance, filtering out
53 // invalid characters before the node name is uniquified.
54 //
55 //
56 // virtual string generate_name(EggNode *node,
57 // const string &category, int index);
58 //
59 // This returns a new name for the given node, once a node has been
60 // identified as having the same name as another node. It may use
61 // any algorithm you please to generate a new name, using any
62 // combination of the node's original name, the category (as
63 // returned by get_category()), and/or the supplied unique index
64 // number.
65 //
66 // If this function returns a name that happens to collide with
67 // some other already-existing node, it will simply be called again
68 // (with a new index number) until it finally returns a unique
69 // name.
70 //
71 ////////////////////////////////////////////////////////////////////
72 
73 #include "pandabase.h"
74 
75 #include "eggObject.h"
76 
77 #include "pmap.h"
78 
79 class EggNode;
80 
81 ////////////////////////////////////////////////////////////////////
82 // Class : EggNameUniquifier
83 // Description : This is a handy class for guaranteeing unique node
84 // names in an egg hierarchy. It is an abstract class;
85 // to use it you must subclass off of it. See the
86 // comment above.
87 ////////////////////////////////////////////////////////////////////
88 class EXPCL_PANDAEGG EggNameUniquifier : public EggObject {
89 PUBLISHED:
92 
93  void clear();
94 
95  void uniquify(EggNode *node);
96 
97  EggNode *get_node(const string &category, const string &name) const;
98  bool has_name(const string &category, const string &name) const;
99  bool add_name(const string &category, const string &name,
100  EggNode *node = NULL);
101 
102  virtual string get_category(EggNode *node)=0;
103  virtual string filter_name(EggNode *node);
104  virtual string generate_name(EggNode *node,
105  const string &category, int index);
106 
107 private:
110 
111  Categories _categories;
112  int _index;
113 
114 public:
115 
116  static TypeHandle get_class_type() {
117  return _type_handle;
118  }
119  static void init_type() {
120  EggObject::init_type();
121  register_type(_type_handle, "EggNameUniquifier",
122  EggObject::get_class_type());
123  }
124  virtual TypeHandle get_type() const {
125  return get_class_type();
126  }
127  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
128 
129 private:
130  static TypeHandle _type_handle;
131 
132 };
133 
134 #endif
135 
136 
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is a handy class for guaranteeing unique node names in an egg hierarchy.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
The highest-level base class in the egg directory.
Definition: eggObject.h:31