Panda3D
attribNodeRegistry.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file attribNodeRegistry.h
10  * @author drose
11  * @date 2007-07-07
12  */
13 
14 #ifndef ATTRIBNODEREGISTRY_H
15 #define ATTRIBNODEREGISTRY_H
16 
17 #include "pandabase.h"
18 #include "nodePath.h"
19 #include "ordered_vector.h"
20 #include "lightMutex.h"
21 
22 /**
23  * This global object records NodePaths that are referenced by scene graph
24  * attribs, such as ClipPlaneAttribs and LightAttribs.
25  *
26  * Its primary purpose is to unify attribs that are loaded in from bam files.
27  * Attrib nodes are identified by name and type; when a bam file that contains
28  * references to some attrib nodes is loaded, those nodes are first looked up
29  * here in the AttribNodeRegistry. If there is a match (by name and node
30  * type), the identified node is used instead of the node referenced within
31  * the bam file itself.
32  */
33 class EXPCL_PANDA_PGRAPH AttribNodeRegistry {
34 protected:
36 
37 PUBLISHED:
38  void add_node(const NodePath &attrib_node);
39  bool remove_node(const NodePath &attrib_node);
40  NodePath lookup_node(const NodePath &orig_node) const;
41 
42  int get_num_nodes() const;
43  NodePath get_node(int n) const;
44  MAKE_SEQ(get_nodes, get_num_nodes, get_node);
45  TypeHandle get_node_type(int n) const;
46  std::string get_node_name(int n) const;
47 
48  int find_node(const NodePath &attrib_node) const;
49  int find_node(TypeHandle type, const std::string &name) const;
50  void remove_node(int n);
51  void clear();
52 
53  void output(std::ostream &out) const;
54  void write(std::ostream &out) const;
55 
56  INLINE static AttribNodeRegistry *get_global_ptr();
57 
58 private:
59  static void make_global_ptr();
60 
61  class Entry {
62  public:
63  INLINE Entry(const NodePath &node);
64  INLINE Entry(TypeHandle type, const std::string &name);
65  INLINE bool operator < (const Entry &other) const;
66 
67  TypeHandle _type;
68  std::string _name;
69  NodePath _node;
70  };
71 
72  typedef ov_set<Entry> Entries;
73  Entries _entries;
74 
75  LightMutex _lock;
76 
77  static AttribNodeRegistry * TVOLATILE _global_ptr;
78 };
79 
80 #include "attribNodeRegistry.I"
81 
82 #endif
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161