Panda3D
globalPointerRegistry.I
1 // Filename: globalPointerRegistry.I
2 // Created by: drose (03Feb00)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GlobalPointerRegistry::get_pointer
18 // Access: Public, Static
19 // Description: Returns the pointer associated with the indicated
20 // TypeHandle, if any. If no pointer has yet been
21 // associated, returns NULL.
22 ////////////////////////////////////////////////////////////////////
23 INLINE void *GlobalPointerRegistry::
25  return get_global_ptr()->ns_get_pointer(type);
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: GlobalPointerRegistry::store_pointer
30 // Access: Public, Static
31 // Description: Associates the given pointer with the indicated
32 // TypeHandle. It is an error to call this with a NULL
33 // pointer, or to call this function more than once with
34 // a given TypeHandle (without first calling
35 // clear_pointer).
36 ////////////////////////////////////////////////////////////////////
37 INLINE void GlobalPointerRegistry::
38 store_pointer(TypeHandle type, void *ptr) {
39  get_global_ptr()->ns_store_pointer(type, ptr);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: GlobalPointerRegistry::clear_pointer
44 // Access: Public, Static
45 // Description: Removes the association of the given pointer with the
46 // indicated TypeHandle. Subsequent calls to
47 // get_pointer() with this TypeHandle will return NULL,
48 // until another call to store_pointer() is made.
49 ////////////////////////////////////////////////////////////////////
50 INLINE void GlobalPointerRegistry::
52  get_global_ptr()->ns_clear_pointer(type);
53 }
54 
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: GlobalPointerRegistry::get_global_pointer
58 // Access: Private, Static
59 // Description: Returns a pointer to the single GlobalPointerRegistry
60 // object. If the object does not yet exist, creates
61 // it. This indirection is used instead of making all
62 // the data members of GlobalPointerRegistry static, so
63 // that we don't have to worry about order dependency
64 // during static init time.
65 ////////////////////////////////////////////////////////////////////
66 INLINE GlobalPointerRegistry *GlobalPointerRegistry::
67 get_global_ptr() {
68  if (_global_ptr == (GlobalPointerRegistry *)NULL) {
69  _global_ptr = new GlobalPointerRegistry;
70  }
71  return _global_ptr;
72 }
static void * get_pointer(TypeHandle type)
Returns the pointer associated with the indicated TypeHandle, if any.
static void clear_pointer(TypeHandle type)
Removes the association of the given pointer with the indicated TypeHandle.
static void store_pointer(TypeHandle type, void *ptr)
Associates the given pointer with the indicated TypeHandle.
This class maintains a one-to-one mapping from TypeHandle to a void * pointer.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85