stream_writer.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H
27 #define ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H
28 
29 #include <iostream>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/asio.hpp>
33 
34 using boost::shared_ptr;
35 using boost::asio::const_buffer;
36 using boost::asio::buffer_cast;
37 using boost::asio::buffer_size;
38 using std::ostream;
39 
40 namespace eip {
41 namespace serialization {
42 
47 class StreamWriter : public Writer
48 {
49 public:
50 
55  StreamWriter(shared_ptr<ostream> osp) : osp_(osp) { }
56 
61  template <typename T>
62  void write(T& v)
63  {
64  osp_->write((char*)&v, sizeof(v));
65  }
66 
72  void writeBytes(const void* p, size_t n)
73  {
74  osp_->write((char*)p, n);
75  }
76 
81  void writeBuffer(const_buffer b)
82  {
83  osp_->write(buffer_cast<const char*>(b), buffer_size(b));
84  }
85 
90  size_t getByteCount()
91  {
92  return osp_->tellp();
93  }
94 
95 private:
96  shared_ptr<ostream> osp_;
97 };
98 
99 } // namespace serialization
100 } // namespace eip
101 #endif // ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H
void writeBuffer(const_buffer b)
Definition: stream_writer.h:81
Definition: connection.h:41
void writeBytes(const void *p, size_t n)
Definition: stream_writer.h:72
StreamWriter(shared_ptr< ostream > osp)
Definition: stream_writer.h:55
shared_ptr< ostream > osp_
Definition: stream_writer.h:96


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Mon Jun 10 2019 14:00:16