Panda3D
Loading...
Searching...
No Matches
globalPointerRegistry.I
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 globalPointerRegistry.I
10 * @author drose
11 * @date 2000-02-03
12 */
13
14/**
15 * Returns the pointer associated with the indicated TypeHandle, if any. If
16 * no pointer has yet been associated, returns NULL.
17 */
20 return get_global_ptr()->ns_get_pointer(type);
21}
22
23/**
24 * Associates the given pointer with the indicated TypeHandle. It is an error
25 * to call this with a NULL pointer, or to call this function more than once
26 * with a given TypeHandle (without first calling clear_pointer).
27 */
29store_pointer(TypeHandle type, void *ptr) {
30 get_global_ptr()->ns_store_pointer(type, ptr);
31}
32
33/**
34 * Removes the association of the given pointer with the indicated TypeHandle.
35 * Subsequent calls to get_pointer() with this TypeHandle will return NULL,
36 * until another call to store_pointer() is made.
37 */
40 get_global_ptr()->ns_clear_pointer(type);
41}
42
43
44/**
45 * Returns a pointer to the single GlobalPointerRegistry object. If the
46 * object does not yet exist, creates it. This indirection is used instead of
47 * making all the data members of GlobalPointerRegistry static, so that we
48 * don't have to worry about order dependency during static init time.
49 */
50INLINE GlobalPointerRegistry *GlobalPointerRegistry::
51get_global_ptr() {
52 if (_global_ptr == nullptr) {
53 _global_ptr = new GlobalPointerRegistry;
54 }
55 return _global_ptr;
56}
This class maintains a one-to-one mapping from TypeHandle to a void * pointer.
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.
static void * get_pointer(TypeHandle type)
Returns the pointer associated with the indicated TypeHandle, if any.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81