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 #pragma warning (push) // icc -W4 complains: controlling expression is constant
00266 #pragma warning (disable : 279)
00267         assert(pBase && "don't call this with a NULL pointer");
00268 #pragma warning (pop)
00269         CNodePtr ptrNode(pBase);
00270         switch(ptrNode->GetPrincipalInterfaceType())
00271         {
00272         case intfIValue:
00273             return GENICAM_NAMESPACE::gcstring("IValue");
00274         case intfIInteger:
00275             return GENICAM_NAMESPACE::gcstring("IInteger");
00276         case intfIBoolean:
00277             return GENICAM_NAMESPACE::gcstring("IBoolean");
00278         case intfICommand:
00279             return GENICAM_NAMESPACE::gcstring("ICommand");
00280         case intfIFloat:
00281             return GENICAM_NAMESPACE::gcstring("IFloat");
00282         case intfIString:
00283             return GENICAM_NAMESPACE::gcstring("IString");
00284         case intfIRegister:
00285             return GENICAM_NAMESPACE::gcstring("IRegister");
00286         case intfICategory:
00287             return GENICAM_NAMESPACE::gcstring("ICategory");
00288         case intfIEnumeration:
00289             return GENICAM_NAMESPACE::gcstring("IEnumeration");
00290         case intfIEnumEntry:
00291             return GENICAM_NAMESPACE::gcstring("IEnumEntry");
00292         case intfIPort:
00293             return GENICAM_NAMESPACE::gcstring("IPort");
00294 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage off
00295         case intfIBase:
00296         default:
00297             return GENICAM_NAMESPACE::gcstring("IBase");
00298 // Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage on
00299         }
00300     }
00301 
00303     template <class T, class B>
00304     inline bool IsReadable( const CPointer<T, B>& ptr)
00305     {
00306         return ptr.IsValid() && IsReadable( ptr->GetAccessMode() );
00307     }
00308 
00310     template <class T, class B>
00311     inline bool IsWritable( const CPointer<T, B>& ptr)
00312     {
00313         return ptr.IsValid() && IsWritable( ptr->GetAccessMode() );
00314     }
00315 
00317     template <class T, class B>
00318     inline bool IsImplemented( const CPointer<T, B>& ptr)
00319     {
00320         return ptr.IsValid() && IsImplemented( ptr->GetAccessMode() );
00321     }
00322 
00324     template <class T, class B>
00325     inline bool IsAvailable( const CPointer<T, B>& ptr)
00326     {
00327         return ptr.IsValid() && IsAvailable( ptr->GetAccessMode() );
00328     }
00329 
00330 
00332 
00333 
00334 }
00335 
00336 #endif // ifndef GENAPI_POINTER_H


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06