WARPXM v1.10.0
Loading...
Searching...
No Matches
wmopaqueptr.h
Go to the documentation of this file.
1#ifndef wmopaqueptr_h
2#define wmopaqueptr_h
3//
4// wmopaqueptr.h
5// warpm Xcode project
6//
7// Created by Noah Reddell on 8/9/11.
8// Copyright 2011 University of Washington. All rights reserved.
9//
10
11#include "wmtypewrapper.h"
12
13#include <type_traits>
14
24{
25public:
31 template<typename VALUETYPE>
32 WmOpaquePtr(VALUETYPE* pointer)
33 : _data(pointer), _type(WmTypeWrapper::create<VALUETYPE>())
34 {
35 }
36
37 const WmTypeWrapper getType() const
38 {
39 return _type;
40 }
41
42 void* getDataPtr() const
43 {
44 return _data;
45 }
46
54 template<typename VALUETYPE> VALUETYPE* getTypedPointer() const
55 {
56 static_assert(!(std::is_pointer<VALUETYPE>::value),
57 "getTypedPointer() takes base template type, not pointer type.");
58 // return object or throw exception if types do not match
59 VALUETYPE* result =
60 getType() == typeid(VALUETYPE) ? static_cast<VALUETYPE*>(_data) : NULL;
61
62 // if it is not null, return value else thow exception
63 if (result)
64 return result;
65 else
66 throw std::bad_cast();
67 }
68
69private:
70 void* _data;
71 const WmTypeWrapper _type;
72};
73
81{
82public:
88 template<typename VALUETYPE>
89 WmConstOpaquePtr(const VALUETYPE* pointer)
90 : _data(pointer), _type(WmTypeWrapper::create<VALUETYPE>())
91 {
92 }
93
98 : _data(source.getDataPtr()), _type(source.getType())
99 {
100 }
101
102 const WmTypeWrapper getType() const
103 {
104 return _type;
105 }
106
107 const void* getDataPtr() const
108 {
109 return _data;
110 }
111
119 template<typename VALUETYPE> const VALUETYPE* getTypedPointer() const
120 {
121 static_assert(!(std::is_pointer<VALUETYPE>::value),
122 "getTypedPointer() takes base template type, not pointer type.");
123 // return object or throw exception if types do not match
124 const VALUETYPE* result =
125 getType() == typeid(VALUETYPE) ? static_cast<const VALUETYPE*>(_data) : NULL;
126
127 // if it is not null, return value else thow exception
128 if (result)
129 return result;
130 else
131 throw std::bad_cast();
132 }
133
134private:
135 const void* _data;
136 const WmTypeWrapper _type;
137};
138
140#endif //__wmopaqueptr_h
Opaque Pointer object that carries the referenced data type, but does not expose this payload type as...
Definition: wmopaqueptr.h:81
const void * getDataPtr() const
Definition: wmopaqueptr.h:107
WmConstOpaquePtr(const WmOpaquePtr &source)
convert from WmOpaquePtr to WmConstOpaquePtr
Definition: wmopaqueptr.h:97
const WmTypeWrapper getType() const
Definition: wmopaqueptr.h:102
const VALUETYPE * getTypedPointer() const
Extract the typed pointer from the opaque pointer.
Definition: wmopaqueptr.h:119
WmConstOpaquePtr(const VALUETYPE *pointer)
Create new opaque pointer from a pointer of a given type.
Definition: wmopaqueptr.h:89
Opaque Pointer object that carries the referenced data type, but does not expose this payload type as...
Definition: wmopaqueptr.h:24
const WmTypeWrapper getType() const
Definition: wmopaqueptr.h:37
VALUETYPE * getTypedPointer() const
Extract the typed pointer from the opaque pointer.
Definition: wmopaqueptr.h:54
void * getDataPtr() const
Definition: wmopaqueptr.h:42
WmOpaquePtr(VALUETYPE *pointer)
Create new opaque pointer from a pointer of a given type.
Definition: wmopaqueptr.h:32
Definition: wmtypewrapper.h:21