dbus-cxx logo
messageappenditerator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2009,2010 by Rick L. Vinyard, Jr. *
3  * rvinyard@cs.nmsu.edu *
4  * *
5  * This file is part of the dbus-cxx library. *
6  * *
7  * The dbus-cxx library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License *
9  * version 3 as published by the Free Software Foundation. *
10  * *
11  * The dbus-cxx library is distributed in the hope that it will be *
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this software. If not see <http://www.gnu.org/licenses/>. *
18  ***************************************************************************/
19 #include <string>
20 #include <vector>
21 #include <map>
22 
23 #include <dbus/dbus.h>
24 
25 #include <dbus-cxx/types.h>
27 
28 #ifndef DBUSCXX_MESSAGEAPPENDITERATOR_H
29 #define DBUSCXX_MESSAGEAPPENDITERATOR_H
30 
31 namespace DBus
32 {
33 
34  class Message;
35 
44  {
45  public:
46 
48 
50 
51  MessageAppendIterator( DBusCxxPointer<Message> message );
52 
54 
59  const Message* message() const;
60 
62  DBusMessageIter* cobj();
63 
65  bool init( Message& message );
66 
68  void invalidate();
69 
71  bool is_valid() const;
72 
74  operator bool() const;
75 
76  bool append( bool v );
77  bool append( uint8_t v );
78  bool append( int16_t v );
79  bool append( uint16_t v );
80  bool append( int32_t v );
81  bool append( uint32_t v );
82  bool append( int64_t v );
83  bool append( uint64_t v );
84  bool append( double v );
85  bool append( const char* v );
86  bool append( const std::string& v );
87  bool append( const Signature& v );
88  bool append( const Path& v );
89  bool append( const FileDescriptor& fd);
90 
91  bool append( char v );
92  bool append( int8_t v );
93  bool append( float v );
94  #if DBUS_CXX_SIZEOF_LONG_INT == 4
95  bool append( long int v );
96  bool append( long unsigned int v );
97  #endif
98 
99  template <typename T>
100  bool append( const std::vector<T>& v){
101  bool success;
102  T type;
103  success = this->open_container( CONTAINER_ARRAY, DBus::signature(type).c_str() );
104 
105  if( not success ){
106  throw ErrorNoMemory::create();
107  }
108 
109  for ( size_t i=0; i < v.size(); i++ )
110  *m_subiter << v[i];
111 
112  return this->close_container();
113  }
114 
115  template <typename Key, typename Data>
116  bool append( const std::map<Key,Data>& dictionary ){
117  std::string sig = signature_dict_data( dictionary );
118  typename std::map<Key,Data>::const_iterator it;
119  this->open_container( CONTAINER_ARRAY, sig );
120  for ( it = dictionary.begin(); it != dictionary.end(); it++ ) {
121  m_subiter->open_container( CONTAINER_DICT_ENTRY, std::string() );
122  m_subiter->m_subiter->append( (*it).first );
123  m_subiter->m_subiter->append( (*it).second );
125  }
126  return this->close_container();
127 
128  }
129 
130  template <typename T>
131  bool append( const Variant<T> & var){
133  m_subiter->append(var.data);
134  return this->close_container();
135  }
136 
137  template <typename T>
139  {
140  this->append( v );
141  return *this;
142  }
143 
144 
145 // template <typename T0, typename T1>
146 // void append(const Struct<T0,T1>& s) {
147 // this->open_container( CONTAINER_STRUCT, std::string() );
148 // m_subiter->append( boost::get<0>(s) );
149 // m_subiter->append( boost::get<1>(s) );
150 // this->close_container();
151 // }
152  //
153 // template <typename T0, typename T1, typename T2>
154 // void append(const Struct<T0,T1,T2>& s) {
155 // this->open_container( CONTAINER_STRUCT, std::string() );
156 // m_subiter->append( boost::get<0>(s) );
157 // m_subiter->append( boost::get<1>(s) );
158 // m_subiter->append( boost::get<2>(s) );
159 // this->close_container();
160 // }
161  //
162 // template <typename T0, typename T1, typename T2, typename T3>
163 // void append(const Struct<T0,T1,T2,T3>& s) {
164 // this->open_container( CONTAINER_STRUCT, std::string() );
165 // m_subiter->append( boost::get<0>(s) );
166 // m_subiter->append( boost::get<1>(s) );
167 // m_subiter->append( boost::get<2>(s) );
168 // m_subiter->append( boost::get<3>(s) );
169 // this->close_container();
170 // }
171  //
172 // template <typename T0, typename T1, typename T2, typename T3, typename T4>
173 // void append(const Struct<T0,T1,T2,T3,T4>& s) {
174 // this->open_container( CONTAINER_STRUCT, std::string() );
175 // m_subiter->append( boost::get<0>(s) );
176 // m_subiter->append( boost::get<1>(s) );
177 // m_subiter->append( boost::get<2>(s) );
178 // m_subiter->append( boost::get<3>(s) );
179 // m_subiter->append( boost::get<4>(s) );
180 // this->close_container();
181 // }
182  //
183 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
184 // void append(const Struct<T0,T1,T2,T3,T4,T5>& s) {
185 // this->open_container( CONTAINER_STRUCT, std::string() );
186 // m_subiter->append( boost::get<0>(s) );
187 // m_subiter->append( boost::get<1>(s) );
188 // m_subiter->append( boost::get<2>(s) );
189 // m_subiter->append( boost::get<3>(s) );
190 // m_subiter->append( boost::get<4>(s) );
191 // m_subiter->append( boost::get<5>(s) );
192 // this->close_container();
193 // }
194  //
195 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
196 // void append(const Struct<T0,T1,T2,T3,T4,T5,T6>& s) {
197 // this->open_container( CONTAINER_STRUCT, std::string() );
198 // m_subiter->append( boost::get<0>(s) );
199 // m_subiter->append( boost::get<1>(s) );
200 // m_subiter->append( boost::get<2>(s) );
201 // m_subiter->append( boost::get<3>(s) );
202 // m_subiter->append( boost::get<4>(s) );
203 // m_subiter->append( boost::get<5>(s) );
204 // m_subiter->append( boost::get<6>(s) );
205 // this->close_container();
206 // }
207 
208  bool open_container( ContainerType t, const std::string& contained_signature );
209 
210  bool close_container( );
211 
213 
214 // bool append_array( char type, const void* ptr, size_t length );
215 
216 // iterator new_array( const char* sig );
217 
218 // iterator new_variant( const char* sig );
219 
220 // iterator new_struct();
221 
222 // iterator new_dict_entry();
223 
224 // void close_container( iterator& container );
225 
226  protected:
228  DBusMessageIter m_cobj;
230 
231  template <typename T> bool protected_append( const T& v );
232  bool protected_append( const bool& v );
233  bool protected_append( const std::string& v );
234  bool protected_append( const Signature& v );
235  bool protected_append( const Path& v );
236  bool protected_append( const FileDescriptor& fd );
237  };
238 
239 }
240 
241 #endif
242 
bool append(bool v)
Definition: messageappenditerator.cpp:161
bool append(const std::vector< T > &v)
Definition: messageappenditerator.h:100
Definition: enums.h:65
Definition: accumulators.h:24
DBusMessageIter m_cobj
Definition: messageappenditerator.h:228
DBusMessageIter * cobj()
Returns a pointer to the underlying DBusMessageIter object.
Definition: messageappenditerator.cpp:122
A Variant is a type of DBus object that can be one of several different types of normal DBus object...
Definition: variant.h:33
ContainerType
Definition: enums.h:63
MessageAppendIterator & operator<<(const T &v)
Definition: messageappenditerator.h:138
bool append(const std::map< Key, Data > &dictionary)
Definition: messageappenditerator.h:116
const Message * message() const
Returns a pointer to the message associated with this iterator or NULL if no message is associated...
This class represents a basic DBus message and also serves as a base class for the specialized messag...
Definition: message.h:56
bool protected_append(const T &v)
Definition: messageappenditerator.cpp:71
bool init(Message &message)
Initializes the iterator for the specified message.
Definition: messageappenditerator.cpp:127
bool append(const Variant< T > &var)
Definition: messageappenditerator.h:131
Definition: enums.h:68
bool open_container(ContainerType t, const std::string &contained_signature)
Definition: messageappenditerator.cpp:261
Message * m_message
Definition: messageappenditerator.h:227
~MessageAppendIterator()
Definition: messageappenditerator.cpp:117
Insertion iterator allow values to be appended to a message.
Definition: messageappenditerator.h:43
A FileDescriptor holds a UNIX file descriptor that can be passed between processes.
Definition: filedescriptor.h:30
MessageAppendIterator()
Definition: messageappenditerator.cpp:97
Definition: path.h:31
Definition: signature.h:37
Type type(uint8_t)
Definition: types.h:38
void invalidate()
Invalidates the iterator.
Definition: messageappenditerator.cpp:143
std::string signature_dict_data(const std::map< Key, Data > &)
Definition: signature.h:137
MessageAppendIterator * m_subiter
Definition: messageappenditerator.h:229
std::string signature(uint8_t &)
Definition: signature.h:94
bool close_container()
Definition: messageappenditerator.cpp:280
Definition: enums.h:66
T data
Definition: variant.h:36
MessageAppendIterator * sub_iterator()
Definition: messageappenditerator.cpp:291
bool is_valid() const
True if this is a valid iterator.
Definition: messageappenditerator.cpp:150

Generated on Sun Mar 19 2017 14:54:27 for dbus-cxx by doxygen 1.8.8