]> Creatis software - cpPlugins.git/blobdiff - lib/cpPluginsBase/RawFileWriter.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RawFileWriter.cxx
diff --git a/lib/cpPluginsBase/RawFileWriter.cxx b/lib/cpPluginsBase/RawFileWriter.cxx
new file mode 100644 (file)
index 0000000..bd76175
--- /dev/null
@@ -0,0 +1,53 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+#include <fstream>
+#include <cpPluginsBase/RawFileWriter.h>
+#include <cpPluginsBase/RawData.h>
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RawFileWriter::
+RawFileWriter( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RawFileWriter::
+~RawFileWriter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RawFileWriter::
+_Configure( )
+{
+  this->ConfigureInValue< std::string >( "FileName" );
+  this->_ConfigureInput< cpPluginsBase::RawData >( "Input", true, false );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RawFileWriter::
+_GenerateData( )
+{
+  typedef cpPluginsBase::RawData _TData;
+
+  const _TData* input = this->_GetInput< _TData >( "Input" );
+  const char* buffer = input->GetBuffer( );
+  std::size_t size = input->GetSize( );
+  std::string fname = std::string( this->GetInValue( "FileName" ) );
+
+  std::ofstream oStr( fname.c_str( ), std::ios::binary | std::ios::out );
+  if( oStr )
+  {
+    oStr.write( buffer, size );
+    oStr.close( );
+  }
+  else
+    cpPluginsErrorMacro(
+      this, << "Could not save file \"" << fname << "\""
+      );
+}
+
+// eof - $RCSfile$