]> Creatis software - cpPlugins.git/blob - lib/cpPluginsBase/RawData.h
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RawData.h
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __cpPluginsBase__RawData__h__
5 #define __cpPluginsBase__RawData__h__
6
7 #include <cpPluginsBase_Export.h>
8 #include <cpPlugins/DataObject.h>
9
10 namespace cpPluginsBase
11 {
12   /**
13    */
14   class CPPLUGINSBASE_EXPORT RawData
15     : public cpPlugins::DataObject
16   {
17     cpPluginsTypeMacro( RawData, cpPlugins::DataObject );
18     cpPluginsNewMacro( );
19
20   public:
21     typedef char TData;
22     typedef std::shared_ptr< TData > TDataPointer;
23
24   public:
25     template< class _TType >
26     void TakeOwnership( _TType* buffer, const std::size_t& size );
27
28     template< class _TType = char >
29     _TType* GetBuffer( );
30
31     template< class _TType = char >
32     const _TType* GetBuffer( ) const;
33
34     const std::size_t& GetSize( ) const;
35
36     virtual void Print( std::ostream& o ) const override;
37
38   protected:
39     RawData( );
40     virtual ~RawData( );
41
42   protected:
43     TDataPointer m_Data;
44     std::size_t  m_Size;
45   };
46
47 } // ecapseman
48
49 // -------------------------------------------------------------------------
50 template< class _TType >
51 void cpPluginsBase::RawData::
52 TakeOwnership( _TType* buffer, const std::size_t& size )
53 {
54   this->m_Data = TDataPointer( reinterpret_cast< TData* >( buffer ) );
55   this->m_Size = size;
56   this->_SynchTime( );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class _TType >
61 _TType* cpPluginsBase::RawData::
62 GetBuffer( )
63 {
64   return( reinterpret_cast< _TType* >( this->m_Data.get( ) ) );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TType >
69 const _TType* cpPluginsBase::RawData::
70 GetBuffer( ) const
71 {
72   return( reinterpret_cast< const _TType* >( this->m_Data.get( ) ) );
73 }
74
75 #endif // __cpPluginsBase__RawData__h__
76
77 // eof - $RCSfile$