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  myId = src.myId;
54  }
55  return *this;
56  }
57  /// @}
58 
59  int getId() const { return myId; }
60 
61  operator const utObj *() const
62  {
63  const void *v = UT_ProxyPointer::lookupProxy(myId);
64  return (const utObj *)v;
65  }
66  operator utObj *()
67  {
68  void *v = UT_ProxyPointer::lookupProxy(myId);
69  return (utObj *)v;
70  }
71  operator int() const
72  {
73  return myId;
74  }
75  void swizzle(utObj *me)
76  {
78  }
79  unsigned int getReferences() const
80  {
82  }
83 
84 private:
85  int myId;
86 };
87 
88 template <typename utObj>
90 {
91 public:
92  explicit UT_RefProxy(int id)
93  {
94  init(id);
95  }
97  {
98  init(ptr.getId());
99  }
101  {
102  if (UT_ProxyPointer::isValid(myId)) // might have been moved
104  }
105 
106  /// Not copyable
107  /// @{
108  UT_RefProxy(const UT_RefProxy<utObj>& copy) = delete;
110  /// @}
111 
112  /// Movable
113  /// @{
115  : myId(src.myId)
116  {
117  src.myId = UT_ProxyPointer::nullId();
118  }
120  {
121  if (this != &src)
122  {
123  myId = src.myId;
124  src.myId = UT_ProxyPointer::nullId();
125  }
126  return *this;
127  }
128  /// @}
129 
130  operator const utObj *() const
131  {
132  const void *v = UT_ProxyPointer::lookupProxy(myId);
133  return (const utObj *)v;
134  }
135  operator utObj *()
136  {
137  void *v = UT_ProxyPointer::lookupProxy(myId);
138  return (utObj *)v;
139  }
140  operator int() const
141  {
142  return myId;
143  }
144 
145 private:
146  void init(int id)
147  {
148  myId = id;
150  }
151  int myId;
152 };
153 
154 
155 #endif
156 
static int isValid(int id)
GLuint id
Definition: glew.h:1679
GLenum src
Definition: glew.h:2410
static int allocProxy(void *ptr)
UT_RefProxy< utObj > & operator=(const UT_RefProxy< utObj > &copy)=delete
UT_RefProxy(int id)
Definition: UT_PtrProxy.h:92
const GLdouble * v
Definition: glew.h:1391
static void deReferenceProxy(int id)
static void referenceProxy(int id)
unsigned int getReferences() const
Definition: UT_PtrProxy.h:79
static int nullId()
int getId() const
Definition: UT_PtrProxy.h:59
static void * lookupProxy(int id)
UT_RefProxy(const UT_PtrProxy< utObj > &ptr)
Definition: UT_PtrProxy.h:96
static unsigned getReferenceCount(int id)
void swizzle(utObj *me)
Definition: UT_PtrProxy.h:75
UT_PtrProxy< utObj > & operator=(const UT_PtrProxy< utObj > &copy)=delete
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static void freeProxy(int &id)
UT_RefProxy(UT_RefProxy< utObj > &&src)
Definition: UT_PtrProxy.h:114
UT_PtrProxy< utObj > & operator=(UT_PtrProxy< utObj > &&src)
Definition: UT_PtrProxy.h:48
const void * ptr(const T *p)
Definition: format.h:3292
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:119
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