DBus-1-TQt  1.0
tqdbusdatamap.h
Go to the documentation of this file.
1 /* qdbusdatamap.h DBUS data mapping transport type
2  *
3  * Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
4  *
5  * Licensed under the Academic Free License version 2.1
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20  * USA.
21  *
22  */
23 
24 #ifndef TQDBUSDATAMAP_H
25 #define TQDBUSDATAMAP_H
26 
27 #include "tqdbusmacros.h"
28 #include <tqmap.h>
29 
30 class TQT_DBusData;
31 class TQT_DBusObjectPath;
32 class TQT_DBusUnixFd;
33 class TQT_DBusVariant;
34 
72 template <typename T>
73 class TQDBUS_EXPORT TQT_DBusDataMap : private TQMap<T, TQT_DBusData>
74 {
75  friend class TQT_DBusData;
76 
77 public:
82  typedef TQMapConstIterator<T, TQT_DBusData> const_iterator;
83 
90  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Invalid) {}
91 
103  explicit TQT_DBusDataMap<T>(TQT_DBusData::Type simpleValueType)
104  : TQMap<T, TQT_DBusData>(), m_valueType(simpleValueType) {}
105 
116  explicit TQT_DBusDataMap<T>(const TQT_DBusData& containerValueType)
117  : TQMap<T, TQT_DBusData>(), m_valueType(containerValueType.type())
118  {
119  if (hasContainerValueType()) m_containerValueType = containerValueType;
120  }
121 
131  : TQMap<T, TQT_DBusData>(other), m_valueType(other.m_valueType),
132  m_containerValueType(other.m_containerValueType) {}
133 
150  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusData>& other)
151  : TQMap<T, TQT_DBusData>(other), m_valueType(TQT_DBusData::Invalid)
152  {
153  const_iterator it = begin();
154  if (it == end()) return;
155 
156  m_valueType = (*it).type();
157 
158  TQCString containerSignature;
159  if (hasContainerValueType())
160  {
161  m_containerValueType = it.data();
162  containerSignature = m_containerValueType.buildDBusSignature();
163  }
164 
165  for (++it; it != end(); ++it)
166  {
167  if ((*it).type() != m_valueType)
168  {
169  m_valueType = TQT_DBusData::Invalid;
170  m_containerValueType = TQT_DBusData();
171 
172  clear();
173  return;
174  }
175  else if (hasContainerValueType())
176  {
177  if (it.data().buildDBusSignature() != containerSignature)
178  {
179  m_valueType = TQT_DBusData::Invalid;
180  m_containerValueType = TQT_DBusData();
181 
182  clear();
183  return;
184  }
185  }
186  }
187  }
188 
201  TQT_DBusDataMap<T>(const TQMap<T, bool>& other)
202  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Bool)
203  {
204  typename TQMap<T, bool>::const_iterator it = other.begin();
205  typename TQMap<T, bool>::const_iterator endIt = other.end();
206  for (; it != endIt; ++it)
207  {
208  insert(it.key(), TQT_DBusData::fromBool(it.data()));
209  }
210  }
211 
224  TQT_DBusDataMap<T>(const TQMap<T, TQ_UINT8>& other)
225  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Byte)
226  {
227  typename TQMap<T, TQ_UINT8>::const_iterator it = other.begin();
228  typename TQMap<T, TQ_UINT8>::const_iterator endIt = other.end();
229  for (; it != endIt; ++it)
230  {
231  insert(it.key(), TQT_DBusData::fromByte(it.data()));
232  }
233  }
234 
247  TQT_DBusDataMap<T>(const TQMap<T, TQ_INT16>& other)
248  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Int16)
249  {
250  typename TQMap<T, TQ_INT16>::const_iterator it = other.begin();
251  typename TQMap<T, TQ_INT16>::const_iterator endIt = other.end();
252  for (; it != endIt; ++it)
253  {
254  insert(it.key(), TQT_DBusData::fromInt16(it.data()));
255  }
256  }
257 
270  TQT_DBusDataMap<T>(const TQMap<T, TQ_UINT16>& other)
271  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::UInt16)
272  {
273  typename TQMap<T, TQ_UINT16>::const_iterator it = other.begin();
274  typename TQMap<T, TQ_UINT16>::const_iterator endIt = other.end();
275  for (; it != endIt; ++it)
276  {
277  insert(it.key(), TQT_DBusData::fromUInt16(it.data()));
278  }
279  }
280 
293  TQT_DBusDataMap<T>(const TQMap<T, TQ_INT32>& other)
294  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Int32)
295  {
296  typename TQMap<T, TQ_INT32>::const_iterator it = other.begin();
297  typename TQMap<T, TQ_INT32>::const_iterator endIt = other.end();
298  for (; it != endIt; ++it)
299  {
300  insert(it.key(), TQT_DBusData::fromInt32(it.data()));
301  }
302  }
303 
316  TQT_DBusDataMap<T>(const TQMap<T, TQ_UINT32>& other)
317  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::UInt32)
318  {
319  typename TQMap<T, TQ_UINT32>::const_iterator it = other.begin();
320  typename TQMap<T, TQ_UINT32>::const_iterator endIt = other.end();
321  for (; it != endIt; ++it)
322  {
323  insert(it.key(), TQT_DBusData::fromUInt32(it.data()));
324  }
325  }
326 
339  TQT_DBusDataMap<T>(const TQMap<T, TQ_INT64>& other)
340  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Int64)
341  {
342  typename TQMap<T, TQ_INT64>::const_iterator it = other.begin();
343  typename TQMap<T, TQ_INT64>::const_iterator endIt = other.end();
344  for (; it != endIt; ++it)
345  {
346  insert(it.key(), TQT_DBusData::fromInt64(it.data()));
347  }
348  }
349 
362  TQT_DBusDataMap<T>(const TQMap<T, TQ_UINT64>& other)
363  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::UInt64)
364  {
365  typename TQMap<T, TQ_UINT64>::const_iterator it = other.begin();
366  typename TQMap<T, TQ_UINT64>::const_iterator endIt = other.end();
367  for (; it != endIt; ++it)
368  {
369  insert(it.key(), TQT_DBusData::fromUInt64(it.data()));
370  }
371  }
372 
385  TQT_DBusDataMap<T>(const TQMap<T, double>& other)
386  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Double)
387  {
388  typename TQMap<T, double>::const_iterator it = other.begin();
389  typename TQMap<T, double>::const_iterator endIt = other.end();
390  for (; it != endIt; ++it)
391  {
392  insert(it.key(), TQT_DBusData::fromDouble(it.data()));
393  }
394  }
395 
408  TQT_DBusDataMap<T>(const TQMap<T, TQString>& other)
409  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::String)
410  {
411  typename TQMap<T, TQString>::const_iterator it = other.begin();
412  typename TQMap<T, TQString>::const_iterator endIt = other.end();
413  for (; it != endIt; ++it)
414  {
415  insert(it.key(), TQT_DBusData::fromString(it.data()));
416  }
417  }
418 
431  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusObjectPath>& other)
432  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::ObjectPath)
433  {
434  typename TQMap<T, TQT_DBusObjectPath>::const_iterator it = other.begin();
435  typename TQMap<T, TQT_DBusObjectPath>::const_iterator endIt = other.end();
436  for (; it != endIt; ++it)
437  {
438  insert(it.key(), TQT_DBusData::fromObjectPath(it.data()));
439  }
440  }
441 
454  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusUnixFd>& other)
455  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::UnixFd)
456  {
457  typename TQMap<T, TQT_DBusUnixFd>::const_iterator it = other.begin();
458  typename TQMap<T, TQT_DBusUnixFd>::const_iterator endIt = other.end();
459  for (; it != endIt; ++it)
460  {
461  insert(it.key(), TQT_DBusData::fromUnixFd(it.data()));
462  }
463  }
464 
477  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusVariant>& other)
478  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Variant)
479  {
480  typename TQMap<T, TQT_DBusVariant>::const_iterator it = other.begin();
481  typename TQMap<T, TQT_DBusVariant>::const_iterator endIt = other.end();
482  for (; it != endIt; ++it)
483  {
484  insert(it.key(), TQT_DBusData::fromVariant(it.data()));
485  }
486  }
487 
493  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_UINT8> >& other)
494  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
495  {
496  typename TQMap<T, TQT_DBusDataMap<TQ_UINT8> >::const_iterator it = other.begin();
497  typename TQMap<T, TQT_DBusDataMap<TQ_UINT8> >::const_iterator endIt = other.end();
498  for (; it != endIt; ++it)
499  {
500  insert(it.key(), TQT_DBusData::fromByteKeyMap(it.data()));
501  }
502  }
503 
509  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_INT16> >& other)
510  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
511  {
512  typename TQMap<T, TQT_DBusDataMap<TQ_INT16> >::const_iterator it = other.begin();
513  typename TQMap<T, TQT_DBusDataMap<TQ_INT16> >::const_iterator endIt = other.end();
514  for (; it != endIt; ++it)
515  {
516  insert(it.key(), TQT_DBusData::fromInt16KeyMap(it.data()));
517  }
518  }
519 
525  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_UINT16> >& other)
526  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
527  {
528  typename TQMap<T, TQT_DBusDataMap<TQ_UINT16> >::const_iterator it = other.begin();
529  typename TQMap<T, TQT_DBusDataMap<TQ_UINT16> >::const_iterator endIt = other.end();
530  for (; it != endIt; ++it)
531  {
532  insert(it.key(), TQT_DBusData::fromUInt16KeyMap(it.data()));
533  }
534  }
535 
541  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_INT32> >& other)
542  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
543  {
544  typename TQMap<T, TQT_DBusDataMap<TQ_INT32> >::const_iterator it = other.begin();
545  typename TQMap<T, TQT_DBusDataMap<TQ_INT32> >::const_iterator endIt = other.end();
546  for (; it != endIt; ++it)
547  {
548  insert(it.key(), TQT_DBusData::fromInt32KeyMap(it.data()));
549  }
550  }
551 
557  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_UINT32> >& other)
558  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
559  {
560  typename TQMap<T, TQT_DBusDataMap<TQ_UINT32> >::const_iterator it = other.begin();
561  typename TQMap<T, TQT_DBusDataMap<TQ_UINT32> >::const_iterator endIt = other.end();
562  for (; it != endIt; ++it)
563  {
564  insert(it.key(), TQT_DBusData::fromUInt32KeyMap(it.data()));
565  }
566  }
567 
573  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_INT64> >& other)
574  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
575  {
576  typename TQMap<T, TQT_DBusDataMap<TQ_INT64> >::const_iterator it = other.begin();
577  typename TQMap<T, TQT_DBusDataMap<TQ_INT64> >::const_iterator endIt = other.end();
578  for (; it != endIt; ++it)
579  {
580  insert(it.key(), TQT_DBusData::fromInt64KeyMap(it.data()));
581  }
582  }
583 
589  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQ_UINT64> >& other)
590  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
591  {
592  typename TQMap<T, TQT_DBusDataMap<TQ_UINT64> >::const_iterator it = other.begin();
593  typename TQMap<T, TQT_DBusDataMap<TQ_UINT64> >::const_iterator endIt = other.end();
594  for (; it != endIt; ++it)
595  {
596  insert(it.key(), TQT_DBusData::fromUInt64KeyMap(it.data()));
597  }
598  }
599 
605  TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusDataMap<TQString> >& other)
606  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
607  {
608  typename TQMap<T, TQT_DBusDataMap<TQString> >::const_iterator it = other.begin();
609  typename TQMap<T, TQT_DBusDataMap<TQString> >::const_iterator endIt = other.end();
610  for (; it != endIt; ++it)
611  {
612  insert(it.key(), TQT_DBusData::fromStringKeyMap(it.data()));
613  }
614  }
615 
622  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
623  {
624  typename TQMap<T, TQT_DBusDataMap<TQT_DBusObjectPath> >::const_iterator it = other.begin();
625  typename TQMap<T, TQT_DBusDataMap<TQT_DBusObjectPath> >::const_iterator endIt = other.end();
626  for (; it != endIt; ++it)
627  {
628  insert(it.key(), TQT_DBusData::fromObjectPathKeyMap(it.data()));
629  }
630  }
631 
638  : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::Map)
639  {
640  typename TQMap<T, TQT_DBusDataMap<TQT_DBusUnixFd > >::const_iterator it = other.begin();
641  typename TQMap<T, TQT_DBusDataMap<TQT_DBusUnixFd > >::const_iterator endIt = other.end();
642  for (; it != endIt; ++it)
643  {
644  insert(it.key(), TQT_DBusData::fromUnixFdKeyMap(it.data()));
645  }
646  }
647 
659  {
660  TQMap<T, TQT_DBusData>::operator=(other);
661 
662  m_valueType = other.m_valueType;
663  m_containerValueType = other.m_containerValueType;
664 
665  return *this;
666  }
667 
682  TQT_DBusDataMap<T>& operator=(const TQMap<T, TQT_DBusData>& other)
683  {
684  TQMap<T, TQT_DBusData>::operator=(other);
685 
686  m_valueType = TQT_DBusData::Invalid;
687  m_containerValueType = TQT_DBusData();
688 
689  const_iterator it = begin();
690  if (it == end()) return *this;
691 
692  m_valueType = (*it).type();
693 
694  TQCString containerSignature;
695  if (hasContainerValueType())
696  {
697  m_containerValueType = it.data();
698  containerSignature = m_containerValueType.buildDBusSignature();
699  }
700 
701  for (++it; it != end(); ++it)
702  {
703  if ((*it).type() != m_valueType)
704  {
705  m_valueType = TQT_DBusData::Invalid;
706  m_containerValueType = TQT_DBusData();
707 
708  clear();
709  return *this;
710  }
711  else if (hasContainerValueType())
712  {
713  if (it.data()->buildSignature() != containerSignature)
714  {
715  m_valueType = TQT_DBusData::Invalid;
716  m_containerValueType = TQT_DBusData();
717 
718  clear();
719  return *this;
720  }
721  }
722  }
723 
724  return *this;
725  }
726 
735  TQT_DBusData::Type keyType() const { return m_keyType; }
736 
746  TQT_DBusData::Type valueType() const { return m_valueType; }
747 
762  {
763  return m_valueType == TQT_DBusData::List || m_valueType == TQT_DBusData::Struct
764  || m_valueType == TQT_DBusData::Map;
765  }
766 
782  TQT_DBusData containerValueType() const { return m_containerValueType; }
783 
791  inline bool isValid() const { return valueType() != TQT_DBusData::Invalid; }
792 
800  bool isEmpty() const { return TQMap<T, TQT_DBusData>::empty(); }
801 
809  uint count() const { return TQMap<T, TQT_DBusData>::count(); }
810 
824  bool operator==(const TQT_DBusDataMap<T>& other) const
825  {
826  if (m_valueType != other.m_valueType) return false;
827 
828  if (count() != other.count()) return false;
829 
830  if (hasContainerValueType() != other.hasContainerValueType()) return false;
831 
832  if (hasContainerValueType())
833  {
834  if (m_containerValueType.buildDBusSignature() !=
835  other.m_containerValueType.buildDBusSignature()) return false;
836  }
837 
838  const_iterator it = begin();
839  const_iterator otherIt = other.begin();
840  for (; it != end() && otherIt != other.end(); ++it, ++otherIt)
841  {
842  if (it.key() != otherIt.key()) return false;
843 
844  if (!(it.data() == otherIt.data())) return false;
845  }
846 
847  return true;
848  }
849 
855  void clear() { TQMap<T, TQT_DBusData>::clear(); }
856 
863  {
864  return TQMap<T, TQT_DBusData>::begin();
865  }
866 
873  {
874  return TQMap<T, TQT_DBusData>::end();
875  }
876 
895  bool insert(const T& key, const TQT_DBusData& data)
896  {
897  if (data.type() == TQT_DBusData::Invalid) return false;
898 
899  if (m_valueType == TQT_DBusData::Invalid)
900  {
901  m_valueType = data.type();
902 
903  // TODO: create empty copy of container
904  if (hasContainerValueType()) m_containerValueType = data;
905 
906  TQMap<T, TQT_DBusData>::insert(key, data);
907  }
908  else if (data.type() != m_valueType)
909  {
910  tqWarning("TQT_DBusDataMap: trying to add data of type %s to map of type %s",
911  data.typeName(), TQT_DBusData::typeName(m_valueType));
912  }
913  else if (hasContainerValueType())
914  {
915  TQCString ourSignature = m_containerValueType.buildDBusSignature();
916  TQCString dataSignature = data.buildDBusSignature();
917 
918  if (ourSignature != dataSignature)
919  {
920  tqWarning("TQT_DBusDataMap: trying to add data with signature %s "
921  "to map with value signature %s",
922  dataSignature.data(), ourSignature.data());
923  }
924  else
925  TQMap<T, TQT_DBusData>::insert(key, data);
926  }
927  else
928  TQMap<T, TQT_DBusData>::insert(key, data);
929 
930  return true;
931  }
932 
938  TQMap<T, TQT_DBusData> toTQMap() const { return *this; }
939 
956  TQMap<T, bool> toBoolMap(bool* ok = 0) const
957  {
958  if (m_valueType != TQT_DBusData::Bool)
959  {
960  if (ok != 0) *ok = false;
961  return TQMap<T, bool>();
962  }
963 
964  TQMap<T, bool> result;
965 
966  const_iterator it = begin();
967  const_iterator endIt = end();
968  for (; it != endIt; ++it)
969  {
970  result.insert(it.key(), (*it).toBool());
971  }
972 
973  if (ok != 0) *ok = true;
974 
975  return result;
976  }
977 
994  TQMap<T, TQ_UINT8> toByteMap(bool* ok = 0) const
995  {
996  if (m_valueType != TQT_DBusData::Byte)
997  {
998  if (ok != 0) *ok = false;
999  return TQMap<T, TQ_UINT8>();
1000  }
1001 
1002  TQMap<T, TQ_UINT8> result;
1003 
1004  const_iterator it = begin();
1005  const_iterator endIt = end();
1006  for (; it != endIt; ++it)
1007  {
1008  result.insert(it.key(), (*it).toByte());
1009  }
1010 
1011  if (ok != 0) *ok = true;
1012 
1013  return result;
1014  }
1015 
1033  TQMap<T, TQ_INT16> toInt16Map(bool* ok = 0) const
1034  {
1035  if (m_valueType != TQT_DBusData::Int16)
1036  {
1037  if (ok != 0) *ok = false;
1038  return TQMap<T, TQ_INT16>();
1039  }
1040 
1041  TQMap<T, TQ_INT16> result;
1042 
1043  const_iterator it = begin();
1044  const_iterator endIt = end();
1045  for (; it != endIt; ++it)
1046  {
1047  result.insert(it.key(), (*it).toInt16());
1048  }
1049 
1050  if (ok != 0) *ok = true;
1051 
1052  return result;
1053  }
1054 
1072  TQMap<T, TQ_UINT16> toUInt16Map(bool* ok = 0) const
1073  {
1074  if (m_valueType != TQT_DBusData::UInt16)
1075  {
1076  if (ok != 0) *ok = false;
1077  return TQMap<T, TQ_UINT16>();
1078  }
1079 
1080  TQMap<T, TQ_UINT16> result;
1081 
1082  const_iterator it = begin();
1083  const_iterator endIt = end();
1084  for (; it != endIt; ++it)
1085  {
1086  result.insert(it.key(), (*it).toUInt16());
1087  }
1088 
1089  if (ok != 0) *ok = true;
1090 
1091  return result;
1092  }
1093 
1111  TQMap<T, TQ_INT32> toInt32Map(bool* ok = 0) const
1112  {
1113  if (m_valueType != TQT_DBusData::Int32)
1114  {
1115  if (ok != 0) *ok = false;
1116  return TQMap<T, TQ_INT32>();
1117  }
1118 
1119  TQMap<T, TQ_INT32> result;
1120 
1121  const_iterator it = begin();
1122  const_iterator endIt = end();
1123  for (; it != endIt; ++it)
1124  {
1125  result.insert(it.key(), (*it).toInt32());
1126  }
1127 
1128  if (ok != 0) *ok = true;
1129 
1130  return result;
1131  }
1132 
1150  TQMap<T, TQ_UINT32> toUInt32Map(bool* ok = 0) const
1151  {
1152  if (m_valueType != TQT_DBusData::UInt32)
1153  {
1154  if (ok != 0) *ok = false;
1155  return TQMap<T, TQ_UINT32>();
1156  }
1157 
1158  TQMap<T, TQ_UINT32> result;
1159 
1160  const_iterator it = begin();
1161  const_iterator endIt = end();
1162  for (; it != endIt; ++it)
1163  {
1164  result.insert(it.key(), (*it).toUInt32());
1165  }
1166 
1167  if (ok != 0) *ok = true;
1168 
1169  return result;
1170  }
1171 
1189  TQMap<T, TQ_INT64> toInt64Map(bool* ok = 0) const
1190  {
1191  if (m_valueType != TQT_DBusData::Int64)
1192  {
1193  if (ok != 0) *ok = false;
1194  return TQMap<T, TQ_INT64>();
1195  }
1196 
1197  TQMap<T, TQ_INT64> result;
1198 
1199  const_iterator it = begin();
1200  const_iterator endIt = end();
1201  for (; it != endIt; ++it)
1202  {
1203  result.insert(it.key(), (*it).toInt64());
1204  }
1205 
1206  if (ok != 0) *ok = true;
1207 
1208  return result;
1209  }
1210 
1228  TQMap<T, TQ_UINT64> toUInt64Map(bool* ok = 0) const
1229  {
1230  if (m_valueType != TQT_DBusData::UInt64)
1231  {
1232  if (ok != 0) *ok = false;
1233  return TQMap<T, TQ_UINT64>();
1234  }
1235 
1236  TQMap<T, TQ_UINT64> result;
1237 
1238  const_iterator it = begin();
1239  const_iterator endIt = end();
1240  for (; it != endIt; ++it)
1241  {
1242  result.insert(it.key(), (*it).toUInt64());
1243  }
1244 
1245  if (ok != 0) *ok = true;
1246 
1247  return result;
1248  }
1249 
1266  TQMap<T, double> toDoubleMap(bool* ok = 0) const
1267  {
1268  if (m_valueType != TQT_DBusData::Double)
1269  {
1270  if (ok != 0) *ok = false;
1271  return TQMap<T, double>();
1272  }
1273 
1274  TQMap<T, double> result;
1275 
1276  const_iterator it = begin();
1277  const_iterator endIt = end();
1278  for (; it != endIt; ++it)
1279  {
1280  result.insert(it.key(), (*it).toDouble());
1281  }
1282 
1283  if (ok != 0) *ok = true;
1284 
1285  return result;
1286  }
1287 
1304  TQMap<T, TQString> toStringMap(bool* ok = 0) const
1305  {
1306  if (m_valueType != TQT_DBusData::String)
1307  {
1308  if (ok != 0) *ok = false;
1309  return TQMap<T, TQString>();
1310  }
1311 
1312  TQMap<T, TQString> result;
1313 
1314  const_iterator it = begin();
1315  const_iterator endIt = end();
1316  for (; it != endIt; ++it)
1317  {
1318  result.insert(it.key(), (*it).toString());
1319  }
1320 
1321  if (ok != 0) *ok = true;
1322 
1323  return result;
1324  }
1325 
1339  TQMap<T, TQT_DBusObjectPath> toObjectPathMap(bool* ok = 0) const
1340  {
1341  if (m_valueType != TQT_DBusData::ObjectPath)
1342  {
1343  if (ok != 0) *ok = false;
1344  return TQMap<T, TQT_DBusObjectPath>();
1345  }
1346 
1347  TQMap<T, TQT_DBusObjectPath> result;
1348 
1349  const_iterator it = begin();
1350  const_iterator endIt = end();
1351  for (; it != endIt; ++it)
1352  {
1353  result.insert(it.key(), (*it).toObjectPath());
1354  }
1355 
1356  if (ok != 0) *ok = true;
1357 
1358  return result;
1359  }
1360 
1374  TQMap<T, TQT_DBusObjectPath> toUnixFdMap(bool* ok = 0) const
1375  {
1376  if (m_valueType != TQT_DBusData::UnixFd)
1377  {
1378  if (ok != 0) *ok = false;
1379  return TQMap<T, TQT_DBusUnixFd>();
1380  }
1381 
1382  TQMap<T, TQT_DBusUnixFd> result;
1383 
1384  const_iterator it = begin();
1385  const_iterator endIt = end();
1386  for (; it != endIt; ++it)
1387  {
1388  result.insert(it.key(), (*it).toUnixFd());
1389  }
1390 
1391  if (ok != 0) *ok = true;
1392 
1393  return result;
1394  }
1395 
1412  TQMap<T, TQT_DBusVariant> toVariantMap(bool* ok = 0) const
1413  {
1414  if (m_valueType != TQT_DBusData::Variant)
1415  {
1416  if (ok != 0) *ok = false;
1417  return TQMap<T, TQT_DBusVariant>();
1418  }
1419 
1420  TQMap<T, TQT_DBusVariant> result;
1421 
1422  const_iterator it = begin();
1423  const_iterator endIt = end();
1424  for (; it != endIt; ++it)
1425  {
1426  result.insert(it.key(), (*it).toVariant());
1427  }
1428 
1429  if (ok != 0) *ok = true;
1430 
1431  return result;
1432  }
1433 
1434 private:
1437 
1439 };
1440 
1441 #endif
Class for accurately representing D-Bus data types.
Definition: tqdbusdata.h:59
const char * typeName() const
Returns the string representation of the object's Type.
Definition: tqdbusdata.h:385
Type type() const
Returns the Type of the data object.
Definition: tqdbusdata.cpp:317
static TQT_DBusData fromBool(bool value)
Creates a data object for the given boolean value.
Definition: tqdbusdata.cpp:355
static TQT_DBusData fromUInt64(TQ_UINT64 value)
Creates a data object for the given unsigned 64-bit integer value.
Definition: tqdbusdata.cpp:516
static TQT_DBusData fromInt16(TQ_INT16 value)
Creates a data object for the given signed 16-bit integer value.
Definition: tqdbusdata.cpp:401
static TQT_DBusData fromStringKeyMap(const TQT_DBusDataMap< TQString > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:913
static TQT_DBusData fromUInt32KeyMap(const TQT_DBusDataMap< TQ_UINT32 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:839
static TQT_DBusData fromInt16KeyMap(const TQT_DBusDataMap< TQ_INT16 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:766
static TQT_DBusData fromUInt16KeyMap(const TQT_DBusDataMap< TQ_UINT16 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:790
static TQT_DBusData fromObjectPathKeyMap(const TQT_DBusDataMap< TQT_DBusObjectPath > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:937
static TQT_DBusData fromByte(TQ_UINT8 value)
Creates a data object for the given byte (unsigned char) value.
Definition: tqdbusdata.cpp:378
static TQT_DBusData fromUInt32(TQ_UINT32 value)
Creates a data object for the given unsigned 32-bit integer value.
Definition: tqdbusdata.cpp:470
static TQT_DBusData fromDouble(double value)
Creates a data object for the given double value.
Definition: tqdbusdata.cpp:539
static TQT_DBusData fromUnixFdKeyMap(const TQT_DBusDataMap< TQT_DBusUnixFd > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:962
TQCString buildDBusSignature() const
Creates the data objects D-Bus signature.
static TQT_DBusData fromInt32KeyMap(const TQT_DBusDataMap< TQ_INT32 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:815
static TQT_DBusData fromObjectPath(const TQT_DBusObjectPath &value)
Creates a data object for the given object path value.
Definition: tqdbusdata.cpp:585
static TQT_DBusData fromUnixFd(const TQT_DBusUnixFd &value)
Creates a data object for the given unix file handle value.
Definition: tqdbusdata.cpp:611
static TQT_DBusData fromInt32(TQ_INT32 value)
Creates a data object for the given signed 32-bit integer value.
Definition: tqdbusdata.cpp:447
static TQT_DBusData fromInt64KeyMap(const TQT_DBusDataMap< TQ_INT64 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:864
Type
Enum for the data types used in D-Bus messages.
Definition: tqdbusdata.h:74
TQT_DBusData()
Creates an empty, Invalid data object.
Definition: tqdbusdata.cpp:176
static TQT_DBusData fromString(const TQString &value)
Creates a data object for the given string value.
Definition: tqdbusdata.cpp:562
static TQT_DBusData fromInt64(TQ_INT64 value)
Creates a data object for the given signed 64-bit integer value.
Definition: tqdbusdata.cpp:493
static TQT_DBusData fromVariant(const TQT_DBusVariant &value)
Creates a data object for the given variant value.
Definition: tqdbusdata.cpp:711
static TQT_DBusData fromUInt16(TQ_UINT16 value)
Creates a data object for the given unsigned 16-bit integer value.
Definition: tqdbusdata.cpp:424
static TQT_DBusData fromByteKeyMap(const TQT_DBusDataMap< TQ_UINT8 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:742
static TQT_DBusData fromUInt64KeyMap(const TQT_DBusDataMap< TQ_UINT64 > &map)
Creates a data object for the given map.
Definition: tqdbusdata.cpp:888
Class to transport maps of D-Bus data types.
Definition: tqdbusdatamap.h:74
TQT_DBusData::Type m_valueType
TQMap< T, TQ_UINT32 > toUInt32Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_UINT32.
TQMap< T, TQ_INT16 > toInt16Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_INT16.
TQMap< T, TQT_DBusObjectPath > toObjectPathMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of object paths.
TQT_DBusData::Type keyType() const
Returns the key type of the map object.
TQT_DBusData::Type valueType() const
Returns the value type of the map object.
bool operator==(const TQT_DBusDataMap< T > &other) const
Checks whether the given other map is equal to this one.
TQMap< T, bool > toBoolMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of bool.
TQMap< T, TQT_DBusObjectPath > toUnixFdMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQT_DBusUnixFd.
bool isValid() const
Checks whether this map object has a valid value type.
TQMapConstIterator< T, TQT_DBusData > const_iterator
Definition: tqdbusdatamap.h:82
TQMap< T, TQT_DBusVariant > toVariantMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQT_DBusVariant.
uint count() const
Returns the number of key/value pairs of this map object.
TQMap< T, double > toDoubleMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of double.
TQMap< T, TQString > toStringMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQString.
TQT_DBusData containerValueType() const
Returns a container prototype for the map's value type.
TQT_DBusDataMap< T > & operator=(const TQMap< T, TQT_DBusData > &other)
Copies from the given other map.
TQMap< T, TQ_INT32 > toInt32Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_INT32.
TQMap< T, TQ_UINT16 > toUInt16Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_UINT16.
TQMap< T, TQ_UINT64 > toUInt64Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_UINT64.
const_iterator begin() const
Returns an iterator to the first item according to the key sort order.
TQT_DBusDataMap< T > & operator=(const TQT_DBusDataMap< T > &other)
Copies from the given other map.
bool isEmpty() const
Checks whether this map object has any key/value pairs.
TQT_DBusData m_containerValueType
const_iterator end() const
Returns an iterator to an invalid position.
bool hasContainerValueType() const
Checks whether the value type is a data container itself.
TQMap< T, TQT_DBusData > toTQMap() const
Converts the map object into a TQMap with TQT_DBusData elements.
static const TQT_DBusData::Type m_keyType
void clear()
Clears the map.
TQMap< T, TQ_INT64 > toInt64Map(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_INT64.
TQMap< T, TQ_UINT8 > toByteMap(bool *ok=0) const
Tries to get the map object's pairs as a TQMap of TQ_UINT8.
bool insert(const T &key, const TQT_DBusData &data)
Inserts a given value for a given key.
Class for representing D-Bus object paths.
Class for representing D-Bus unix file handles.
Definition: tqdbusunixfd.h:52
Data type for representing a D-Bus variant.
Definition: tqdbusvariant.h:57
#define TQDBUS_EXPORT
Definition: tqdbusmacros.h:29