HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_PtrProxy.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_PtrProxy.h ( UT Library, C++)
7  *
8  * COMMENTS: Template interface to the UT_ProxyPointer methods
9  */
10 
11 #ifndef __UT_PtrProxy__
12 #define __UT_PtrProxy__
13 
14 #include "UT_ProxyPointer.h"
15 
16 
17 //
18 // First half of the proxy pointer interface. The UT_PtrProxy maintains a
19 // pointer to the source object.
20 //
21 template <typename utObj>
23 {
24 public:
25  explicit UT_PtrProxy(utObj *me)
26  {
27  myId = UT_ProxyPointer::allocProxy(me);
28  }
30  {
31  if (UT_ProxyPointer::isValid(myId)) // might have been moved
33  }
34 
35  /// Not copyable
36  /// @{
37  UT_PtrProxy(const UT_PtrProxy<utObj>& copy) = delete;
39  /// @}
40 
41  /// Movable
42  /// @{
44  : myId(src.myId)
45  {
47  }
49  {
50  if (this != &src)
51  {
52  // NB: Two UT_PtrProxy instances cannot share the same id, so this
53  // is not something we need to check for here.
54  if (UT_ProxyPointer::isValid(myId)) // might have been moved
56  myId = src.myId;
58  }
59  return *this;
60  }
61  /// @}
62 
63  int getId() const { return myId; }
64 
65  operator const utObj *() const
66  {
67  const void *v = UT_ProxyPointer::lookupProxy(myId);
68  return (const utObj *)v;
69  }
70  operator utObj *()
71  {
72  void *v = UT_ProxyPointer::lookupProxy(myId);
73  return (utObj *)v;
74  }
75  operator int() const
76  {
77  return myId;
78  }
79  void swizzle(utObj *me)
80  {
82  }
83  unsigned int getReferences() const
84  {
86  }
87 
88 private:
89  int myId;
90 };
91 
92 template <typename utObj>
94 {
95 public:
96  explicit UT_RefProxy(int id)
97  {
98  init(id);
99  }
101  {
102  init(ptr.getId());
103  }
105  {
106  if (UT_ProxyPointer::isValid(myId)) // might have been moved
108  }
109 
110  /// Copyable
111  /// @{
113  {
114  init(copy.myId);
115  }
117  {
118  if (this != &copy)
119  reset(copy.myId);
120  return *this;
121  }
122  /// @}
123 
124  /// Movable
125  /// @{
127  : myId(src.myId)
128  {
129  src.myId = UT_ProxyPointer::nullId();
130  }
132  {
133  if (this != &src)
134  {
135  // NB: Two UT_RefProxy instances can share the same id, but we
136  // need to remove one reference here even in that case.
137  if (UT_ProxyPointer::isValid(myId))
139  myId = src.myId;
140  src.myId = UT_ProxyPointer::nullId();
141  }
142  return *this;
143  }
144  /// @}
145 
147  {
148  if (id != myId)
149  {
150  if (UT_ProxyPointer::isValid(myId))
152  myId = id;
153  if (UT_ProxyPointer::isValid(myId))
155  }
156  }
158  { reset(ptr.getId()); }
159 
160  bool isSet() const { return UT_ProxyPointer::isValid(myId); }
161 
162  operator const utObj *() const
163  {
164  if (UT_ProxyPointer::isValid(myId))
165  {
166  void *v = UT_ProxyPointer::lookupProxy(myId);
167  return static_cast<const utObj *>(v);
168  }
169  return nullptr;
170  }
171  operator utObj *()
172  {
173  if (UT_ProxyPointer::isValid(myId))
174  {
175  void *v = UT_ProxyPointer::lookupProxy(myId);
176  return static_cast<utObj *>(v);
177  }
178  return nullptr;
179  }
180  operator int() const
181  {
182  return myId;
183  }
184 
185 private:
186  void init(int id)
187  {
188  myId = id;
189  if (UT_ProxyPointer::isValid(myId))
191  }
192  int myId;
193 };
194 
195 
196 #endif
197 
static int isValid(int id)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
void reset(const UT_PtrProxy< utObj > &ptr)
Definition: UT_PtrProxy.h:157
static int allocProxy(void *ptr)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
UT_RefProxy(int id)
Definition: UT_PtrProxy.h:96
static void deReferenceProxy(int id)
static void referenceProxy(int id)
unsigned int getReferences() const
Definition: UT_PtrProxy.h:83
static int nullId()
int getId() const
Definition: UT_PtrProxy.h:63
static void * lookupProxy(int id)
UT_RefProxy(const UT_PtrProxy< utObj > &ptr)
Definition: UT_PtrProxy.h:100
static unsigned getReferenceCount(int id)
void swizzle(utObj *me)
Definition: UT_PtrProxy.h:79
UT_PtrProxy< utObj > & operator=(const UT_PtrProxy< utObj > &copy)=delete
GLuint id
Definition: glcorearb.h:655
static void freeProxy(int &id)
UT_RefProxy< utObj > & operator=(const UT_RefProxy< utObj > &copy)
Definition: UT_PtrProxy.h:116
bool isSet() const
Definition: UT_PtrProxy.h:160
UT_RefProxy(UT_RefProxy< utObj > &&src)
Definition: UT_PtrProxy.h:126
UT_PtrProxy< utObj > & operator=(UT_PtrProxy< utObj > &&src)
Definition: UT_PtrProxy.h:48
UT_RefProxy< utObj > & operator=(UT_RefProxy< utObj > &&src)
Definition: UT_PtrProxy.h:131
auto ptr(T p) -> const void *
Definition: format.h:2448
void reset(int id=UT_ProxyPointer::nullId())
Definition: UT_PtrProxy.h:146
UT_PtrProxy(utObj *me)
Definition: UT_PtrProxy.h:25
UT_RefProxy(const UT_RefProxy< utObj > &copy)
Definition: UT_PtrProxy.h:112
static void swizzlePointer(int id, void *ptr)
UT_PtrProxy(UT_PtrProxy< utObj > &&src)
Definition: UT_PtrProxy.h:43
GLenum src
Definition: glcorearb.h:1793