dbus-cxx
types.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later OR BSD-3-Clause
2/***************************************************************************
3 * Copyright (C) 2007,2008,2009,2010 by Rick L. Vinyard, Jr. *
4 * rvinyard@cs.nmsu.edu *
5 * *
6 * This file is part of the dbus-cxx library. *
7 ***************************************************************************/
8#include <dbus-cxx/enums.h>
9#include <dbus-cxx/path.h>
10#include <dbus-cxx/signature.h>
12#include <stdint.h>
13#include <string>
14#include <tuple>
15#include <vector>
16
17#ifndef DBUSCXX_TYPES_H
18#define DBUSCXX_TYPES_H
19
20namespace DBus {
21
22typedef std::map<DBus::Path,std::map<std::string,std::map<std::string,DBus::Variant>>> ObjectManagerObjects;
23
24class Variant;
25
26inline int typeToDBusType( DataType t ) {
27 return static_cast<int>( t );
28}
29
31 return static_cast<int>( t );
32}
33
34inline DataType char_to_dbus_type( char c ) {
35 switch( c ) {
36 case 'y':
37 return DataType::BYTE;
38
39 case 'b':
40 return DataType::BOOLEAN;
41
42 case 'n':
43 return DataType::INT16;
44
45 case 'q':
46 return DataType::UINT16;
47
48 case 'i':
49 return DataType::INT32;
50
51 case 'u':
52 return DataType::UINT32;
53
54 case 'x':
55 return DataType::INT64;
56
57 case 't':
58 return DataType::UINT64;
59
60 case 'd':
61 return DataType::DOUBLE;
62
63 case 's':
64 return DataType::STRING;
65
66 case 'o':
68
69 case 'g':
71
72 case 'a':
73 return DataType::ARRAY;
74
75 case 'r':
76 case '(':
77 case ')':
78 return DataType::STRUCT;
79
80 case 'v':
81 return DataType::VARIANT;
82
83 case 'e':
84 case '{':
85 case '}':
87
88 case 'h':
89 return DataType::UNIX_FD;
90
91 }
92
93 return DataType::INVALID;
94}
95
97 switch( c ) {
98 case 'a':
100
101 case 'e':
102 case '{':
104
105 case '(':
106 case 'r':
108
109 case 'v':
111 }
112
113 return ContainerType::None;
114}
115
116inline bool is_ending_container( char c ) {
117 switch( c ) {
118 case '}':
119 case ')':
120 return true;
121
122 default:
123 return false;
124 }
125}
126
128 switch( c ) {
129 case '}':
131
132 case ')':
134 }
135
136 return ContainerType::None;
137}
138
139inline DataType type( const uint8_t& ) { return DataType::BYTE; }
140inline DataType type( const bool& ) { return DataType::BOOLEAN; }
141inline DataType type( const int16_t& ) { return DataType::INT16; }
142inline DataType type( const uint16_t& ) { return DataType::UINT16; }
143inline DataType type( const int32_t& ) { return DataType::INT32; }
144inline DataType type( const uint32_t& ) { return DataType::UINT32; }
145inline DataType type( const int64_t& ) { return DataType::INT64; }
146inline DataType type( const uint64_t& ) { return DataType::UINT64; }
147inline DataType type( const double& ) { return DataType::DOUBLE; }
148inline DataType type( const std::string& ) { return DataType::STRING; }
149inline DataType type( const char* ) { return DataType::STRING; }
150inline DataType type( const Path& ) { return DataType::OBJECT_PATH; }
151inline DataType type( const Signature& ) { return DataType::SIGNATURE; }
152template <typename... args>
153inline DataType type( const DBus::Variant& ) { return DataType::VARIANT; }
154inline DataType type( const FileDescriptor& ) { return DataType::UNIX_FD; }
155
156inline DataType type( const char& ) { return DataType::BYTE; }
157inline DataType type( const int8_t& ) { return DataType::BYTE; }
158
159inline DataType type( const float& ) { return DataType::DOUBLE; }
160
161template <typename T>
162inline DataType type( const std::vector<T>& ) { return DataType::ARRAY; }
163
164template <typename ...T>
165inline DataType type( const std::tuple<T...>& ) { return DataType::STRUCT; }
166
167inline
169 return ( DataType )( n );
170}
171
176class TypeInfo {
177public:
181 TypeInfo( DataType d );
182
186 bool isTemplated() const;
187
191 std::vector<std::string> includeFilesForType() const;
192
196 std::string cppType() const;
197
199 bool is_basic() const;
200
202 bool is_fixed() const;
203
205 bool is_container() const;
206
211 int32_t alignment() const;
212
217 char to_dbus_char() const;
218
219private:
221};
222
223std::ostream& operator<<( std::ostream& os, DataType d );
224
225}
226
227#endif
A FileDescriptor holds a UNIX file descriptor that can be passed between processes.
Definition: filedescriptor.h:21
Represents a DBus Path.
Definition: path.h:21
Represents a DBus signature.
Definition: signature.h:78
Contains useful data about the type in order for code generation to happen in an easy manner.
Definition: types.h:176
DataType m_type
Definition: types.h:220
int32_t alignment() const
Return the alignment of the type.
Definition: types.cpp:181
TypeInfo(DataType d)
The type to get info for.
Definition: types.cpp:15
bool is_container() const
True if the element type is a container.
Definition: types.cpp:168
std::string cppType() const
Returns the C++ type of this DataType.
Definition: types.cpp:72
bool isTemplated() const
Returns true if this type is templated.
Definition: types.cpp:17
std::vector< std::string > includeFilesForType() const
Returns the needed includes in order to use this type.
Definition: types.cpp:31
char to_dbus_char() const
Turn this type into a DBus char.
Definition: types.cpp:215
bool is_basic() const
True if the element type is a basic type.
Definition: types.cpp:132
bool is_fixed() const
True if the element type is a fixed type.
Definition: types.cpp:152
A Variant is a type-safe union for DBus operations.
Definition: variant.h:42
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
int typeToDBusContainerType(ContainerType t)
Definition: types.h:30
ContainerType
Definition: enums.h:73
DataType checked_type_cast(int n)
Definition: types.h:168
std::shared_ptr< DBus::Connection > operator<<(std::shared_ptr< DBus::Connection > ptr, std::shared_ptr< DBus::Message > msg)
Definition: connection.h:449
bool is_ending_container(char c)
Definition: types.h:116
DataType type(const uint8_t &)
Definition: types.h:139
std::map< DBus::Path, std::map< std::string, std::map< std::string, DBus::Variant > > > ObjectManagerObjects
Definition: types.h:22
ContainerType char_to_ending_container(char c)
Definition: types.h:127
DataType char_to_dbus_type(char c)
Definition: types.h:34
DataType
Definition: enums.h:52
int typeToDBusType(DataType t)
Definition: types.h:26
ContainerType char_to_container_type(char c)
Definition: types.h:96