Pointer.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2006 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Fritz Dierks
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_POINTER_H
00032 #define GENAPI_POINTER_H
00033 
00034 #include <assert.h>
00035 #include <GenICamFwd.h>
00036 #include <GenApi/IEnumeration.h>
00037 #include <GenApi/IFloat.h>
00038 #include <GenApi/IInteger.h>
00039 
00040 namespace GENAPI_NAMESPACE
00041 {
00042     //*************************************************************
00043     // CPointer class
00044     //*************************************************************
00045 
00050     template <class T, class B = IBase>
00051     class CPointer
00052     {
00053 
00054     public:
00056         CPointer(void) throw()
00057             : m_pT( NULL )
00058         {
00059         }
00060 
00062         CPointer( B *pB )
00063             : m_pT( dynamic_cast<T*>(pB) )
00064         {
00065         }
00066 
00067         virtual ~CPointer(void)
00068         {
00069         }
00070 
00072         void operator=( B *pB )
00073         {
00074             m_pT = dynamic_cast<T*>(pB);
00075         }
00076 
00078         operator T*(void) const
00079         {
00080             if (NULL == m_pT)
00081                 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
00082             return m_pT;
00083         }
00084 
00086         T& operator*(void) const
00087         {
00088             if (NULL == m_pT)
00089                 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
00090             return *m_pT;
00091         }
00092 
00094         T& operator()(void) const
00095         {
00096             if (NULL == m_pT)
00097                 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
00098             return *m_pT;
00099         }
00100 
00102         T* operator->(void) const
00103         {
00104             if (NULL == m_pT)
00105                 throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
00106             return m_pT;
00107         }
00108 
00110         bool IsValid() const throw()
00111         {
00112             return m_pT != NULL;
00113         }
00114 
00116         operator bool(void) const throw()
00117         {
00118             return m_pT != NULL;
00119         }
00120 
00122         bool operator==(T* pT) const 
00123         {
00124             return m_pT == pT;
00125         }
00126 
00128         bool operator==(const CPointer<T,B> &rT) const 
00129         {
00130             return m_pT == rT.m_pT;
00131         }
00132 
00134         bool operator==(int nMustBeNull) const
00135         {
00136             if (0 != nMustBeNull)
00137                 throw LOGICAL_ERROR_EXCEPTION( "argument must be NULL" );
00138             return NULL == m_pT;
00139         }
00140 
00141 
00142     protected:
00143 
00145         T* m_pT;
00146     };
00147 
00148     //*************************************************************
00149     // Smartpointer for all interface
00150     //*************************************************************
00151 
00154 
00156     typedef CPointer<IBase> CBasePtr;
00157 
00159     typedef CPointer<INode> CNodePtr;
00160 
00162     typedef CPointer<IValue> CValuePtr;
00163 
00165     typedef CPointer<ICategory> CCategoryPtr;
00166 
00168     typedef CPointer<IBoolean> CBooleanPtr;
00169 
00171     typedef CPointer<IInteger> CIntegerPtr;
00172 
00174     typedef CPointer<IString> CStringPtr;
00175 
00177     typedef CPointer<IRegister> CRegisterPtr;
00178 
00180     typedef CPointer<IEnumeration> CEnumerationPtr;
00181 
00183     typedef CPointer<IEnumEntry> CEnumEntryPtr;
00184 
00186     typedef CPointer<IPort> CPortPtr;
00187 
00189     typedef CPointer<IPortReplay> CPortReplayPtr;
00190 
00192     typedef CPointer<IPortRecorder> CPortRecorderPtr;
00193 
00195     typedef CPointer<IPortWriteList, IPortWriteList> CPortWriteListPtr;
00196 
00198     typedef CPointer<IChunkPort> CChunkPortPtr;
00199 
00201     typedef CPointer<INodeMap, INodeMap> CNodeMapPtr;
00202 
00204     typedef CPointer<IDeviceInfo, INodeMap> CDeviceInfoPtr;
00205 
00207     typedef CPointer<IUserData, INodeMap> CNodeMapUserDataPtr;
00209     typedef CPointer<IUserData> CNodeUserDataPtr;
00210 
00212     typedef CPointer<ISelector> CSelectorPtr;
00213 
00215      typedef CPointer<ICommand> CCommandPtr;
00216 
00218     class CFloatPtr : public CPointer<IFloat, IBase>
00219     {
00220     public:
00222         CFloatPtr() throw()
00223             : CPointer<IFloat, IBase>(  )
00224         {
00225         }
00226 
00228         CFloatPtr( IBase *pB )
00229             : CPointer<IFloat, IBase>( pB )
00230         {
00231         }
00232 
00234         void operator=( IBase *pB )
00235         {
00236             CPointer<IFloat, IBase>::operator =(pB);
00237         }
00238 
00240         IInteger *GetIntAlias()
00241         {
00242             return dynamic_cast<IInteger*>(m_pT->GetNode()->GetCastAlias());
00243         }
00244 
00246         IEnumeration *GetEnumAlias()
00247         {
00248             return dynamic_cast<IEnumeration*>(m_pT->GetNode()->GetCastAlias());
00249         }
00250     };
00251 
00253 
00256 
00258     typedef CPointer<IPortConstruct> CPortConstructPtr;
00259 
00260 
00263     inline GENICAM_NAMESPACE::gcstring GetInterfaceName(IBase *pBase)
00264     {
00265 #       ifdef _MSC_VER
00266 #           pragma warning (push) // icc -W4 complains: controlling expression is constant
00267 #           pragma warning (disable : 279)
00268 #       endif
00269         assert(pBase && "don't call this with a NULL pointer");
00270 #       ifdef _MSC_VER
00271 #           pragma warning (pop)
00272 #       endif
00273         CNodePtr ptrNode(pBase);
00274         switch(ptrNode->GetPrincipalInterfaceType())
00275         {
00276         case intfIValue:
00277             return GENICAM_NAMESPACE::gcstring("IValue");
00278         case intfIInteger:
00279             return GENICAM_NAMESPACE::gcstring("IInteger");
00280         case intfIBoolean:
00281             return GENICAM_NAMESPACE::gcstring("IBoolean");
00282         case intfICommand:
00283             return GENICAM_NAMESPACE::gcstring("ICommand");
00284         case intfIFloat:
00285             return GENICAM_NAMESPACE::gcstring("IFloat");
00286         case intfIString:
00287             return GENICAM_NAMESPACE::gcstring("IString");
00288         case intfIRegister:
00289             return GENICAM_NAMESPACE::gcstring("IRegister");
00290         case intfICategory:
00291             return GENICAM_NAMESPACE::gcstring("ICategory");
00292         case intfIEnumeration:
00293             return GENICAM_NAMESPACE::gcstring("IEnumeration");
00294         case intfIEnumEntry:
00295             return GENICAM_NAMESPACE::gcstring("IEnumEntry");
00296         case intfIPort:
00297             return GENICAM_NAMESPACE::gcstring("IPort");
00298 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage off
00299         case intfIBase:
00300         default:
00301             return GENICAM_NAMESPACE::gcstring("IBase");
00302 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage on
00303         }
00304     }
00305 
00307     template <class T, class B>
00308     inline bool IsReadable( const CPointer<T, B>& ptr)
00309     {
00310         return ptr.IsValid() && IsReadable( ptr->GetAccessMode() );
00311     }
00312 
00314     template <class T, class B>
00315     inline bool IsWritable( const CPointer<T, B>& ptr)
00316     {
00317         return ptr.IsValid() && IsWritable( ptr->GetAccessMode() );
00318     }
00319 
00321     template <class T, class B>
00322     inline bool IsImplemented( const CPointer<T, B>& ptr)
00323     {
00324         return ptr.IsValid() && IsImplemented( ptr->GetAccessMode() );
00325     }
00326 
00328     template <class T, class B>
00329     inline bool IsAvailable( const CPointer<T, B>& ptr)
00330     {
00331         return ptr.IsValid() && IsAvailable( ptr->GetAccessMode() );
00332     }
00333 
00334 
00336 
00337 
00338 }
00339 
00340 #endif // ifndef GENAPI_POINTER_H


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47