fw4spl
fwMedData/src/fwMedData/AttachmentSeries.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 "fwMedData/AttachmentSeries.hpp"
8 
9 #include <fwData/Exception.hpp>
10 #include <fwData/registry/macros.hpp>
11 
12 #include <fwMemory/stream/in/Raw.hpp>
13 
14 #include <boost/filesystem/operations.hpp>
15 
16 fwDataRegisterMacro( ::fwMedData::AttachmentSeries );
17 
18 namespace fwMedData
19 {
20 
22  m_buffer(::fwMemory::BufferObject::New()),
23  m_attachmentAvailability(NONE)
24 {
25 }
26 
27 //------------------------------------------------------------------------------
28 
30 {
31 }
32 
33 //------------------------------------------------------------------------------
34 
35 void AttachmentSeries::cachedDeepCopy(const ::fwData::Object::csptr& _source, DeepCopyCacheType& cache)
36 {
37  AttachmentSeries::csptr other = AttachmentSeries::dynamicConstCast(_source);
38  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
39  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
40  + " to " + this->getClassname()), !bool(other) );
41 
42  this->::fwMedData::Series::cachedDeepCopy(_source, cache);
43 
44  if( !other->m_buffer->isEmpty() )
45  {
47  m_buffer->allocate(other->m_buffer->getSize());
48  char* buffDest = static_cast< char* >( lockerDest.getBuffer() );
49 
50  ::fwMemory::BufferObject::Lock lockerSource(other->m_buffer);
51  char* buffSrc = static_cast< char* >( lockerSource.getBuffer() );
52 
53  std::copy(buffSrc, buffSrc+other->m_buffer->getSize(), buffDest );
54  }
55  m_attachmentAvailability = other->m_attachmentAvailability;
56  m_attachmentPath = other->m_attachmentPath;
57  m_mediaType = other->m_mediaType;
58 }
59 
60 //------------------------------------------------------------------------------
61 
62 const ::boost::filesystem::path& AttachmentSeries::getAttachmentPath() const
63 {
64  return m_attachmentPath;
65 }
66 
67 //------------------------------------------------------------------------------
68 
69 void AttachmentSeries::setAttachmentPath(const ::boost::filesystem::path& path)
70 {
71  m_attachmentPath = path;
72  size_t buffSize = ::boost::filesystem::file_size(path);
73  m_buffer->setIStreamFactory( std::make_shared< ::fwMemory::stream::in::Raw >(path),
74  buffSize, path, ::fwMemory::RAW);
76 }
77 
78 //------------------------------------------------------------------------------
79 
80 ::fwMemory::BufferObject::sptr AttachmentSeries::getBufferObject () const
81 {
82  return m_buffer;
83 }
84 
85 //------------------------------------------------------------------------------
86 
88 {
90 }
91 
92 //------------------------------------------------------------------------------
93 
94 std::string AttachmentSeries::getMediaType() const
95 {
96  return m_mediaType;
97 }
98 
99 //------------------------------------------------------------------------------
100 
101 void AttachmentSeries::setMediaType(const std::string& mediaType)
102 {
103  m_mediaType = mediaType;
104 }
105 
106 //------------------------------------------------------------------------------
107 
108 } // namespace fwMedData
109 
FWMEDDATA_API AttachmentSeries(::fwData::Object::Key key)
Constructor.
virtual const std::string & getClassname() const override
return full object&#39;s classname with its namespace, i.e. fwCore::BaseObject
FWMEDDATA_API::fwMemory::BufferObject::sptr getBufferObject() const
Returns BufferObject of the current attachment file.
FWMEDDATA_APIconst::boost::filesystem::path & getAttachmentPath() const
Local path of attachment file.
Namespace containing medical data.
FWMEDDATA_API void cachedDeepCopy(const ::fwData::Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20
FWMEDDATA_API AttachmentAvailability getAttachmentAvailability() const
Returns the state of the attached file.
AttachmentAvailability m_attachmentAvailability
Attachment availability.
std::string m_mediaType
Media type of the attached file.
::boost::filesystem::path m_attachmentPath
Local path of attachment file.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Implements data exception class.
FWMEDDATA_API void cachedDeepCopy(const ::fwData::Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
::fwMemory::BufferObject::sptr m_buffer
BufferObject of the current attachment file.
base class for BufferObject Lock
virtual FWMEDDATA_API ~AttachmentSeries()
Destructor.
LockBase< T >::BufferType getBuffer() const
Returns BufferObject&#39;s buffer pointer.
FWMEDDATA_API void setAttachmentPath(const ::boost::filesystem::path &path)
Local path of attachment file.
FWMEDDATA_API void setMediaType(const std::string &mediaType)
Specifies the media type of the attached file (see IANA list of official media types) ...
FWMEDDATA_API std::string getMediaType() const
Returns the media type of the attached file.