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  /// Not copyable
111  /// @{
112  UT_RefProxy(const UT_RefProxy<utObj>& copy) = delete;
114  /// @}
115 
116  /// Movable
117  /// @{
119  : myId(src.myId)
120  {
121  src.myId = UT_ProxyPointer::nullId();
122  }
124  {
125  if (this != &src)
126  {
127  // NB: Two UT_RefProxy instances can share the same id, but we
128  // need to remove one reference here even in that case.
129  if (UT_ProxyPointer::isValid(myId)) // might have been moved
131  myId = src.myId;
132  src.myId = UT_ProxyPointer::nullId();
133  }
134  return *this;
135  }
136  /// @}
137 
138  operator const utObj *() const
139  {
140  const void *v = UT_ProxyPointer::lookupProxy(myId);
141  return (const utObj *)v;
142  }
143  operator utObj *()
144  {
145  void *v = UT_ProxyPointer::lookupProxy(myId);
146  return (utObj *)v;
147  }
148  operator int() const
149  {
150  return myId;
151  }
152 
153 private:
154  void init(int id)
155  {
156  myId = id;
158  }
159  int myId;
160 };
161 
162 
163 #endif
164 
static int isValid(int id)
static int allocProxy(void *ptr)
UT_RefProxy< utObj > & operator=(const UT_RefProxy< utObj > &copy)=delete
UT_RefProxy(int id)
Definition: UT_PtrProxy.h:96
static void deReferenceProxy(int id)
GLenum src
Definition: glcorearb.h:1792
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)
const GLdouble * v
Definition: glcorearb.h:836
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:654
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static void freeProxy(int &id)
UT_RefProxy(UT_RefProxy< utObj > &&src)
Definition: UT_PtrProxy.h:118
UT_PtrProxy< utObj > & operator=(UT_PtrProxy< utObj > &&src)
Definition: UT_PtrProxy.h:48
const void * ptr(const T *p)
Definition: format.h:3603
OIIO_API bool copy(string_view from, string_view to, std::string &err)
UT_RefProxy< utObj > & operator=(UT_RefProxy< utObj > &&src)
Definition: UT_PtrProxy.h:123
UT_PtrProxy(utObj *me)
Definition: UT_PtrProxy.h:25
static void swizzlePointer(int id, void *ptr)
UT_PtrProxy(UT_PtrProxy< utObj > &&src)
Definition: UT_PtrProxy.h:43