Panda3D
 All Classes Functions Variables Enumerations
pointerToVoid.h
1 // Filename: pointerToVoid.h
2 // Created by: drose (27Sep04)
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 #ifndef POINTERTOVOID_H
16 #define POINTERTOVOID_H
17 
18 #include "pandabase.h"
19 #include "pnotify.h"
20 #include "memoryBase.h"
21 #include "atomicAdjust.h"
22 
23 #include <algorithm>
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : PointerToVoid
27 // Description : This is the non-template part of the base class for
28 // PointerTo and ConstPointerTo. It is necessary so we
29 // can keep a pointer to a non-template class within the
30 // ReferenceCount object, to implement weak reference
31 // pointers--we need to have something to clean up when
32 // the ReferenceCount object destructs.
33 //
34 // This is the base class for PointerToBase<T>.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDAEXPRESS PointerToVoid : public MemoryBase {
37 protected:
38  INLINE PointerToVoid();
39  INLINE ~PointerToVoid();
40 
41 private:
42  INLINE PointerToVoid(const PointerToVoid &copy);
43 
44 PUBLISHED:
45  INLINE bool is_null() const;
46  INLINE size_t get_hash() const;
47 
48 public:
49  // These comparison functions are common to all things PointerTo, so
50  // they're defined up here.
51  INLINE bool operator < (const void *other) const;
52  INLINE bool operator < (const PointerToVoid &other) const;
53 
54  INLINE bool operator == (const PointerToVoid &other) const;
55  INLINE bool operator != (const PointerToVoid &other) const;
56 
57  INLINE void swap(PointerToVoid &other) NOEXCEPT;
58 
59 protected:
60  // Within the PointerToVoid class, we only store a void pointer.
61  // This is actually the (To *) pointer that is typecast to (void *)
62  // from the derived template classes.
63 
64  // It is tempting to try to store a (ReferenceCount *) pointer here,
65  // but this is not useful because it prohibits defining, say,
66  // PT(PandaNode), or a PointerTo any class that inherits virtually
67  // from ReferenceCount. (You can't downcast past a virtual
68  // inheritance level, but you can always cross-cast from a void
69  // pointer.)
70  AtomicAdjust::Pointer _void_ptr;
71 };
72 
73 #include "pointerToVoid.I"
74 
75 #endif
This is the non-template part of the base class for PointerTo and ConstPointerTo. ...
Definition: pointerToVoid.h:36
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition: memoryBase.h:73