00001
00002
00003 #ifndef TO_BYTES_V_HPP_
00004 #define TO_BYTES_V_HPP_
00005
00006 #include <memory>
00007 #include <stdint.h>
00008 #include "vfacade.hpp"
00009
00015 class to_bytes_v {
00016 public:
00017
00018
00020 virtual bool is_bytes_size_static() const = 0;
00021
00023 virtual size_t to_bytes_size() const = 0;
00024
00026 virtual void to_bytes(uint8_t* bytes) const = 0;
00027
00029 virtual bool assign(const uint8_t* bytes, size_t size) = 0;
00030 };
00031
00032 typedef vfacade<to_bytes_v> to_bytes_vf;
00033
00034 template<class NonVirtual, class AdaptorType>
00035 class vobject_hull<NonVirtual, to_bytes_v, AdaptorType> : public to_bytes_v {
00036 private:
00037 typename AdaptorType::template adaptor_type<NonVirtual> obj;
00038
00039 public:
00040 template<typename T>
00041 explicit vobject_hull(T& obj) :
00042 obj(obj) {
00043 }
00044
00045 explicit vobject_hull() :
00046 obj() {
00047 }
00048
00049
00050
00052 virtual bool is_bytes_size_static() const {
00053 return obj->is_bytes_size_static();
00054 }
00055
00057 virtual size_t to_bytes_size() const {
00058 return obj->to_bytes_size();
00059 }
00060
00062 virtual void to_bytes(uint8_t* bytes) const {
00063 obj->to_bytes(bytes);
00064 }
00065
00067 virtual bool assign(const uint8_t* bytes, size_t size) {
00068 return obj->assign(bytes,size);
00069 }
00070 };
00071
00072
00073 #endif