-
Notifications
You must be signed in to change notification settings - Fork 0
/
rw_structure.h
64 lines (52 loc) · 2.2 KB
/
rw_structure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// (C) Copyright 2009-2011 Vit Kasal
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include "si_constants.h"
#include "tuple_type.h"
#include "sequence_position.h"
#include "protocol_encoders.h"
#include "command_interface.h"
#include <boost/shared_array.hpp>
namespace si
{
template<boost::uint8_t command_tt
, typename parameters_tt = boost::deque<>
> struct rw_structure
: public boostext::tuple_type<typename create_parameter_sequence<parameters_tt>::type>::type
{
typedef parameters_tt structure_template_type;
typedef typename create_parameter_sequence<parameters_tt>::type parameters_type;
typedef typename boostext::tuple_type<typename create_parameter_sequence<parameters_tt>::type>::type parameters_tuple_type;
typedef boost::shared_ptr<rw_structure> pointer;
typedef rw_structure this_type;
template<typename parameter_tt>struct element
{
typedef boost::mpl::integral_c<unsigned, boostext::sequence_position<typename parameter_tt::parameter_type, command_parameters_type>::value> type;
};
template<typename parameter_tt> typename parameter_tt::type & get()
{
return *(typename parameter_tt::type*)¶meters_tuple_type::get<boostext::sequence_position<typename parameter_tt::parameter_type, command_parameters_type>::value>();
}
std::size_t get_size(protocols::id<>::value_type protocol = protocols::id<>::value)
{
return parameters_size_counter<parameters_tt, this_type>::get_size(this);
}
virtual bool accept_data(std::size_t size, data_type data)
{
boost::add_pointer<data_type::element_type>::type it = data.get();
return raw_data_reader<this_type>::read_data(this, size, it);
}
virtual bool can_accept_data(std::size_t size, data_type data)
{
boost::add_pointer<data_type::element_type>::type it = data.get();
return raw_data_reader<this_type>::can_read_data(this, size, it);
}
static inline bool can_accept_data_static(std::size_t size, data_type data)
{
boost::add_pointer<data_type::element_type>::type it = data.get();
return raw_data_reader<this_type>::can_read_data_static(size, it);
}
};
};//namespace si