1 | // to_bytes_v.hpp, created on 30.06.2009 by Sebastian Mies |
---|
2 | |
---|
3 | #ifndef TO_BYTES_V_HPP_ |
---|
4 | #define TO_BYTES_V_HPP_ |
---|
5 | |
---|
6 | #include <memory> |
---|
7 | #include <stdint.h> |
---|
8 | #include "vfacade.hpp" |
---|
9 | |
---|
10 | /** |
---|
11 | * TODO: Doc |
---|
12 | * |
---|
13 | * @author Sebastian Mies <mies@tm.uka.de> |
---|
14 | */ |
---|
15 | class to_bytes_v { |
---|
16 | public: |
---|
17 | //--- to_bytes_v ---------------------------------------------------------- |
---|
18 | |
---|
19 | /// returns true, if this address has a fixed size in bytes |
---|
20 | virtual bool is_bytes_size_static() const = 0; |
---|
21 | |
---|
22 | /// returns the number of bytes used for serialization of this address |
---|
23 | virtual size_t to_bytes_size() const = 0; |
---|
24 | |
---|
25 | /// converts this address to a binary representation |
---|
26 | virtual void to_bytes(uint8_t* bytes) const = 0; |
---|
27 | |
---|
28 | /// Assigns an address using a bunch of bytes |
---|
29 | virtual bool assign(const uint8_t* bytes, size_t size) = 0; |
---|
30 | }; |
---|
31 | |
---|
32 | typedef vfacade<to_bytes_v> to_bytes_vf; |
---|
33 | |
---|
34 | template<class NonVirtual, class AdaptorType> |
---|
35 | class vobject_hull<NonVirtual, to_bytes_v, AdaptorType> : public to_bytes_v { |
---|
36 | private: |
---|
37 | typename AdaptorType::template adaptor_type<NonVirtual> obj; |
---|
38 | |
---|
39 | public: |
---|
40 | template<typename T> |
---|
41 | explicit vobject_hull(T& obj) : |
---|
42 | obj(obj) { |
---|
43 | } |
---|
44 | |
---|
45 | explicit vobject_hull() : |
---|
46 | obj() { |
---|
47 | } |
---|
48 | |
---|
49 | //--- to_bytes_v ---------------------------------------------------------- |
---|
50 | |
---|
51 | /// returns true, if this address has a fixed size in bytes |
---|
52 | virtual bool is_bytes_size_static() const { |
---|
53 | return obj->is_bytes_size_static(); |
---|
54 | } |
---|
55 | |
---|
56 | /// returns the number of bytes used for serialization of this address |
---|
57 | virtual size_t to_bytes_size() const { |
---|
58 | return obj->to_bytes_size(); |
---|
59 | } |
---|
60 | |
---|
61 | /// converts this address to a binary representation |
---|
62 | virtual void to_bytes(uint8_t* bytes) const { |
---|
63 | obj->to_bytes(bytes); |
---|
64 | } |
---|
65 | |
---|
66 | /// Assigns an address using a bunch of bytes |
---|
67 | virtual bool assign(const uint8_t* bytes, size_t size) { |
---|
68 | return obj->assign(bytes,size); |
---|
69 | } |
---|
70 | }; |
---|
71 | |
---|
72 | |
---|
73 | #endif /* TO_BYTES_V_HPP_ */ |
---|