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