NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
stream-sink.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "stream-sink.hpp"
23 
24 namespace ndn {
25 namespace security {
26 namespace transform {
27 
28 StreamSink::StreamSink(std::ostream& os)
29  : m_os(os)
30 {
31 }
32 
33 size_t
34 StreamSink::doWrite(const uint8_t* buf, size_t size)
35 {
36  m_os.write(reinterpret_cast<const char*>(buf), size);
37 
38  if (m_os.bad())
39  BOOST_THROW_EXCEPTION(Error(getIndex(), "Fail to write data into output stream"));
40 
41  return size;
42 }
43 
44 void
45 StreamSink::doEnd()
46 {
47  m_os.flush();
48 }
49 
50 unique_ptr<Sink>
51 streamSink(std::ostream& os)
52 {
53  return make_unique<StreamSink>(os);
54 }
55 
56 
57 } // namespace transform
58 } // namespace security
59 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
size_t getIndex() const
Get the module index.
StreamSink(std::ostream &os)
Create a stream sink which outputs to os.
Definition: stream-sink.cpp:28
unique_ptr< Sink > streamSink(std::ostream &os)
Definition: stream-sink.cpp:51
Base class of transformation error.