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 
38 namespace GENAPI_NAMESPACE
39 {
40  //*************************************************************
41  // CPointer class
42  //*************************************************************
43 
48  template <class T, class B = IBase>
49  class CPointer
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 
144  T* m_pT;
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 
228  : CPointer<IFloat, IBase>( pB )
229  {
230  }
231 
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
CFloatPtr(IBase *pB)
Constructor from IBase pointer type.
Definition: Pointer.h:227
CPointer< IBase > CBasePtr
SmartPointer for IBase interface pointer.
Definition: Pointer.h:155
bool IsWritable(const CPointer< T, B > &ptr)
Checks if a node is Writable.
Definition: Pointer.h:317
bool operator==(T *pT) const
pointer equal
Definition: Pointer.h:121
IRegister interface.
Definition: Types.h:195
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:58
CPointer< IUserData, INodeMap > CNodeMapUserDataPtr
SmartPointer for IUserData interface pointer.
Definition: Pointer.h:206
CPointer< ICategory > CCategoryPtr
SmartPointer for ICategory interface pointer.
Definition: Pointer.h:164
bool IsValid() const
true if the pointer is valid
Definition: Pointer.h:109
CPointer & operator=(B *pB)
Assign INode Pointer.
Definition: Pointer.h:70
CPointer< IPortRecorder > CPortRecorderPtr
SmartPointer for IPortRecorder interface pointer.
Definition: Pointer.h:191
CPointer< IPort > CPortPtr
SmartPointer for IPort interface pointer.
Definition: Pointer.h:185
T * operator->(void) const
Dereferencing.
Definition: Pointer.h:101
T & operator*(void) const
Dereferencing.
Definition: Pointer.h:85
CPointer< IPortConstruct > CPortConstructPtr
SmartPointer for IPortConstruct interface pointer.
Definition: Pointer.h:258
bool operator==(const CPointer< T, B > &rT) const
pointer equal
Definition: Pointer.h:127
CPointer< IString > CStringPtr
SmartPointer for IString interface pointer.
Definition: Pointer.h:173
T & operator()(void) const
Dereferencing.
Definition: Pointer.h:93
CPointer< ICommand > CCommandPtr
SmartPointer for ICommand interface pointer.
Definition: Pointer.h:214
CPointer< INode > CNodePtr
SmartPointer for INode interface pointer.
Definition: Pointer.h:158
IEnumeration interface.
Definition: Types.h:197
IInteger interface.
Definition: Types.h:190
IInteger * GetIntAlias()
gets the interface of an integer alias node.
Definition: Pointer.h:240
CPointer< IPortWriteList, IPortWriteList > CPortWriteListPtr
SmartPointer for IPortWriteList interface pointer.
Definition: Pointer.h:194
CPointer< IEnumeration > CEnumerationPtr
SmartPointer for IEnumeration interface pointer.
Definition: Pointer.h:179
T * m_pT
Underlying raw pointer.
Definition: Pointer.h:144
IEnumeration * GetEnumAlias()
gets the interface of an enum alias node.
Definition: Pointer.h:246
GENICAM_NAMESPACE::gcstring GetInterfaceName(IBase *pBase)
Definition: Pointer.h:265
Definition of the IFloat interface.
IPort interface.
Definition: Types.h:199
CPointer< IBoolean > CBooleanPtr
SmartPointer for IBoolean interface pointer.
Definition: Pointer.h:167
CPointer< IEnumEntry > CEnumEntryPtr
SmartPointer for IEnumEntry interface pointer.
Definition: Pointer.h:182
IString interface.
Definition: Types.h:194
IBoolean interface.
Definition: Types.h:191
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition: Pointer.h:49
CPointer< IRegister > CRegisterPtr
SmartPointer for IRegister interface pointer.
Definition: Pointer.h:176
CPointer< INodeMap, INodeMap > CNodeMapPtr
SmartPointer for INodeMap interface pointer.
Definition: Pointer.h:200
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBase
Base interface common to all nodes.
Definition: IBase.h:53
CPointer< IValue > CValuePtr
SmartPointer for IValue interface pointer.
Definition: Pointer.h:161
bool IsAvailable(const CPointer< T, B > &ptr)
Checks if a node is Available.
Definition: Pointer.h:331
ICommand interface.
Definition: Types.h:192
bool IsReadable(const CPointer< T, B > &ptr)
Checks if a node is readable.
Definition: Pointer.h:310
#define LOGICAL_ERROR_EXCEPTION
Fires a logical error exception, e.g. throw LOGICAL_ERROR_EXCEPTION("Should never reach this point") ...
Definition: GCException.h:249
CPointer< IPortReplay > CPortReplayPtr
SmartPointer for IPortReplay interface pointer.
Definition: Pointer.h:188
Forward declarations for GenICam types.
CPointer< IPortStackedConstruct > CPortStackedConstructPtr
SmartPointer for IPortStackedConstruct interface pointer.
Definition: Pointer.h:261
Definition of the interface IInteger.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:58
IEnumEntry interface.
Definition: Types.h:198
bool IsImplemented(const CPointer< T, B > &ptr)
Checks if a node is Implemented.
Definition: Pointer.h:324
A string class which is a clone of std::string.
Definition: GCString.h:50
IBase interface.
Definition: Types.h:189
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:112
CPointer(void)
Default constructor.
Definition: Pointer.h:54
ICategory interface.
Definition: Types.h:196
IValue interface.
Definition: Types.h:188
Definition of interface IEnumeration.
IFloat interface.
Definition: Types.h:193
CPointer< IInteger > CIntegerPtr
SmartPointer for IInteger interface pointer.
Definition: Pointer.h:170
CPointer(B *pB)
Constructor from INode pointer type.
Definition: Pointer.h:60
CPointer< ISelector > CSelectorPtr
SmartPointer for ISelector interface pointer.
Definition: Pointer.h:211
bool operator==(int nMustBeNull) const
pointer equal
Definition: Pointer.h:133
CPointer< IUserData > CNodeUserDataPtr
SmartPointer for IUserData interface pointer.
Definition: Pointer.h:208
CFloatPtr()
Default constructor.
Definition: Pointer.h:221
CPointer< IChunkPort > CChunkPortPtr
SmartPointer for IChunkPort interface pointer.
Definition: Pointer.h:197
CFloatPtr & operator=(IBase *pB)
Assign IBase Pointer.
Definition: Pointer.h:233
CPointer< IDeviceInfo, INodeMap > CDeviceInfoPtr
SmartPointer for IDeviceInfo interface pointer.
Definition: Pointer.h:203
Definition: ChunkAdapter.h:37
SmartPointer for IFloat interface pointer.
Definition: Pointer.h:217