Panda3D

Loading...
Searching...
No Matches
pointerToVoid.h
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 pointerToVoid.h
10 * @author drose
11 * @date 2004-09-27
12 */
13
14#ifndef POINTERTOVOID_H
15#define POINTERTOVOID_H
16
17#include "pandabase.h"
18#include "pnotify.h"
19#include "memoryBase.h"
20#include "atomicAdjust.h"
21
22#include <algorithm>
23
24/**
25 * This is the non-template part of the base class for PointerTo and
26 * ConstPointerTo. It is necessary so we can keep a pointer to a non-template
27 * class within the ReferenceCount object, to implement weak reference
28 * pointers--we need to have something to clean up when the ReferenceCount
29 * object destructs.
30 *
31 * This is the base class for PointerToBase<T>.
32 */
33 class EXPCL_PANDA_EXPRESS PointerToVoid : public MemoryBase {
34 protected:
35 constexpr PointerToVoid() noexcept = default;
36 //INLINE ~PointerToVoid();
37
38 private:
39 PointerToVoid(const PointerToVoid &copy) = delete;
40
41PUBLISHED:
42 constexpr bool is_null() const;
43 INLINE size_t get_hash() const;
44
45 public:
46 // These comparison functions are common to all things PointerTo, so they're
47 // defined up here.
48 INLINE bool operator < (const void *other) const;
49 INLINE bool operator < (const PointerToVoid &other) const;
50
51 INLINE bool operator == (const PointerToVoid &other) const;
52 INLINE bool operator != (const PointerToVoid &other) const;
53
54 INLINE void swap(PointerToVoid &other) noexcept;
55
56 protected:
57 // Within the PointerToVoid class, we only store a void pointer. This is
58 // actually the (To *) pointer that is typecast to (void *) from the derived
59 // template classes.
60
61 // It is tempting to try to store a (ReferenceCount *) pointer here, but
62 // this is not useful because it prohibits defining, say, PT(PandaNode), or
63 // a PointerTo any class that inherits virtually from ReferenceCount. (You
64 // can't downcast past a virtual inheritance level, but you can always
65 // cross-cast from a void pointer.)
66 AtomicAdjust::Pointer _void_ptr = nullptr;
67};
68
69#include "pointerToVoid.I"
70
71#endif
atomicAdjust.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
MemoryBase
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition memoryBase.h:65
PointerToVoid::is_null
constexpr bool is_null() const
Returns true if the PointerTo is a NULL pointer, false otherwise.
Definition pointerToVoid.I:27
PointerToVoid::swap
void swap(PointerToVoid &other) noexcept
Swaps the contents of this PointerTo with the other, without touching the reference counts.
Definition pointerToVoid.I:78
memoryBase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerToVoid.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.