libMVRgdtf 40bc00a
A library for GDTF and MVR
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorworksMVR.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <stdint.h>
6#include <cstring>
7#include <memory>
8
9// ---------------------------------------------------------------------------------------------------
10// Support
11namespace VectorworksMVR
12{
13 // ---------------------------------------------------------------------------------------------------
14 #ifdef _WIN32
15 #ifdef EXPORT_STATIC
16 #define EXPORT_MVR_CLASS
17 #else
18 #ifdef EXPORT_SYMBOLS
19 #define EXPORT_MVR_CLASS __declspec(dllexport)
20 #else
21 #define EXPORT_MVR_CLASS __declspec(dllimport)
22 #endif
23 #endif
24 #elif _LINUX
25 #define EXPORT_MVR_CLASS __attribute__((visibility("default")))
26 #else
27 #define EXPORT_MVR_CLASS __attribute__((visibility("default")))
28 #endif
29
30 // ---------------------------------------------------------------------------------------------------
31 struct VWIID
32 {
33 uint32_t data1;
34 uint16_t data2;
35 uint16_t data3;
36 uint8_t data4[8];
37
38 VWIID& operator = (const VWIID& iid) {
39#if _LINUX
40 std::memcpy( this, &iid, sizeof(VWIID) );
41#else
42 memcpy( this, &iid, sizeof(VWIID) );
43#endif
44 return *this;
45 }
46
47 bool operator == (const VWIID& iid) const {
48#if _LINUX
49 return std::memcmp( this, &iid, sizeof(VWIID) ) == 0;
50#else
51 return memcmp( this, &iid, sizeof(VWIID) ) == 0;
52#endif
53 }
54
55 bool operator < (const VWIID& iid) const {
56 bool isLess = true;
57 bool isEqual = true;
58
59 // data1
60 if ( isEqual ) {
61 isEqual = isEqual && data1 == iid.data1;
62 if ( ! isEqual ) { isLess = (data1 < iid.data1); }
63
64 // data2
65 if ( isEqual ) {
66 isEqual = isEqual && data2 == iid.data2;
67 if ( ! isEqual ) { isLess = (data2 < iid.data2); }
68
69 // data3
70 if ( isEqual ) {
71 isEqual = isEqual && data3 == iid.data3;
72 if ( ! isEqual ) { isLess = (data3 < iid.data3); }
73
74 // data4
75 for(uint32_t i=0; i<8 && isEqual; i++) {
76 isEqual = isEqual && data4[i] == iid.data4[i];
77 if ( ! isEqual ) { isLess = (data4[i] < iid.data4[i]); }
78 }
79 }
80 }
81 }
82
83 return isLess && ! isEqual;
84 }
85 void SetToNULL(void) { memset(this, 0, sizeof(VWIID)); }
86 bool IsNULL(void) const { VWIID compare; compare.SetToNULL(); return(*this == compare);}
87 };
88
89 // ---------------------------------------------------------------------------------------------------
90 #ifdef _WIN32
91 # define VCOM_CALLTYPE __stdcall
92 #else
93 # define VCOM_CALLTYPE
94 #endif
95
96 // ---------------------------------------------------------------------------------------------------
97 // We define Dynamic Attribute modificator so VCOM and other C++ interfaces
98 // could participate in static_cast operator on Mac.
99 // This is a bug (or issue) in Mac compiler that causes static_cast operator to fail
100 // if the interface instance is from local memory of a DLL!
101 #ifdef _WIN32
102 # define DYNAMIC_ATTRIBUTE
103 #else
104 # define DYNAMIC_ATTRIBUTE __attribute__((visibility("default")))
105 #endif
106
107 // ---------------------------------------------------------------------------------------------------
109 {
110 public:
111 virtual ~IVWUnknown( void ) {}
112 virtual uint32_t VCOM_CALLTYPE AddRef() = 0;
113 virtual uint32_t VCOM_CALLTYPE Release() = 0;
114
115 };
116
117 // ---------------------------------------------------------------------------------------------------
118 // VCOM errors
119 typedef uint32_t VCOMError;
120
130
137
143
144 // ---------------------------------------------------------------------------------------------------
145 extern "C" VCOMError VWQueryInterface(const VWIID& iid, IVWUnknown** outInterface);
146
147 // ---------------------------------------------------------------------------------------------------
148 template<class T> class VCOMPtr
149 {
150 public:
151 VCOMPtr() { fPtr = NULL; }
152 VCOMPtr(T* ptr) { fPtr = ptr; if ( fPtr ) { fPtr->AddRef(); } }
153 VCOMPtr(const VWIID& iid) { fPtr = NULL; this->Query( iid ); }
154 VCOMPtr(const VCOMPtr& p) { fPtr = p.fPtr; if ( fPtr ) { fPtr->AddRef(); } }
155 ~VCOMPtr() { this->Release(); }
156
157 VCOMError Query(const VWIID& iid) {
158 this->Release();
159 IVWUnknown* pInterface = NULL;
160 VCOMError err = VectorworksMVR::VWQueryInterface( iid, & pInterface );
161 if ( err == kVCOMError_NoError ) {
162 // Vlado: Temporally removed 'static_cast'
163 // because on new Mac OS it is failing to cast properly
164 //fPtr = static_cast<T*>( pInterface );
165 fPtr = (T*)( pInterface );
166 if ( fPtr == NULL ) {
167 if ( pInterface ) {
168 pInterface->Release();
169 pInterface = NULL;
170 }
171 // the passed 'iid' is not from the extected type 'T'
173 }
174 }
175 return err;
176 }
177 void AddRef() { if ( fPtr ) { fPtr->AddRef(); } }
178 uint32_t Release() { uint32_t res = 0; if ( fPtr ) { res = fPtr->Release(); } fPtr = NULL; return res; }
179
180 VCOMPtr& operator=(T* ptr) { T* pOld = fPtr; fPtr = ptr; if ( fPtr ) { fPtr->AddRef(); } if ( pOld ) { pOld->Release(); } return *this; }
181 VCOMPtr& operator=(const VCOMPtr& p) { T* pOld = fPtr; fPtr = p.fPtr; if ( fPtr ) { fPtr->AddRef(); } if ( pOld ) { pOld->Release(); } return *this; }
182
183 T* operator->() const { return fPtr; }
184 T** operator&() { return & fPtr; }
185 operator T*() const { return fPtr; }
186
187 protected:
188 T* Get() const { return fPtr; }
189 void Set(T* p) { fPtr = p; }
190
191 private:
192 T* fPtr;
193 };
194}
195
196// ---------------------------------------------------------------------------------------------------
197// Interfaces
199
#define VCOM_CALLTYPE
Definition VectorworksMVR.h:93
#define DYNAMIC_ATTRIBUTE
Definition VectorworksMVR.h:104
Definition VectorworksMVR.h:109
virtual uint32_t VCOM_CALLTYPE Release()=0
virtual uint32_t VCOM_CALLTYPE AddRef()=0
virtual ~IVWUnknown(void)
Definition VectorworksMVR.h:111
Definition VectorworksMVR.h:149
void Set(T *p)
Definition VectorworksMVR.h:189
uint32_t Release()
Definition VectorworksMVR.h:178
T * Get() const
Definition VectorworksMVR.h:188
VCOMPtr(T *ptr)
Definition VectorworksMVR.h:152
VCOMPtr()
Definition VectorworksMVR.h:151
VCOMPtr & operator=(T *ptr)
Definition VectorworksMVR.h:180
T * operator->() const
Definition VectorworksMVR.h:183
VCOMPtr(const VWIID &iid)
Definition VectorworksMVR.h:153
T ** operator&()
Definition VectorworksMVR.h:184
VCOMError Query(const VWIID &iid)
Definition VectorworksMVR.h:157
VCOMPtr(const VCOMPtr &p)
Definition VectorworksMVR.h:154
void AddRef()
Definition VectorworksMVR.h:177
~VCOMPtr()
Definition VectorworksMVR.h:155
VCOMPtr & operator=(const VCOMPtr &p)
Definition VectorworksMVR.h:181
Definition CieColor.h:9
const VCOMError kVCOMError_WrongRDMParameterValueType
Definition VectorworksMVR.h:140
const VCOMError kVCOMError_WrongGeometryType
Definition VectorworksMVR.h:139
const VCOMError kVCOMError_OutOfBounds
Definition VectorworksMVR.h:136
const VCOMError kVCOMError_SlaveMasterNotInSameMode
Definition VectorworksMVR.h:141
VCOMError VWQueryInterface(const VWIID &iid, IVWUnknown **outInterface)
const VCOMError kVCOMError_NoValidContainerObj
Definition VectorworksMVR.h:133
const VCOMError kVCOMError_False
Definition VectorworksMVR.h:123
const VCOMError kVCOMError_Failed
Definition VectorworksMVR.h:122
const VCOMError kVCOMError_NoInterface
Definition VectorworksMVR.h:126
const VCOMError kVCOMError_NoError
Definition VectorworksMVR.h:121
const VCOMError kVCOMError_NoObj
Definition VectorworksMVR.h:142
const VCOMError kVCOMError_NotInitialized
Definition VectorworksMVR.h:125
const VCOMError kVCOMError_NoFixtureObj
Definition VectorworksMVR.h:135
uint32_t VCOMError
Definition VectorworksMVR.h:119
const VCOMError kVCOMError_NoLayerObj
Definition VectorworksMVR.h:134
const VCOMError kVCOMError_OutOfMemory
Definition VectorworksMVR.h:124
const VCOMError kVCOMError_NotSet
Definition VectorworksMVR.h:138
const VCOMError kVCOMError_NoProjectorObj
Definition VectorworksMVR.h:131
const VCOMError kVCOMError_InvalidArg
Definition VectorworksMVR.h:128
const VCOMError kVCOMError_NotImplemented
Definition VectorworksMVR.h:127
const VCOMError kVCOMError_NoVideoScreenObj
Definition VectorworksMVR.h:132
const VCOMError kVCOMError_NoInstance
Definition VectorworksMVR.h:129
Definition VectorworksMVR.h:32
uint16_t data2
Definition VectorworksMVR.h:34
uint8_t data4[8]
Definition VectorworksMVR.h:36
bool operator==(const VWIID &iid) const
Definition VectorworksMVR.h:47
bool operator<(const VWIID &iid) const
Definition VectorworksMVR.h:55
void SetToNULL(void)
Definition VectorworksMVR.h:85
uint32_t data1
Definition VectorworksMVR.h:33
VWIID & operator=(const VWIID &iid)
Definition VectorworksMVR.h:38
uint16_t data3
Definition VectorworksMVR.h:35
bool IsNULL(void) const
Definition VectorworksMVR.h:86