Panda3D
 All Classes Functions Variables Enumerations
attribNodeRegistry.h
1 // Filename: attribNodeRegistry.h
2 // Created by: drose (07Jul07)
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 ATTRIBNODEREGISTRY_H
16 #define ATTRIBNODEREGISTRY_H
17 
18 #include "pandabase.h"
19 #include "nodePath.h"
20 #include "ordered_vector.h"
21 #include "lightMutex.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : AttribNodeRegistry
25 // Description : This global object records NodePaths that are
26 // referenced by scene graph attribs, such as
27 // ClipPlaneAttribs and LightAttribs.
28 //
29 // Its primary purpose is to unify attribs that are
30 // loaded in from bam files. Attrib nodes are
31 // identified by name and type; when a bam file that
32 // contains references to some attrib nodes is loaded,
33 // those nodes are first looked up here in the
34 // AttribNodeRegistry. If there is a match (by name and
35 // node type), the identified node is used instead of
36 // the node referenced within the bam file itself.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_PGRAPH AttribNodeRegistry {
39 protected:
41 
42 PUBLISHED:
43  void add_node(const NodePath &attrib_node);
44  bool remove_node(const NodePath &attrib_node);
45  NodePath lookup_node(const NodePath &orig_node) const;
46 
47  int get_num_nodes() const;
48  NodePath get_node(int n) const;
49  MAKE_SEQ(get_nodes, get_num_nodes, get_node);
50  TypeHandle get_node_type(int n) const;
51  string get_node_name(int n) const;
52 
53  int find_node(const NodePath &attrib_node) const;
54  int find_node(TypeHandle type, const string &name) const;
55  void remove_node(int n);
56  void clear();
57 
58  void output(ostream &out) const;
59  void write(ostream &out) const;
60 
61  INLINE static AttribNodeRegistry *get_global_ptr();
62 
63 private:
64  static void make_global_ptr();
65 
66  class Entry {
67  public:
68  INLINE Entry(const NodePath &node);
69  INLINE Entry(TypeHandle type, const string &name);
70  INLINE bool operator < (const Entry &other) const;
71 
72  TypeHandle _type;
73  string _name;
74  NodePath _node;
75  };
76 
77  typedef ov_set<Entry> Entries;
78  Entries _entries;
79 
80  LightMutex _lock;
81 
82  static AttribNodeRegistry * TVOLATILE _global_ptr;
83 };
84 
85 #include "attribNodeRegistry.I"
86 
87 #endif
88 
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165