]> Creatis software - cpPlugins.git/blobdiff - lib/cpPluginsBase/RawFileReader.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RawFileReader.cxx
diff --git a/lib/cpPluginsBase/RawFileReader.cxx b/lib/cpPluginsBase/RawFileReader.cxx
new file mode 100644 (file)
index 0000000..386bbc9
--- /dev/null
@@ -0,0 +1,53 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+#include <fstream>
+#include <cpPluginsBase/RawFileReader.h>
+#include <cpPluginsBase/RawData.h>
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RawFileReader::
+RawFileReader( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RawFileReader::
+~RawFileReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RawFileReader::
+ _Configure( )
+{
+  this->ConfigureInValue< std::string >( "FileName" );
+  this->_ConfigureOutput< cpPluginsBase::RawData >( "Output" );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RawFileReader::
+_GenerateData( )
+{
+  typedef cpPluginsBase::RawData _TData;
+
+  std::string fname = std::string( this->GetInValue( "FileName" ) );
+  std::ifstream iStr( fname.c_str( ), std::ios::binary | std::ios::ate );
+  if( iStr )
+  {
+    std::streamsize size = iStr.tellg( );
+    iStr.seekg( 0, std::ios::beg );
+    char* buffer = new char[ size ];
+    iStr.read( buffer, size );
+    this->_GetOutput< _TData >( "Output" )->TakeOwnership( buffer, size );
+    iStr.close( );
+  }
+  else
+    cpPluginsErrorMacro(
+      this, << "Could not load file \"" << fname << "\""
+      );
+}
+
+// eof - $RCSfile$