fw4spl
Buffer.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 <boost/iostreams/device/array.hpp>
8 #include <boost/iostreams/stream.hpp>
9 
10 #include <fwCore/macros.hpp>
11 #include <fwCore/spyLog.hpp>
12 
13 #include "fwMemory/stream/in/Buffer.hpp"
14 
15 namespace fwMemory
16 {
17 namespace stream
18 {
19 namespace in
20 {
21 
22 struct HoldCounterStream : ::boost::iostreams::stream< ::boost::iostreams::array_source >
23 {
24  HoldCounterStream(char *buf, size_t size, const Buffer::LockType &lock) :
25  ::boost::iostreams::stream< ::boost::iostreams::array_source >(buf, size),
26  m_counter(lock)
27  {
28  }
29 
30  Buffer::LockType m_counter;
31 };
32 
33 Buffer::LockType noFactory()
34 {
35  return Buffer::LockType();
36 }
37 
38 Buffer::Buffer(void* buf, size_t size) :
39  m_buf(buf), m_size(size), m_counterFactory(&noFactory)
40 {
41  OSLM_ASSERT("Buffer is null.", m_buf || size == 0);
42 }
43 
44 Buffer::Buffer(void* buf, size_t size, CounterFactoryType counterFactory) :
45  m_buf(buf), m_size(size), m_counterFactory(counterFactory)
46 {
47  OSLM_ASSERT("Buffer is null.", m_buf || size == 0);
48 }
49 
50 SPTR(std::istream) Buffer::get()
51 {
52  namespace io = boost::iostreams;
53 
54  typedef HoldCounterStream ArrayStreamType;
55  SPTR( ArrayStreamType ) arrayInStream
56  = std::make_shared< ArrayStreamType > ( static_cast<char *>(m_buf), m_size, m_counterFactory() );
57 
58  return arrayInStream;
59 }
60 
61 } // namespace in
62 } // namespace stream
63 } // namespace fwMemory
64 
#define SPTR(_cls_)
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20
This file defines fwCore base macros.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...