element.hpp (82a51ce2400eee6597afbe757d966ac7091da58b) | element.hpp (377e76abd1f1deb498e8495c61fb160675584eec) |
---|---|
1// Copyright (c) Benjamin Kietzman (github.com/bkietz) 2// 3// Distributed under the Boost Software License, Version 1.0. (See accompanying 4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6#ifndef DBUS_ELEMENT_HPP 7#define DBUS_ELEMENT_HPP 8 --- 20 unchanged lines hidden (view full) --- 29 30typedef boost::int64_t int64; 31typedef boost::uint64_t uint64; 32// double 33// unix_fd 34 35typedef std::string string; 36 | 1// Copyright (c) Benjamin Kietzman (github.com/bkietz) 2// 3// Distributed under the Boost Software License, Version 1.0. (See accompanying 4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6#ifndef DBUS_ELEMENT_HPP 7#define DBUS_ELEMENT_HPP 8 --- 20 unchanged lines hidden (view full) --- 29 30typedef boost::int64_t int64; 31typedef boost::uint64_t uint64; 32// double 33// unix_fd 34 35typedef std::string string; 36 |
37typedef boost::variant<std::string, bool, byte, int16, uint16, int32, uint32, int64, 38 uint64, double> | 37typedef boost::variant<std::string, bool, byte, int16, uint16, int32, uint32, 38 int64, uint64, double> |
39 dbus_variant; 40 41struct object_path { 42 string value; 43}; 44struct signature { 45 string value; 46}; 47 | 39 dbus_variant; 40 41struct object_path { 42 string value; 43}; 44struct signature { 45 string value; 46}; 47 |
48/// Traits template for message elements | 48template <std::size_t... Is> 49struct seq {}; 50 51template <std::size_t N, std::size_t... Is> 52struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; 53 54template <std::size_t... Is> 55struct gen_seq<0, Is...> : seq<Is...> {}; 56 57template <std::size_t N1, std::size_t... I1, std::size_t N2, std::size_t... I2> 58constexpr std::array<char, N1 + N2 - 1> concat_helper( 59 const std::array<char, N1>& a1, const std::array<char, N2>& a2, seq<I1...>, 60 seq<I2...>) { 61 return {{a1[I1]..., a2[I2]...}}; 62} 63 64template <std::size_t N1, std::size_t N2> 65// Initializer for the recursion 66constexpr std::array<char, N1 + N2 - 1> concat(const std::array<char, N1>& a1, 67 const std::array<char, N2>& a2) { 68 // note, this function expects both character arrays to be null 69 // terminated. The -1 below drops the null terminator on the first string 70 return concat_helper(a1, a2, gen_seq<N1 - 1>{}, gen_seq<N2>{}); 71} 72 |
49/** 50 * D-Bus Message elements are identified by unique integer type codes. 51 */ | 73/** 74 * D-Bus Message elements are identified by unique integer type codes. 75 */ |
76 |
|
52template <typename InvalidType> | 77template <typename InvalidType> |
78struct element_signature; 79 80template <> 81struct element_signature<bool> { 82 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_BOOLEAN, 0}}; 83}; 84 85template <> 86struct element_signature<byte> { 87 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_BYTE, 0}}; 88}; 89 90template <> 91struct element_signature<int16> { 92 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_INT16, 0}}; 93}; 94 95template <> 96struct element_signature<uint16> { 97 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_UINT16, 0}}; 98}; 99 100template <> 101struct element_signature<int32> { 102 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_INT32, 0}}; 103}; 104 105template <> 106struct element_signature<uint32> { 107 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_UINT32, 0}}; 108}; 109 110template <> 111struct element_signature<int64> { 112 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_INT64, 0}}; 113}; 114 115template <> 116struct element_signature<uint64> { 117 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_UINT64, 0}}; 118}; 119 120template <> 121struct element_signature<double> { 122 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_DOUBLE, 0}}; 123}; 124 125template <> 126struct element_signature<string> { 127 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_STRING, 0}}; 128}; 129 130template <> 131struct element_signature<dbus_variant> { 132 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_VARIANT, 0}}; 133}; 134 135template <> 136struct element_signature<object_path> { 137 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_OBJECT_PATH, 0}}; 138}; 139 140template <> 141struct element_signature<signature> { 142 static auto constexpr code = std::array<char, 2>{{DBUS_TYPE_SIGNATURE, 0}}; 143}; 144 145template <typename Key, typename Value> 146struct element_signature<std::pair<Key, Value>> { 147 static auto constexpr code = 148 concat(std::array<char, 2>{{'{', 0}}, 149 concat(element_signature<Key>::code, 150 concat(element_signature<Value>::code, 151 std::array<char, 2>{{'}', 0}}))); 152 ; 153}; 154 155template <typename Element> 156struct element_signature<std::vector<Element>> { 157 static auto constexpr code = concat(std::array<char, 2>{{DBUS_TYPE_ARRAY, 0}}, 158 element_signature<Element>::code); 159}; 160 161template <typename InvalidType> |
|
53struct element { 54 static const int code = DBUS_TYPE_INVALID; 55}; 56 57template <> 58struct element<bool> { 59 static const int code = DBUS_TYPE_BOOLEAN; 60}; --- 38 unchanged lines hidden (view full) --- 99 static const int code = DBUS_TYPE_DOUBLE; 100}; 101 102template <> 103struct element<string> { 104 static const int code = DBUS_TYPE_STRING; 105}; 106 | 162struct element { 163 static const int code = DBUS_TYPE_INVALID; 164}; 165 166template <> 167struct element<bool> { 168 static const int code = DBUS_TYPE_BOOLEAN; 169}; --- 38 unchanged lines hidden (view full) --- 208 static const int code = DBUS_TYPE_DOUBLE; 209}; 210 211template <> 212struct element<string> { 213 static const int code = DBUS_TYPE_STRING; 214}; 215 |
107template <typename Element> 108struct element<std::vector<Element>> { 109 static const int code = DBUS_TYPE_ARRAY; 110}; 111 | |
112template <> 113struct element<dbus_variant> { 114 static const int code = DBUS_TYPE_VARIANT; 115}; 116 117template <> 118struct element<object_path> { 119 static const int code = DBUS_TYPE_OBJECT_PATH; --- 80 unchanged lines hidden --- | 216template <> 217struct element<dbus_variant> { 218 static const int code = DBUS_TYPE_VARIANT; 219}; 220 221template <> 222struct element<object_path> { 223 static const int code = DBUS_TYPE_OBJECT_PATH; --- 80 unchanged lines hidden --- |