StructPort.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2009 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 //-----------------------------------------------------------------------------
00025 
00031 #ifndef __STRUCTPORT_H
00032 #define __STRUCTPORT_H
00033 
00034 #include <cstring>
00035 #include <string.h>
00036 #include <GenApi/PortImpl.h>
00037 
00038 namespace GENAPI_NAMESPACE
00039 {
00041     template <class CDataStruct>
00042     class CTestPortStruct : public CDataStruct, public GENAPI_NAMESPACE::CPortImpl
00043     {
00044     public:
00045         CTestPortStruct(int64_t BaseAddress = 0)
00046             : m_BaseAddress(BaseAddress)
00047         {
00048             MemSet(0);
00049             ResetStatistics();
00050         }
00051 
00052         //-------------------------------------------------------------
00053         // IBase implementation
00054         //-------------------------------------------------------------
00055 
00057         virtual GENAPI_NAMESPACE::EAccessMode GetAccessMode() const
00058         {
00059             return RW;
00060         }
00061 
00063         virtual GENAPI_NAMESPACE::EInterfaceType GetPrincipalInterfaceType() const
00064         {
00065             return intfIPort;
00066         }
00067 
00068         //---------------------------------------------------------------
00069         // IPort implementation
00070         //---------------------------------------------------------------
00071 
00073         virtual void Read(void *pBuffer, int64_t Address, int64_t Length)
00074         {
00075             int64_t InternalAddress = Address - m_BaseAddress;
00076 
00077             CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
00078             if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
00079                 throw RUNTIME_EXCEPTION("CTestPortStruct::Read - Invalid address and/or length");
00080             memcpy( pBuffer, (uint8_t*)pDataStruct + InternalAddress, (size_t)Length );
00081             m_NumReads++;
00082         }
00083 
00085         virtual void Write(const void *pBuffer, int64_t Address, int64_t Length)
00086         {
00087             int64_t InternalAddress = Address - m_BaseAddress;
00088 
00089             CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
00090             if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
00091                 throw RUNTIME_EXCEPTION("CTestPortStruct::Write - Invalid address and/or length");
00092             memcpy( (uint8_t*)pDataStruct + InternalAddress, pBuffer, (size_t)Length );
00093             m_NumWrites++;
00094         }
00095 
00096         //-------------------------------------------------------------
00097         // Utility functions
00098         //-------------------------------------------------------------
00099 
00100         void MemSet( const char FillValue )
00101         {
00102              memset( static_cast<CDataStruct*>(this), FillValue, sizeof(CDataStruct) );
00103         }
00104 
00105         //-------------------------------------------------------------
00106         // Statistics functions
00107         //-------------------------------------------------------------
00108 
00110         void ResetStatistics()
00111         {
00112             m_NumReads = 0;
00113             m_NumWrites = 0;
00114         }
00115 
00117         int64_t GetNumReads()
00118         {
00119             return m_NumReads;
00120         }
00121 
00123         int64_t GetNumWrites()
00124         {
00125             return m_NumWrites;
00126         }
00127 
00128     protected:
00130         int64_t m_NumReads;
00131 
00133         int64_t m_NumWrites;
00134 
00136         int64_t m_BaseAddress;
00137     };
00138 }
00139 
00140 #endif // __STRUCTPORT_H


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