stream_writer.h
Go to the documentation of this file.
00001 
00026 #ifndef ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H
00027 #define ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H
00028 
00029 #include <iostream>
00030 #include <boost/shared_ptr.hpp>
00031 #include <boost/asio.hpp>
00032 #include "odva_ethernetip/serialization/writer.h"
00033 
00034 using boost::shared_ptr;
00035 using boost::asio::const_buffer;
00036 using boost::asio::buffer_cast;
00037 using boost::asio::buffer_size;
00038 using std::ostream;
00039 
00040 namespace eip {
00041 namespace serialization {
00042 
00047 class StreamWriter : public Writer
00048 {
00049 public:
00050 
00055   StreamWriter(shared_ptr<ostream> osp) : osp_(osp) { }
00056 
00061   template <typename T>
00062   void write(T& v)
00063   {
00064     osp_->write((char*)&v, sizeof(v));
00065   }
00066 
00072   void writeBytes(const void* p, size_t n)
00073   {
00074     osp_->write((char*)p, n);
00075   }
00076 
00081   void writeBuffer(const_buffer b)
00082   {
00083     osp_->write(buffer_cast<const char*>(b), buffer_size(b));
00084   }
00085 
00090   size_t getByteCount()
00091   {
00092     return osp_->tellp();
00093   }
00094 
00095 private:
00096   shared_ptr<ostream> osp_;
00097 };
00098 
00099 } // namespace serialization
00100 } // namespace eip
00101 #endif  // ODVA_ETHERNETIP_SERIALIZATION_STREAM_WRITER_H


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Sat Jun 8 2019 20:21:23