Panda3D
Loading...
Searching...
No Matches
copyOnWritePointer.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 copyOnWritePointer.h
10 * @author drose
11 * @date 2007-04-09
12 */
13
14#ifndef COPYONWRITEPOINTER_H
15#define COPYONWRITEPOINTER_H
16
17#include "pandabase.h"
18
19#include "copyOnWriteObject.h"
20#include "pointerTo.h"
21#include "dcast.h"
22
23/**
24 * This safely stores the primary, owned pointer to a CopyOnWriteObject. At
25 * any time, you may call get_read_pointer() or get_write_pointer() to get a
26 * read-only or modifiable pointer to the object stored.
27 *
28 * There may be multiple copies of a CopyOnWritePointer which all refer to the
29 * same shared object. They will negotiate with each other properly.
30 */
31class EXPCL_PANDA_PUTIL CopyOnWritePointer {
32public:
33 INLINE CopyOnWritePointer(CopyOnWriteObject *object = nullptr);
34 INLINE CopyOnWritePointer(const CopyOnWritePointer &copy);
35 INLINE CopyOnWritePointer(CopyOnWritePointer &&from) noexcept;
37 INLINE ~CopyOnWritePointer();
38
39 INLINE void operator = (const CopyOnWritePointer &copy);
40 INLINE void operator = (CopyOnWritePointer &&from) noexcept;
41 INLINE void operator = (PointerTo<CopyOnWriteObject> &&from) noexcept;
42 INLINE void operator = (CopyOnWriteObject *object);
43
44 INLINE bool operator == (const CopyOnWritePointer &other) const;
45 INLINE bool operator != (const CopyOnWritePointer &other) const;
46 INLINE bool operator < (const CopyOnWritePointer &other) const;
47
48#ifdef COW_THREADED
49 CPT(CopyOnWriteObject) get_read_pointer(Thread *current_thread) const;
50 PT(CopyOnWriteObject) get_write_pointer();
51#else
52 INLINE const CopyOnWriteObject *get_read_pointer(Thread *current_thread) const;
53 INLINE CopyOnWriteObject *get_write_pointer();
54#endif // COW_THREADED
55
56 INLINE CopyOnWriteObject *get_unsafe_pointer();
57
58 INLINE bool is_null() const;
59 INLINE void clear();
60
61 INLINE bool test_ref_count_integrity() const;
62 INLINE bool test_ref_count_nonzero() const;
63
64protected:
65 CopyOnWriteObject *_cow_object;
66};
67
68
69/**
70 * A template wrapper around the above class, mainly to handle the little
71 * typecasting niceties.
72 */
73template <class T>
75public:
76 // By hiding this template from interrogate, we improve compile-time speed
77 // and memory utilization.
78#ifndef CPPPARSER
79 typedef T To;
80
81 INLINE CopyOnWritePointerTo(To *object = nullptr);
83 INLINE CopyOnWritePointerTo(CopyOnWritePointerTo &&from) noexcept;
84 INLINE CopyOnWritePointerTo(PointerTo<T> &&from) noexcept;
85
86 INLINE void operator = (const CopyOnWritePointerTo<T> &copy);
87 INLINE void operator = (To *object);
88 INLINE void operator = (CopyOnWritePointerTo &&from) noexcept;
89 INLINE void operator = (PointerTo<T> &&from) noexcept;
90
91#ifdef COW_THREADED
92 INLINE CPT(To) get_read_pointer(Thread *current_thread = Thread::get_current_thread()) const;
93 INLINE PT(To) get_write_pointer();
94#else
95 INLINE const To *get_read_pointer(Thread *current_thread = Thread::get_current_thread()) const;
96 INLINE To *get_write_pointer();
97#endif // COW_THREADED
98
99 INLINE To *get_unsafe_pointer();
100#endif // CPPPARSER
101};
102
103#define COWPT(type) CopyOnWritePointerTo< type >
104
105#include "copyOnWritePointer.I"
106
107#endif
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
A template wrapper around the above class, mainly to handle the little typecasting niceties.
To * get_unsafe_pointer()
See CopyOnWritePointer::get_unsafe_pointer().
To * get_write_pointer()
See CopyOnWritePointer::get_write_pointer().
const To * get_read_pointer(Thread *current_thread=Thread::get_current_thread()) const
See CopyOnWritePointer::get_read_pointer().
This safely stores the primary, owned pointer to a CopyOnWriteObject.
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
Definition pointerTo.h:69
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.