// Filename: globalPointerRegistry.I
// Created by:  drose (03Feb00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////
//     Function: GlobalPointerRegistry::get_pointer
//       Access: Public, Static
//  Description: Returns the pointer associated with the indicated
//               TypeHandle, if any.  If no pointer has yet been
//               associated, returns NULL.
////////////////////////////////////////////////////////////////////
INLINE void *GlobalPointerRegistry::
get_pointer(TypeHandle type) {
  return get_global_ptr()->ns_get_pointer(type);
}

////////////////////////////////////////////////////////////////////
//     Function: GlobalPointerRegistry::store_pointer
//       Access: Public, Static
//  Description: Associates the given pointer with the indicated
//               TypeHandle.  It is an error to call this with a NULL
//               pointer, or to call this function more than once with
//               a given TypeHandle (without first calling
//               clear_pointer).
////////////////////////////////////////////////////////////////////
INLINE void GlobalPointerRegistry::
store_pointer(TypeHandle type, void *ptr) {
  get_global_ptr()->ns_store_pointer(type, ptr);
}

////////////////////////////////////////////////////////////////////
//     Function: GlobalPointerRegistry::clear_pointer
//       Access: Public, Static
//  Description: Removes the association of the given pointer with the
//               indicated TypeHandle.  Subsequent calls to
//               get_pointer() with this TypeHandle will return NULL,
//               until another call to store_pointer() is made.
////////////////////////////////////////////////////////////////////
INLINE void GlobalPointerRegistry::
clear_pointer(TypeHandle type) {
  get_global_ptr()->ns_clear_pointer(type);
}


////////////////////////////////////////////////////////////////////
//     Function: GlobalPointerRegistry::get_global_pointer
//       Access: Private, Static
//  Description: Returns a pointer to the single GlobalPointerRegistry
//               object.  If the object does not yet exist, creates
//               it.  This indirection is used instead of making all
//               the data members of GlobalPointerRegistry static, so
//               that we don't have to worry about order dependency
//               during static init time.
////////////////////////////////////////////////////////////////////
INLINE GlobalPointerRegistry *GlobalPointerRegistry::
get_global_ptr() {
  if (_global_ptr == (GlobalPointerRegistry *)NULL) {
    _global_ptr = new GlobalPointerRegistry;
  }
  return _global_ptr;
}
