NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
buffer-stream.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24
#ifndef NDN_ENCODING_BUFFER_STREAM_HPP
25
#define NDN_ENCODING_BUFFER_STREAM_HPP
26
27
#include "
buffer.hpp
"
28
29
#include <boost/iostreams/detail/ios.hpp>
30
#include <boost/iostreams/categories.hpp>
31
#include <boost/iostreams/stream.hpp>
32
33
namespace
ndn
{
34
36
namespace
iostreams
37
{
38
39
class
buffer_append_device
40
{
41
public
:
42
typedef
char
char_type;
43
typedef
boost::iostreams::sink_tag category;
44
45
buffer_append_device(Buffer& container)
46
: m_container(container)
47
{
48
}
49
50
std::streamsize
51
write(
const
char_type* s, std::streamsize n)
52
{
53
std::copy(s, s+n, std::back_inserter(m_container));
54
return
n;
55
}
56
57
protected
:
58
Buffer& m_container;
59
};
60
61
}
// iostreams
63
79
class
OBufferStream
:
public
boost::iostreams::stream<iostreams::buffer_append_device>
80
{
81
public
:
85
OBufferStream
()
86
: m_buffer(make_shared<
Buffer
>())
87
, m_device(*m_buffer)
88
{
89
open(m_device);
90
}
91
95
shared_ptr<Buffer>
96
buf
()
97
{
98
flush();
99
return
m_buffer;
100
}
101
102
private
:
103
BufferPtr
m_buffer;
104
iostreams::buffer_append_device m_device;
105
};
106
107
}
// ndn
108
109
#endif // NDN_ENCODING_BUFFER_STREAM_HPP
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::BufferPtr
shared_ptr< Buffer > BufferPtr
Definition:
buffer.hpp:35
ndn::OBufferStream::buf
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Definition:
buffer-stream.hpp:96
ndn::OBufferStream::OBufferStream
OBufferStream()
Default constructor.
Definition:
buffer-stream.hpp:85
buffer.hpp
ndn::OBufferStream
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
Definition:
buffer-stream.hpp:79
ndn::Buffer
Class representing a general-use automatically managed/resized buffer.
Definition:
buffer.hpp:44
ndnSIM
ndn-cxx
src
encoding
buffer-stream.hpp
Generated on Sat Nov 12 2016 16:02:52 for ndnSIM by
1.8.12