]> Creatis software - cpPlugins.git/blob - lib/cpPluginsBase/RawFileReader.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RawFileReader.cxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4
5 #include <fstream>
6 #include <cpPluginsBase/RawFileReader.h>
7 #include <cpPluginsBase/RawData.h>
8
9 // -------------------------------------------------------------------------
10 cpPluginsBase::RawFileReader::
11 RawFileReader( )
12   : Superclass( )
13 {
14 }
15
16 // -------------------------------------------------------------------------
17 cpPluginsBase::RawFileReader::
18 ~RawFileReader( )
19 {
20 }
21
22 // -------------------------------------------------------------------------
23 void cpPluginsBase::RawFileReader::
24  _Configure( )
25 {
26   this->ConfigureInValue< std::string >( "FileName" );
27   this->_ConfigureOutput< cpPluginsBase::RawData >( "Output" );
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPluginsBase::RawFileReader::
32 _GenerateData( )
33 {
34   typedef cpPluginsBase::RawData _TData;
35
36   std::string fname = std::string( this->GetInValue( "FileName" ) );
37   std::ifstream iStr( fname.c_str( ), std::ios::binary | std::ios::ate );
38   if( iStr )
39   {
40     std::streamsize size = iStr.tellg( );
41     iStr.seekg( 0, std::ios::beg );
42     char* buffer = new char[ size ];
43     iStr.read( buffer, size );
44     this->_GetOutput< _TData >( "Output" )->TakeOwnership( buffer, size );
45     iStr.close( );
46   }
47   else
48     cpPluginsErrorMacro(
49       this, << "Could not load file \"" << fname << "\""
50       );
51 }
52
53 // eof - $RCSfile$