source: source/ariba/utility/addressing/facades/to_bytes_v.hpp@ 6867

Last change on this file since 6867 was 6786, checked in by mies, 15 years ago

Changed Data to Message conversion constructor in Message to explicit
Fixed some general bugs in Data: operator<<
Fixed bug in DHTMessage: allow unspecified key/values
Added local DHT message delivery
Adapted sources to work with gcc 4.4.1

File size: 1.8 KB
Line 
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 */
15class to_bytes_v {
16public:
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
32typedef vfacade<to_bytes_v> to_bytes_vf;
33
34template<class NonVirtual, class AdaptorType>
35class vobject_hull<NonVirtual, to_bytes_v, AdaptorType> : public to_bytes_v {
36private:
37 typename AdaptorType::template adaptor_type<NonVirtual> obj;
38
39public:
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_ */
Note: See TracBrowser for help on using the repository browser.