Panda3D

pointerToVoid.h

00001 // Filename: pointerToVoid.h
00002 // Created by:  drose (27Sep04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef POINTERTOVOID_H
00016 #define POINTERTOVOID_H
00017 
00018 #include "pandabase.h"
00019 #include "pnotify.h"
00020 #include "memoryBase.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : PointerToVoid
00024 // Description : This is the non-template part of the base class for
00025 //               PointerTo and ConstPointerTo.  It is necessary so we
00026 //               can keep a pointer to a non-template class within the
00027 //               ReferenceCount object, to implement weak reference
00028 //               pointers--we need to have something to clean up when
00029 //               the ReferenceCount object destructs.
00030 //
00031 //               This is the base class for PointerToBase<T>.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDAEXPRESS PointerToVoid : public MemoryBase {
00034 protected:
00035   INLINE PointerToVoid();
00036   INLINE ~PointerToVoid();
00037 
00038 private:
00039   INLINE PointerToVoid(const PointerToVoid &copy);
00040 
00041 PUBLISHED:
00042   INLINE bool is_null() const;
00043   INLINE size_t get_hash() const;
00044 
00045 public:
00046   // These comparison functions are common to all things PointerTo, so
00047   // they're defined up here.
00048   INLINE bool operator < (const void *other) const;
00049   INLINE bool operator < (const PointerToVoid &other) const;
00050 
00051   INLINE bool operator == (const PointerToVoid &other) const;
00052   INLINE bool operator != (const PointerToVoid &other) const;
00053 
00054 protected:
00055   // Within the PointerToVoid class, we only store a void pointer.
00056   // This is actually the (To *) pointer that is typecast to (void *)
00057   // from the derived template classes.
00058 
00059   // It is tempting to try to store a (ReferenceCount *) pointer here,
00060   // but this is not useful because it prohibits defining, say,
00061   // PT(PandaNode), or a PointerTo any class that inherits virtually
00062   // from ReferenceCount.  (You can't downcast past a virtual
00063   // inheritance level, but you can always cross-cast from a void
00064   // pointer.)
00065   void *_void_ptr;
00066 };
00067 
00068 #include "pointerToVoid.I"
00069 
00070 #endif
 All Classes Functions Variables Enumerations