fw4spl
ArrayWriter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwDataIO/writer/ArrayWriter.hpp"
8 
9 #include "fwDataIO/writer/registry/macros.hpp"
10 
11 #include <fwDataTools/helper/ArrayGetter.hpp>
12 
13 #include <boost/filesystem/path.hpp>
14 
15 #include <fstream>
16 #include <iostream>
17 
18 fwDataIOWriterRegisterMacro( ::fwDataIO::writer::ArrayWriter);
19 
20 namespace fwDataIO
21 {
22 namespace writer
23 {
24 
25 //------------------------------------------------------------------------------
26 
28  ::fwData::location::enableSingleFile< ::fwDataIO::writer::IObjectWriter >(this)
29 {
30 }
31 
32 //------------------------------------------------------------------------------
33 
35 {
36 }
37 
38 //------------------------------------------------------------------------------
39 
41 {
42  ::boost::filesystem::path file = getFile();
43 
44  ::fwData::Array::csptr array = this->getConcreteObject();
45  size_t arraySizeInBytes = array->getSizeInBytes();
46  ::fwDataTools::helper::ArrayGetter arrayHelper(array);
47  const char* buff = arrayHelper.begin();
48 
49  std::ofstream fs(file.string().c_str(), std::ios::binary|std::ios::trunc);
50 
51  FW_RAISE_IF("Unable to open " << file, !fs.good());
52 
53  fs.write(buff, arraySizeInBytes);
54  fs.close();
55 
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  return ".raw";
63 }
64 
65 //------------------------------------------------------------------------------
66 
67 } // namespace writer
68 
69 } // namespace fwDataIO
Array Writer. Write file format .raw.
Definition: ArrayWriter.hpp:27
This namespace fwDataIO contains reader and writer for several framework&#39;s data.
virtual FWDATAIO_API void write() override
Read the file with zlib API.
Definition: ArrayWriter.cpp:40
virtual std::shared_ptr< const DataType > getConcreteObject() const
m_object getter.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWDATATOOLS_API const char * begin() const
Returns the begining/end of the buffer interpreted as a char buffer.
Definition: ArrayGetter.cpp:37
Helper to manage array buffer. Lock the buffer before to modify it.
Definition: ArrayGetter.hpp:28
Base class for all object writers.
virtual FWDATAIO_API ~ArrayWriter()
Destructor. Do nothing.
Definition: ArrayWriter.cpp:34
FWDATAIO_API ArrayWriter(::fwDataIO::writer::IObjectWriter::Key key)
Constructor. Do nothing.
Definition: ArrayWriter.cpp:27
virtual FWDATAIO_API std::string extension() override
Defines extension supported by this writer ".raw".
Definition: ArrayWriter.cpp:60
Contains the representation of the data objects used in the framework.