GenApi 3.5.1
Pointer.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// (c) 2006 by Basler Vision Technologies
3// Author: Fritz Dierks
4//
5// License: This file is published under the license of the EMVA GenICam Standard Group.
6// A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
7// If for some reason you are missing this file please contact the EMVA or visit the website
8// (http://www.genicam.org) for a full copy.
9//
10// THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
11// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
12// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
14// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
15// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
17// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20// POSSIBILITY OF SUCH DAMAGE.
21//
22//-----------------------------------------------------------------------------
29#ifndef GENAPI_POINTER_H
30#define GENAPI_POINTER_H
31
32#include <assert.h>
33#include <GenICamFwd.h>
34#include <GenApi/IEnumeration.h>
35#include <GenApi/IFloat.h>
36#include <GenApi/IInteger.h>
37
38namespace GENAPI_NAMESPACE
39{
40 //*************************************************************
41 // CPointer class
42 //*************************************************************
43
48 template <class T, class B = IBase>
50 {
51
52 public:
54 CPointer(void) throw()
55 : m_pT( NULL )
56 {
57 }
58
60 CPointer(B *pB)
61 : m_pT( dynamic_cast<T*>(pB) )
62 {
63 }
64
65 virtual ~CPointer(void)
66 {
67 }
68
71 {
72 m_pT = dynamic_cast<T*>(pB);
73 return *this;
74 }
75
77 operator T*(void) const
78 {
79 if (NULL == m_pT)
80 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
81 return m_pT;
82 }
83
85 T& operator*(void) const
86 {
87 if (NULL == m_pT)
88 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
89 return *m_pT;
90 }
91
93 T& operator()(void) const
94 {
95 if (NULL == m_pT)
96 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
97 return *m_pT;
98 }
99
101 T* operator->(void) const
102 {
103 if (NULL == m_pT)
104 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
105 return m_pT;
106 }
107
109 bool IsValid() const throw()
110 {
111 return m_pT != NULL;
112 }
113
115 operator bool(void) const throw()
116 {
117 return m_pT != NULL;
118 }
119
121 bool operator==(T* pT) const
122 {
123 return m_pT == pT;
124 }
125
127 bool operator==(const CPointer<T,B> &rT) const
128 {
129 return m_pT == rT.m_pT;
130 }
131
133 bool operator==(int nMustBeNull) const
134 {
135 if (0 != nMustBeNull)
136 throw LOGICAL_ERROR_EXCEPTION( "argument must be NULL" );
137 return NULL == m_pT;
138 }
139
140
141 protected:
142
145 };
146
147 //*************************************************************
148 // Smartpointer for all interface
149 //*************************************************************
150
153
156
159
162
165
168
171
174
177
180
183
186
189
192
195
198
201
204
209
212
215
217 class CFloatPtr : public CPointer<IFloat, IBase>
218 {
219 public:
221 CFloatPtr() throw()
222 : CPointer<IFloat, IBase>( )
223 {
224 }
225
227 CFloatPtr( IBase *pB )
228 : CPointer<IFloat, IBase>( pB )
229 {
230 }
231
233 CFloatPtr& operator=( IBase *pB )
234 {
236 return *this;
237 }
238
241 {
242 return dynamic_cast<IInteger*>(m_pT->GetNode()->GetCastAlias());
243 }
244
247 {
248 return dynamic_cast<IEnumeration*>(m_pT->GetNode()->GetCastAlias());
249 }
250 };
251
253
256
259
262
266 {
267# ifdef _MSC_VER
268# pragma warning (push) // icc -W4 complains: controlling expression is constant
269# pragma warning (disable : 279)
270# endif
271 assert(pBase && "don't call this with a NULL pointer");
272# ifdef _MSC_VER
273# pragma warning (pop)
274# endif
275 CNodePtr ptrNode(pBase);
276 switch(ptrNode->GetPrincipalInterfaceType())
277 {
278 case intfIValue:
279 return GENICAM_NAMESPACE::gcstring("IValue");
280 case intfIInteger:
281 return GENICAM_NAMESPACE::gcstring("IInteger");
282 case intfIBoolean:
283 return GENICAM_NAMESPACE::gcstring("IBoolean");
284 case intfICommand:
285 return GENICAM_NAMESPACE::gcstring("ICommand");
286 case intfIFloat:
287 return GENICAM_NAMESPACE::gcstring("IFloat");
288 case intfIString:
289 return GENICAM_NAMESPACE::gcstring("IString");
290 case intfIRegister:
291 return GENICAM_NAMESPACE::gcstring("IRegister");
292 case intfICategory:
293 return GENICAM_NAMESPACE::gcstring("ICategory");
294 case intfIEnumeration:
295 return GENICAM_NAMESPACE::gcstring("IEnumeration");
296 case intfIEnumEntry:
297 return GENICAM_NAMESPACE::gcstring("IEnumEntry");
298 case intfIPort:
299 return GENICAM_NAMESPACE::gcstring("IPort");
300// Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage off
301 case intfIBase:
302 default:
303 return GENICAM_NAMESPACE::gcstring("IBase");
304// Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage on
305 }
306 }
307
309 template <class T, class B>
310 inline bool IsReadable( const CPointer<T, B>& ptr)
311 {
312 return ptr.IsValid() && IsReadable( ptr->GetAccessMode() );
313 }
314
316 template <class T, class B>
317 inline bool IsWritable( const CPointer<T, B>& ptr)
318 {
319 return ptr.IsValid() && IsWritable( ptr->GetAccessMode() );
320 }
321
323 template <class T, class B>
324 inline bool IsImplemented( const CPointer<T, B>& ptr)
325 {
326 return ptr.IsValid() && IsImplemented( ptr->GetAccessMode() );
327 }
328
330 template <class T, class B>
331 inline bool IsAvailable( const CPointer<T, B>& ptr)
332 {
333 return ptr.IsValid() && IsAvailable( ptr->GetAccessMode() );
334 }
335
336
338
339
340}
341
342#endif // ifndef GENAPI_POINTER_H
Forward declarations for GenICam types.
Definition of interface IEnumeration.
Definition of the IFloat interface.
Definition of the interface IInteger.
SmartPointer for IFloat interface pointer.
Definition Pointer.h:218
CFloatPtr & operator=(IBase *pB)
Assign IBase Pointer.
Definition Pointer.h:233
CFloatPtr()
Default constructor.
Definition Pointer.h:221
CFloatPtr(IBase *pB)
Constructor from IBase pointer type.
Definition Pointer.h:227
IEnumeration * GetEnumAlias()
gets the interface of an enum alias node.
Definition Pointer.h:246
IInteger * GetIntAlias()
gets the interface of an integer alias node.
Definition Pointer.h:240
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:50
T & operator*(void) const
Dereferencing.
Definition Pointer.h:85
T * m_pT
Underlying raw pointer.
Definition Pointer.h:144
CPointer(B *pB)
Constructor from INode pointer type.
Definition Pointer.h:60
T * operator->(void) const
Dereferencing.
Definition Pointer.h:101
bool operator==(const CPointer< T, B > &rT) const
pointer equal
Definition Pointer.h:127
T & operator()(void) const
Dereferencing.
Definition Pointer.h:93
bool IsValid() const
true if the pointer is valid
Definition Pointer.h:109
CPointer & operator=(B *pB)
Assign INode Pointer.
Definition Pointer.h:70
bool operator==(int nMustBeNull) const
pointer equal
Definition Pointer.h:133
bool operator==(T *pT) const
pointer equal
Definition Pointer.h:121
CPointer(void)
Default constructor.
Definition Pointer.h:54
A string class which is a clone of std::string.
Definition GCString.h:51
#define LOGICAL_ERROR_EXCEPTION
Fires a logical error exception, e.g. throw LOGICAL_ERROR_EXCEPTION("Should never reach this point")
Definition GCException.h:249
GENICAM_NAMESPACE::gcstring GetInterfaceName(IBase *pBase)
Definition Pointer.h:265
@ intfIRegister
IRegister interface.
Definition Types.h:195
@ intfIPort
IPort interface.
Definition Types.h:199
@ intfIBase
IBase interface.
Definition Types.h:189
@ intfIFloat
IFloat interface.
Definition Types.h:193
@ intfIValue
IValue interface.
Definition Types.h:188
@ intfIEnumEntry
IEnumEntry interface.
Definition Types.h:198
@ intfIInteger
IInteger interface.
Definition Types.h:190
@ intfIString
IString interface.
Definition Types.h:194
@ intfIBoolean
IBoolean interface.
Definition Types.h:191
@ intfICategory
ICategory interface.
Definition Types.h:196
@ intfICommand
ICommand interface.
Definition Types.h:192
@ intfIEnumeration
IEnumeration interface.
Definition Types.h:197
bool IsImplemented(EAccessMode AccessMode)
Tests if implemented.
Definition INode.h:212
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBase
Base interface common to all nodes.
Definition IBase.h:53
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition IEnumeration.h:58
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition INode.h:194
bool IsAvailable(EAccessMode AccessMode)
Tests if available.
Definition INode.h:230
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition IFloat.h:58
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition IFloat.h:118
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition INode.h:176