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
eip::serialization::Writer
Definition: writer.h:41
eip
Definition: connection.h:41
eip::serialization::StreamWriter::writeBytes
void writeBytes(const void *p, size_t n)
Definition: stream_writer.h:72
eip::serialization::StreamWriter::write
void write(T &v)
Definition: stream_writer.h:62
eip::serialization::StreamWriter
Definition: stream_writer.h:47
eip::serialization::StreamWriter::StreamWriter
StreamWriter(shared_ptr< ostream > osp)
Definition: stream_writer.h:55
eip::serialization::StreamWriter::writeBuffer
void writeBuffer(const_buffer b)
Definition: stream_writer.h:81
eip::serialization::StreamWriter::osp_
shared_ptr< ostream > osp_
Definition: stream_writer.h:96
eip::serialization::StreamWriter::getByteCount
size_t getByteCount()
Definition: stream_writer.h:90
writer.h


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:56