GenApi/Pointer.h#
Namespaces#
Name |
---|
GenApi Contains definitions of the types of GenICam GenApi modules. |
Classes#
Name | |
---|---|
class | GenApi::CPointer Encapsulates a GenApi pointer dealing with the dynamic_cast automatically. |
class | GenApi::CFloatPtr SmartPointer for IFloat interface pointer. |
Source code#
//-----------------------------------------------------------------------------
// (c) 2006 by Basler Vision Technologies
// Section: Vision Components
// Project: GenApi
// Author: Fritz Dierks
// $Header$
//
// License: This file is published under the license of the EMVA GenICam Standard Group.
// A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
// If for some reason you are missing this file please contact the EMVA or visit the website
// (http://www.genicam.org) for a full copy.
//
// THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
#ifndef GENAPI_POINTER_H
#define GENAPI_POINTER_H
#include <assert.h>
#include <GenICamFwd.h>
#include <GenApi/IEnumeration.h>
#include <GenApi/IFloat.h>
#include <GenApi/IInteger.h>
namespace GENAPI_NAMESPACE
{
//*************************************************************
// CPointer class
//*************************************************************
template <class T, class B = IBase>
class CPointer
{
public:
CPointer(void) throw()
: m_pT( NULL )
{
}
CPointer( B *pB )
: m_pT( dynamic_cast<T*>(pB) )
{
}
virtual ~CPointer(void)
{
}
void operator=( B *pB )
{
m_pT = dynamic_cast<T*>(pB);
}
operator T*(void) const
{
if (NULL == m_pT)
throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
return m_pT;
}
T& operator*(void) const
{
if (NULL == m_pT)
throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
return *m_pT;
}
T& operator()(void) const
{
if (NULL == m_pT)
throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
return *m_pT;
}
T* operator->(void) const
{
if (NULL == m_pT)
throw LOGICAL_ERROR_EXCEPTION( "NULL pointer dereferenced" );
return m_pT;
}
bool IsValid() const throw()
{
return m_pT != NULL;
}
operator bool(void) const throw()
{
return m_pT != NULL;
}
bool operator==(T* pT) const
{
return m_pT == pT;
}
bool operator==(const CPointer<T,B> &rT) const
{
return m_pT == rT.m_pT;
}
bool operator==(int nMustBeNull) const
{
if (0 != nMustBeNull)
throw LOGICAL_ERROR_EXCEPTION( "argument must be NULL" );
return NULL == m_pT;
}
protected:
T* m_pT;
};
//*************************************************************
// Smartpointer for all interface
//*************************************************************
typedef CPointer<IBase> CBasePtr;
typedef CPointer<INode> CNodePtr;
typedef CPointer<IValue> CValuePtr;
typedef CPointer<ICategory> CCategoryPtr;
typedef CPointer<IBoolean> CBooleanPtr;
typedef CPointer<IInteger> CIntegerPtr;
typedef CPointer<IString> CStringPtr;
typedef CPointer<IRegister> CRegisterPtr;
typedef CPointer<IEnumeration> CEnumerationPtr;
typedef CPointer<IEnumEntry> CEnumEntryPtr;
typedef CPointer<IPort> CPortPtr;
typedef CPointer<IPortReplay> CPortReplayPtr;
typedef CPointer<IPortRecorder> CPortRecorderPtr;
typedef CPointer<IPortWriteList, IPortWriteList> CPortWriteListPtr;
typedef CPointer<IChunkPort> CChunkPortPtr;
typedef CPointer<INodeMap, INodeMap> CNodeMapPtr;
typedef CPointer<IDeviceInfo, INodeMap> CDeviceInfoPtr;
typedef CPointer<IUserData, INodeMap> CNodeMapUserDataPtr;
typedef CPointer<IUserData> CNodeUserDataPtr;
typedef CPointer<ISelector> CSelectorPtr;
typedef CPointer<ICommand> CCommandPtr;
class CFloatPtr : public CPointer<IFloat, IBase>
{
public:
CFloatPtr() throw()
: CPointer<IFloat, IBase>( )
{
}
CFloatPtr( IBase *pB )
: CPointer<IFloat, IBase>( pB )
{
}
void operator=( IBase *pB )
{
CPointer<IFloat, IBase>::operator =(pB);
}
IInteger *GetIntAlias()
{
return dynamic_cast<IInteger*>(m_pT->GetNode()->GetCastAlias());
}
IEnumeration *GetEnumAlias()
{
return dynamic_cast<IEnumeration*>(m_pT->GetNode()->GetCastAlias());
}
};
typedef CPointer<IPortConstruct> CPortConstructPtr;
inline GENICAM_NAMESPACE::gcstring GetInterfaceName(IBase *pBase)
{
# ifdef _MSC_VER
# pragma warning (push) // icc -W4 complains: controlling expression is constant
# pragma warning (disable : 279)
# endif
assert(pBase && "don't call this with a NULL pointer");
# ifdef _MSC_VER
# pragma warning (pop)
# endif
CNodePtr ptrNode(pBase);
switch(ptrNode->GetPrincipalInterfaceType())
{
case intfIValue:
return GENICAM_NAMESPACE::gcstring("IValue");
case intfIInteger:
return GENICAM_NAMESPACE::gcstring("IInteger");
case intfIBoolean:
return GENICAM_NAMESPACE::gcstring("IBoolean");
case intfICommand:
return GENICAM_NAMESPACE::gcstring("ICommand");
case intfIFloat:
return GENICAM_NAMESPACE::gcstring("IFloat");
case intfIString:
return GENICAM_NAMESPACE::gcstring("IString");
case intfIRegister:
return GENICAM_NAMESPACE::gcstring("IRegister");
case intfICategory:
return GENICAM_NAMESPACE::gcstring("ICategory");
case intfIEnumeration:
return GENICAM_NAMESPACE::gcstring("IEnumeration");
case intfIEnumEntry:
return GENICAM_NAMESPACE::gcstring("IEnumEntry");
case intfIPort:
return GENICAM_NAMESPACE::gcstring("IPort");
// Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage off
case intfIBase:
default:
return GENICAM_NAMESPACE::gcstring("IBase");
// Do not use this pragma in public header files (warnings in depend projects): #pragma BullseyeCoverage on
}
}
template <class T, class B>
inline bool IsReadable( const CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsReadable( ptr->GetAccessMode() );
}
template <class T, class B>
inline bool IsWritable( const CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsWritable( ptr->GetAccessMode() );
}
template <class T, class B>
inline bool IsImplemented( const CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsImplemented( ptr->GetAccessMode() );
}
template <class T, class B>
inline bool IsAvailable( const CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsAvailable( ptr->GetAccessMode() );
}
}
#endif // ifndef GENAPI_POINTER_H
Updated on 5 July 2022 at 15:30:01