Skip to content

pylon/private/DeviceSpecificGrabResultPtr.h#

Contains a smart pointer that holds a reference to device specific grab result data.

Namespaces#

Name
Pylon
Contains definitions of pylon types.
Pylon::PylonPrivate

Classes#

Name
class Pylon::PylonPrivate::CGrabResultDataConverter
class Pylon::CDeviceSpecificGrabResultPtr
Implementation Detail: Header only implementation class for creating device specific grab result ptrs.

Defines#

Name
PYLON_DEFINE_DEVICE_SPECIFIC_GRAB_RESULT_PTR(ClassName, ResultDataName)

Macros Documentation#

define PYLON_DEFINE_DEVICE_SPECIFIC_GRAB_RESULT_PTR#

#define PYLON_DEFINE_DEVICE_SPECIFIC_GRAB_RESULT_PTR(
    ClassName,
    ResultDataName
)

Source code#

//-----------------------------------------------------------------------------
//  Basler pylon SDK
//  Copyright (c) 2010-2022 Basler AG
//  http://www.baslerweb.com
//  Author:  Andreas Gau
//-----------------------------------------------------------------------------
#ifndef INCLUDED_DEVICESPECIFICGRABRESULTPTR_H_9329951
#define INCLUDED_DEVICESPECIFICGRABRESULTPTR_H_9329951

#include <pylon/GrabResultPtr.h>

#define PYLON_DEFINE_DEVICE_SPECIFIC_GRAB_RESULT_PTR(ClassName, ResultDataName) \
    class ClassName : public CDeviceSpecificGrabResultPtr<ResultDataName> \
    { \
    public: \
 \
            ClassName() \
        { \
        } \
 \
            ClassName( const CGrabResultPtr& rhs ) \
            : CDeviceSpecificGrabResultPtr<ResultDataName>( rhs ) \
        { \
        } \
 \
            ClassName( const ClassName& rhs ) \
            : CDeviceSpecificGrabResultPtr<ResultDataName>( rhs ) \
        { \
        } \
 \
            virtual ~ClassName() \
        { \
        } \
    };


    namespace Pylon
    {

        namespace PylonPrivate
        {
            // Internal use only. This is subject to change without notice.
            class CGrabResultDataConverter
            {
            public:
                // Internal use only. This is subject to change without notice.
                template <typename GrabResultDataT>
                static void Convert( GrabResultDataT*& ptr, CGrabResultPtr& target, const CGrabResultPtr& source )
                {
                    ptr = dynamic_cast<GrabResultDataT*>(source.GetPtr());
                    if (ptr)
                    {
                        target = source;
                    }
                }
            };
        }

        template <typename GrabResultDataT>
        class CDeviceSpecificGrabResultPtr
        {
        public:
            CDeviceSpecificGrabResultPtr();


            CDeviceSpecificGrabResultPtr( const CGrabResultPtr& rhs );


            CDeviceSpecificGrabResultPtr<GrabResultDataT>& operator = ( const CGrabResultPtr& rhs );


            CDeviceSpecificGrabResultPtr( const CDeviceSpecificGrabResultPtr<GrabResultDataT>& rhs );


            CDeviceSpecificGrabResultPtr<GrabResultDataT>& operator = ( const CDeviceSpecificGrabResultPtr<GrabResultDataT>& rhs );


            virtual ~CDeviceSpecificGrabResultPtr();


            GrabResultDataT* operator->() const;


            bool IsValid() const;


            operator bool() const;


            operator CGrabResultPtr() const;


            operator IImage& () const;


            bool IsUnique() const;


            void Release();

        private:
            GrabResultDataT* m_pGrabResultData;
            CGrabResultPtr m_gptr;
        };






        // Implementation ----------------------------------------------------------

        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::CDeviceSpecificGrabResultPtr()
            : m_pGrabResultData( 0 )
        {
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::CDeviceSpecificGrabResultPtr( const CGrabResultPtr& rhs )
        {
            PylonPrivate::CGrabResultDataConverter::Convert<GrabResultDataT>( m_pGrabResultData, m_gptr, rhs );
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>& CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator = ( const CGrabResultPtr& rhs )
        {
            PylonPrivate::CGrabResultDataConverter::Convert<GrabResultDataT>( m_pGrabResultData, m_gptr, rhs );
            return *this;
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::CDeviceSpecificGrabResultPtr( const CDeviceSpecificGrabResultPtr<GrabResultDataT>& rhs )
            : m_pGrabResultData( rhs.m_pGrabResultData )
            , m_gptr( rhs.m_gptr )
        {
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>& CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator = ( const CDeviceSpecificGrabResultPtr<GrabResultDataT>& rhs )
        {
            if (this != &rhs) // self-assignment check
            {
                m_pGrabResultData = rhs.m_pGrabResultData;
                m_gptr = rhs.m_gptr;
            }
            return *this;
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::~CDeviceSpecificGrabResultPtr()
        {
        }


        template <typename GrabResultDataT>
        GrabResultDataT* CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator->() const
        {
            if (!IsValid())
            {
                throw RUNTIME_EXCEPTION( "No grab result data is referenced. Cannot access NULL pointer." );
            }
            return m_pGrabResultData;
        }


        template <typename GrabResultDataT>
        bool CDeviceSpecificGrabResultPtr<GrabResultDataT>::IsValid() const
        {
            return m_pGrabResultData != NULL;
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator bool() const
        {
            return IsValid();
        }


        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator CGrabResultPtr() const
        {
            return m_gptr;
        }

        template <typename GrabResultDataT>
        CDeviceSpecificGrabResultPtr<GrabResultDataT>::operator IImage& () const
        {
            return m_gptr;
        }

        template <typename GrabResultDataT>
        bool CDeviceSpecificGrabResultPtr<GrabResultDataT>::IsUnique() const
        {
            return m_gptr.IsUnique();
        }

        template <typename GrabResultDataT>
        void CDeviceSpecificGrabResultPtr<GrabResultDataT>::Release()
        {
            m_pGrabResultData = NULL;
            m_gptr.Release();
        }
    }

#endif /* INCLUDED_DEVICESPECIFICGRABRESULTPTR_H_9329951 */

Updated on 5 July 2022 at 15:30:01