Pointer.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Fritz Dierks
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_POINTER_H
32 #define GENAPI_POINTER_H
33 
34 #include <assert.h>
35 #include <GenICamFwd.h>
36 #include <GenApi/IEnumeration.h>
37 #include <GenApi/IFloat.h>
38 #include <GenApi/IInteger.h>
39 
40 namespace GENAPI_NAMESPACE
41 {
42  //*************************************************************
43  // CPointer class
44  //*************************************************************
45 
50  template <class T, class B = IBase>
51  class CPointer
52  {
53 
54  public:
56  CPointer(void) throw()
57  : m_pT( NULL )
58  {
59  }
60 
62  CPointer( B *pB )
63  : m_pT( dynamic_cast<T*>(pB) )
64  {
65  }
66 
67  virtual ~CPointer(void)
68  {
69  }
70 
72  void operator=( B *pB )
73  {
74  m_pT = dynamic_cast<T*>(pB);
75  }
76 
78  operator T*(void) const
79  {
80  if (NULL == m_pT)
81  throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
82  return m_pT;
83  }
84 
86  T& operator*(void) const
87  {
88  if (NULL == m_pT)
89  throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
90  return *m_pT;
91  }
92 
94  T& operator()(void) const
95  {
96  if (NULL == m_pT)
97  throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
98  return *m_pT;
99  }
100 
102  T* operator->(void) const
103  {
104  if (NULL == m_pT)
105  throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
106  return m_pT;
107  }
108 
110  bool IsValid() const throw()
111  {
112  return m_pT != NULL;
113  }
114 
116  operator bool(void) const throw()
117  {
118  return m_pT != NULL;
119  }
120 
122  bool operator==(T* pT) const
123  {
124  return m_pT == pT;
125  }
126 
128  bool operator==(const CPointer<T,B> &rT) const
129  {
130  return m_pT == rT.m_pT;
131  }
132 
134  bool operator==(int nMustBeNull) const
135  {
136  if (0 != nMustBeNull)
137  throw LOGICAL_ERROR_EXCEPTION( "argument must be NULL" );
138  return NULL == m_pT;
139  }
140 
141 
142  protected:
143 
145  T* m_pT;
146  };
147 
148  //*************************************************************
149  // Smartpointer for all interface
150  //*************************************************************
151 
154 
157 
160 
163 
166 
169 
172 
175 
178 
181 
184 
187 
190 
193 
196 
199 
202 
205 
210 
213 
216 
218  class CFloatPtr : public CPointer<IFloat, IBase>
219  {
220  public:
222  CFloatPtr() throw()
223  : CPointer<IFloat, IBase>( )
224  {
225  }
226 
229  : CPointer<IFloat, IBase>( pB )
230  {
231  }
232 
234  void operator=( IBase *pB )
235  {
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 
260 
264  {
265 # ifdef _MSC_VER
266 # pragma warning (push) // icc -W4 complains: controlling expression is constant
267 # pragma warning (disable : 279)
268 # endif
269  assert(pBase && "don't call this with a NULL pointer");
270 # ifdef _MSC_VER
271 # pragma warning (pop)
272 # endif
273  CNodePtr ptrNode(pBase);
274  switch(ptrNode->GetPrincipalInterfaceType())
275  {
276  case intfIValue:
277  return GENICAM_NAMESPACE::gcstring("IValue");
278  case intfIInteger:
279  return GENICAM_NAMESPACE::gcstring("IInteger");
280  case intfIBoolean:
281  return GENICAM_NAMESPACE::gcstring("IBoolean");
282  case intfICommand:
283  return GENICAM_NAMESPACE::gcstring("ICommand");
284  case intfIFloat:
285  return GENICAM_NAMESPACE::gcstring("IFloat");
286  case intfIString:
287  return GENICAM_NAMESPACE::gcstring("IString");
288  case intfIRegister:
289  return GENICAM_NAMESPACE::gcstring("IRegister");
290  case intfICategory:
291  return GENICAM_NAMESPACE::gcstring("ICategory");
292  case intfIEnumeration:
293  return GENICAM_NAMESPACE::gcstring("IEnumeration");
294  case intfIEnumEntry:
295  return GENICAM_NAMESPACE::gcstring("IEnumEntry");
296  case intfIPort:
297  return GENICAM_NAMESPACE::gcstring("IPort");
298 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage off
299  case intfIBase:
300  default:
301  return GENICAM_NAMESPACE::gcstring("IBase");
302 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage on
303  }
304  }
305 
307  template <class T, class B>
308  inline bool IsReadable( const CPointer<T, B>& ptr)
309  {
310  return ptr.IsValid() && IsReadable( ptr->GetAccessMode() );
311  }
312 
314  template <class T, class B>
315  inline bool IsWritable( const CPointer<T, B>& ptr)
316  {
317  return ptr.IsValid() && IsWritable( ptr->GetAccessMode() );
318  }
319 
321  template <class T, class B>
322  inline bool IsImplemented( const CPointer<T, B>& ptr)
323  {
324  return ptr.IsValid() && IsImplemented( ptr->GetAccessMode() );
325  }
326 
328  template <class T, class B>
329  inline bool IsAvailable( const CPointer<T, B>& ptr)
330  {
331  return ptr.IsValid() && IsAvailable( ptr->GetAccessMode() );
332  }
333 
334 
336 
337 
338 }
339 
340 #endif // ifndef GENAPI_POINTER_H
bool operator==(int nMustBeNull) const
pointer equal
Definition: Pointer.h:134
CPointer(void)
Default constructor.
Definition: Pointer.h:56
IFloat interface.
Definition: Types.h:196
CPointer< ISelector > CSelectorPtr
SmartPointer for ISelector interface pointer.
Definition: Pointer.h:212
CPointer< IPortReplay > CPortReplayPtr
SmartPointer for IPortReplay interface pointer.
Definition: Pointer.h:189
ICommand interface.
Definition: Types.h:195
IPort interface.
Definition: Types.h:202
CPointer< IChunkPort > CChunkPortPtr
SmartPointer for IChunkPort interface pointer.
Definition: Pointer.h:198
IBase interface.
Definition: Types.h:192
CPointer< IString > CStringPtr
SmartPointer for IString interface pointer.
Definition: Pointer.h:174
CPointer< IUserData, INodeMap > CNodeMapUserDataPtr
SmartPointer for IUserData interface pointer.
Definition: Pointer.h:207
bool operator==(T *pT) const
pointer equal
Definition: Pointer.h:122
CFloatPtr()
Default constructor.
Definition: Pointer.h:222
CPointer< IValue > CValuePtr
SmartPointer for IValue interface pointer.
Definition: Pointer.h:162
CFloatPtr(IBase *pB)
Constructor from IBase pointer type.
Definition: Pointer.h:228
bool operator==(const CPointer< T, B > &rT) const
pointer equal
Definition: Pointer.h:128
T * operator->(void) const
Dereferencing.
Definition: Pointer.h:102
CPointer< IDeviceInfo, INodeMap > CDeviceInfoPtr
SmartPointer for IDeviceInfo interface pointer.
Definition: Pointer.h:204
CPointer< IPortRecorder > CPortRecorderPtr
SmartPointer for IPortRecorder interface pointer.
Definition: Pointer.h:192
interface GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
T & operator()(void) const
Dereferencing.
Definition: Pointer.h:94
CPointer< IPort > CPortPtr
SmartPointer for IPort interface pointer.
Definition: Pointer.h:186
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
interface GENAPI_DECL_ABSTRACT IInteger
Interface for integer properties.
Definition: IInteger.h:61
T & operator*(void) const
Dereferencing.
Definition: Pointer.h:86
interface GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
T * m_pT
Underlying raw pointer.
Definition: Pointer.h:145
GENICAM_NAMESPACE::gcstring GetInterfaceName(IBase *pBase)
Returns the name of the main interface as string DEPRECATED, use IBase::GetPrincipalInterfaceType() i...
Definition: Pointer.h:263
Definition of the IFloat interface.
IString interface.
Definition: Types.h:197
IBoolean interface.
Definition: Types.h:194
IEnumeration * GetEnumAlias()
gets the interface of an enum alias node.
Definition: Pointer.h:246
interface GENAPI_DECL_ABSTRACT IBase
Base interface common to all nodes.
Definition: IBase.h:55
CPointer< IUserData > CNodeUserDataPtr
SmartPointer for IUserData interface pointer.
Definition: Pointer.h:209
bool IsAvailable(EAccessMode AccessMode)
Tests if available.
Definition: INode.h:232
CPointer< IBoolean > CBooleanPtr
SmartPointer for IBoolean interface pointer.
Definition: Pointer.h:168
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition: Pointer.h:51
CPointer< INode > CNodePtr
SmartPointer for INode interface pointer.
Definition: Pointer.h:159
IValue interface.
Definition: Types.h:191
CPointer< IEnumEntry > CEnumEntryPtr
SmartPointer for IEnumEntry interface pointer.
Definition: Pointer.h:183
ICategory interface.
Definition: Types.h:199
CPointer< INodeMap, INodeMap > CNodeMapPtr
SmartPointer for INodeMap interface pointer.
Definition: Pointer.h:201
void operator=(IBase *pB)
Assign IBase Pointer.
Definition: Pointer.h:234
#define LOGICAL_ERROR_EXCEPTION
Fires a logical error exception, e.g. throw LOGICAL_ERROR_EXCEPTION("Should never reach this point") ...
Definition: GCException.h:249
bool IsImplemented(EAccessMode AccessMode)
Tests if implemented.
Definition: INode.h:214
CPointer< IBase > CBasePtr
SmartPointer for IBase interface pointer.
Definition: Pointer.h:156
IInteger * GetIntAlias()
gets the interface of an integer alias node.
Definition: Pointer.h:240
Forward declarations for GenICam types.
Definition of the interface IInteger.
CPointer< IInteger > CIntegerPtr
SmartPointer for IInteger interface pointer.
Definition: Pointer.h:171
A string class which is a clone of std::string.
Definition: GCString.h:52
CPointer< IRegister > CRegisterPtr
SmartPointer for IRegister interface pointer.
Definition: Pointer.h:177
virtual ~CPointer(void)
Definition: Pointer.h:67
bool IsValid() const
true if the pointer is valid
Definition: Pointer.h:110
CPointer< IPortWriteList, IPortWriteList > CPortWriteListPtr
SmartPointer for IPortWriteList interface pointer.
Definition: Pointer.h:195
CPointer< IPortConstruct > CPortConstructPtr
SmartPointer for IPortConstruct interface pointer.
Definition: Pointer.h:258
IEnumeration interface.
Definition: Types.h:200
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition: INode.h:196
Definition of interface IEnumeration.
IRegister interface.
Definition: Types.h:198
IEnumEntry interface.
Definition: Types.h:201
IInteger interface.
Definition: Types.h:193
CPointer< IEnumeration > CEnumerationPtr
SmartPointer for IEnumeration interface pointer.
Definition: Pointer.h:180
CPointer< ICommand > CCommandPtr
SmartPointer for ICommand interface pointer.
Definition: Pointer.h:215
Part of the generic device API.
Definition: Autovector.h:48
CPointer< ICategory > CCategoryPtr
SmartPointer for ICategory interface pointer.
Definition: Pointer.h:165
void operator=(B *pB)
Assign INode Pointer.
Definition: Pointer.h:72
SmartPointer for IFloat interface pointer.
Definition: Pointer.h:218
CPointer(B *pB)
Constructor from INode pointer type.
Definition: Pointer.h:62


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54