File Pointer.h¶
File List > include > SpinGenApi > Pointer.h
Go to the documentation of this file
//=============================================================================
// Copyright (c) 2026 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
#ifndef SPINNAKER_GENAPI_POINTER_H
#define SPINNAKER_GENAPI_POINTER_H
#include "Base.h"
#include "INode.h"
#include "IValue.h"
#include "ICategory.h"
#include "IInteger.h"
#include "IFloat.h"
#include "IRegister.h"
#include "IEnumeration.h"
#include "IEnumEntry.h"
#include "IBoolean.h"
#include "IPort.h"
#include "IPortRecorder.h"
#include "IPortConstruct.h"
#include "IChunkPort.h"
#include "IString.h"
#include "INodeMap.h"
#include "INodeMapDyn.h"
#include "IDestroy.h"
#include "IDeviceInfo.h"
#include "ISelector.h"
#include "ICommand.h"
#include "GCString.h"
#include "Exception.h"
#include <stdio.h>
// Windows-specific.
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
// Linux specific.
#else
// End of OS-specific code.
#endif
namespace Spinnaker
{
namespace GenApi
{
//*************************************************************
// CPointer class
//*************************************************************
template <class T, class B = IBase> class CPointer
{
public:
CPointer(void) : 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 (nullptr == m_pT)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException NULL pointer dereferenced",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return m_pT;
}
T& operator*(void)const
{
if (nullptr == m_pT)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException NULL pointer dereferenced",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return *m_pT;
}
T& operator()(void) const
{
if (nullptr == m_pT)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException NULL pointer dereferenced",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return *m_pT;
}
T* operator->(void)const
{
if (nullptr == m_pT)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException NULL pointer dereferenced",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return m_pT;
}
bool IsValid() const throw()
{
return m_pT != nullptr;
}
operator bool(void) const throw()
{
return m_pT != nullptr;
}
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 Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException argument must be NULL",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return NULL == m_pT;
}
bool operator!=(const CPointer<T, B>& rT) const
{
return m_pT != rT.m_pT;
}
bool operator!=(T* pT) const
{
return m_pT != pT;
}
bool operator!=(const long int nMustBeNull) const
{
if (0 != nMustBeNull)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException argument must be NULL",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return NULL != m_pT;
}
bool operator!=(const int nMustBeNull) const
{
if (0 != nMustBeNull)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException argument must be NULL",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return NULL != m_pT;
}
bool operator!=(const std::nullptr_t nullPtr) const
{
if (nullPtr != nullptr)
{
throw Spinnaker::Exception(
__LINE__,
__FILE__,
__FUNCTION__,
"LogicalErrorException argument must be nullptr",
SPINNAKER_ERR_GENICAM_LOGICAL);
}
return m_pT != nullptr;
}
protected:
T* m_pT;
};
//*************************************************************
// Smartpointer for all interface
//*************************************************************
typedef CPointer<IBase> CBasePtr;
typedef CPointer<INode, IBase> 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<INodeMapDyn, INodeMap> CNodeMapDynPtr;
typedef CPointer<IDeviceInfo, INodeMap> CDeviceInfoPtr;
typedef CPointer<ISelector> CSelectorPtr;
typedef CPointer<ICommand> CCommandPtr;
typedef CPointer<IPortConstruct> CPortConstructPtr;
#ifdef SWIG
%template(_SWIG_CFltPtr)CPointer<IFloat, IBase>; // definition for Python wrapper generation
#endif
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());
}
};
template <class T, class B> inline bool IsReadable(const Spinnaker::GenApi::CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsReadable(ptr->GetAccessMode());
}
template <class T, class B> inline bool IsWritable(const Spinnaker::GenApi::CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsWritable(ptr->GetAccessMode());
}
template <class T, class B> inline bool IsImplemented(const Spinnaker::GenApi::CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsImplemented(ptr->GetAccessMode());
}
template <class T, class B> inline bool IsAvailable(const Spinnaker::GenApi::CPointer<T, B>& ptr)
{
return ptr.IsValid() && IsAvailable(ptr->GetAccessMode());
}
inline GenICam::gcstring GetInterfaceName(IBase* pBase)
{
#ifdef _WIN32
#pragma warning(push) // icc -W4 complains: controlling expression is constant
#pragma warning(disable : 279)
assert(pBase && "don't call this with a NULL pointer");
#pragma warning(pop)
#else
assert(pBase && "don't call this with a NULL pointer");
#endif
CNodePtr ptrNode(pBase);
switch (ptrNode->GetPrincipalInterfaceType())
{
case intfIValue:
return GenICam::gcstring("IValue");
case intfIInteger:
return GenICam::gcstring("IInteger");
case intfIBoolean:
return GenICam::gcstring("IBoolean");
case intfICommand:
return GenICam::gcstring("ICommand");
case intfIFloat:
return GenICam::gcstring("IFloat");
case intfIString:
return GenICam::gcstring("IString");
case intfIRegister:
return GenICam::gcstring("IRegister");
case intfICategory:
return GenICam::gcstring("ICategory");
case intfIEnumeration:
return GenICam::gcstring("IEnumeration");
case intfIEnumEntry:
return GenICam::gcstring("IEnumEntry");
case intfIPort:
return GenICam::gcstring("IPort");
case intfIBase:
default:
return GenICam::gcstring("IBase");
}
}
} // namespace GenApi
} // namespace Spinnaker
#endif // ifndef SPINNAKER_GENAPI_POINTER_H