DBus-1-TQt 1.0
tqdbusdatalist.cpp
Go to the documentation of this file.
1/* qdbusdatalist.cpp list of DBUS data 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#include "tqdbusdatalist.h"
25#include "tqdbusobjectpath.h"
26#include "tqdbusunixfd.h"
27#include "tqdbusvariant.h"
28
29#include <tqstringlist.h>
30
32{
33public:
34 Private() : type(TQT_DBusData::Invalid) {}
35
36public:
40};
41
43{
44}
45
47{
48 d->type = simpleItemType;
49}
50
51TQT_DBusDataList::TQT_DBusDataList(const TQT_DBusData& containerItemType) : d(new Private())
52{
54
55 switch(d->type)
56 {
57 case TQT_DBusData::List: // fall through
58 case TQT_DBusData::Struct: // fall through
61 break;
62
63 default: // not a container
64 break;
65 }
66}
67
69{
70 d->type = other.d->type;
71 d->list = other.d->list;
73}
74
76{
77 if (other.isEmpty()) return;
78
81
82 d->type = (*it).type();
83
84 TQCString elementSignature;
86 {
87 d->containerItem = other[0]; // would be nice to get an empty one
88 elementSignature = d->containerItem.buildDBusSignature();
89 }
90
91 for (++it; it != endIt; ++it)
92 {
93 if (d->type != (*it).type())
94 {
97
98 return;
99 }
100 else if (hasContainerItemType())
101 {
102 if ((*it).buildDBusSignature() != elementSignature)
103 {
106
107 return;
108 }
109 }
110 }
111
112 d->list = other;
113}
114
116{
118
119 if (other.isEmpty()) return;
120
121 TQValueList<bool>::const_iterator it = other.begin();
122 TQValueList<bool>::const_iterator endIt = other.end();
123 for (; it != endIt; ++it)
124 {
126 }
127}
128
130{
132
133 if (other.isEmpty()) return;
134
135 TQValueList<TQ_UINT8>::const_iterator it = other.begin();
136 TQValueList<TQ_UINT8>::const_iterator endIt = other.end();
137 for (; it != endIt; ++it)
138 {
140 }
141}
142
144{
146
147 if (other.isEmpty()) return;
148
149 TQValueList<TQ_INT16>::const_iterator it = other.begin();
150 TQValueList<TQ_INT16>::const_iterator endIt = other.end();
151 for (; it != endIt; ++it)
152 {
154 }
155}
156
158{
160
161 if (other.isEmpty()) return;
162
164 TQValueList<TQ_UINT16>::const_iterator endIt = other.end();
165 for (; it != endIt; ++it)
166 {
168 }
169}
170
172{
174
175 if (other.isEmpty()) return;
176
177 TQValueList<TQ_INT32>::const_iterator it = other.begin();
178 TQValueList<TQ_INT32>::const_iterator endIt = other.end();
179 for (; it != endIt; ++it)
180 {
182 }
183}
184
186{
188
189 if (other.isEmpty()) return;
190
192 TQValueList<TQ_UINT32>::const_iterator endIt = other.end();
193 for (; it != endIt; ++it)
194 {
196 }
197}
198
200{
202
203 if (other.isEmpty()) return;
204
205 TQValueList<TQ_INT64>::const_iterator it = other.begin();
206 TQValueList<TQ_INT64>::const_iterator endIt = other.end();
207 for (; it != endIt; ++it)
208 {
210 }
211}
212
214{
216
217 if (other.isEmpty()) return;
218
220 TQValueList<TQ_UINT64>::const_iterator endIt = other.end();
221 for (; it != endIt; ++it)
222 {
224 }
225}
226
228{
230
231 if (other.isEmpty()) return;
232
233 TQValueList<double>::const_iterator it = other.begin();
234 TQValueList<double>::const_iterator endIt = other.end();
235 for (; it != endIt; ++it)
236 {
238 }
239}
240
242 : d(new Private())
243{
245
246 if (other.isEmpty()) return;
247
250 for (; it != endIt; ++it)
251 {
253 }
254}
255
256TQT_DBusDataList::TQT_DBusDataList(const TQStringList& other) : d(new Private())
257{
259
260 if (other.isEmpty()) return;
261
262 TQStringList::const_iterator it = other.begin();
263 TQStringList::const_iterator endIt = other.end();
264 for (; it != endIt; ++it)
265 {
267 }
268}
269
271 : d(new Private())
272{
274
275 if (other.isEmpty()) return;
276
279 for (; it != endIt; ++it)
280 {
282 }
283}
284
286 : d(new Private())
287{
289
290 if (other.isEmpty()) return;
291
294 for (; it != endIt; ++it)
295 {
297 }
298}
299
301{
302 delete d;
303}
304
306{
307 if (&other == this) return *this;
308
309 d->type = other.d->type;
310 d->list = other.d->list;
311 d->containerItem = other.d->containerItem;
312
313 return *this;
314}
315
317{
318 d->list.clear();
321
322 if (other.isEmpty()) return *this;
323
326
327 d->type = (*it).type();
328
329 TQCString elementSignature;
331 {
332 d->containerItem = other[0]; // would be nice to get an empty one
333
334 elementSignature = d->containerItem.buildDBusSignature();
335 }
336
337 for (++it; it != endIt; ++it)
338 {
339 if (d->type != (*it).type())
340 {
343
344 return *this;
345 }
346 else if (hasContainerItemType())
347 {
348 if ((*it).buildDBusSignature() != elementSignature)
349 {
352
353 return *this;
354 }
355 }
356 }
357
358 d->list = other;
359
360 return *this;
361}
362
364{
365 d->list.clear();
368
369 TQStringList::const_iterator it = other.begin();
370 TQStringList::const_iterator endIt = other.end();
371 for (; it != endIt; ++it)
372 {
374 }
375
376 return *this;
377}
378
380{
381 return d->type;
382}
383
385{
388}
389
391{
392 return d->containerItem;
393}
394
396{
397 return d->list.isEmpty();
398}
399
401{
402 return d->list.count();
403}
404
406{
407 if (&other == this) return true;
408 if (d == other.d) return true;
409
410 bool containerEqual = true;
412 {
413 if (other.hasContainerItemType())
414 {
415 containerEqual = d->containerItem.buildDBusSignature() ==
417 }
418 else
419 containerEqual = false;
420 }
421 else if (other.hasContainerItemType())
422 containerEqual = false;
423
424 return d->type == other.d->type && containerEqual && d->list == other.d->list;
425}
426
428{
429 if (&other == this) return false;
430 if (d == other.d) return false;
431
432 bool containerEqual = true;
434 {
435 if (other.hasContainerItemType())
436 {
437 containerEqual = d->containerItem.buildDBusSignature() ==
439 }
440 else
441 containerEqual = false;
442 }
443 else if (other.hasContainerItemType())
444 containerEqual = false;
445
446 return d->type != other.d->type || !containerEqual || d->list != other.d->list;
447}
448
450{
451 d->list.clear();
452}
453
455{
456 if (data.type() == TQT_DBusData::Invalid) return *this;
457
459 {
460 d->type = data.type();
461
462 // check if we are now have container items
463 if (hasContainerItemType()) d->containerItem = data;
464
465 d->list << data;
466 }
467 else if (d->type != data.type())
468 {
469 tqWarning("TQT_DBusDataList: trying to add data of type %s to list of type %s",
471 }
472 else if (hasContainerItemType())
473 {
474 TQCString ourSignature = d->containerItem.buildDBusSignature();
475 TQCString dataSignature = data.buildDBusSignature();
476
477 if (ourSignature != dataSignature)
478 {
479 tqWarning("TQT_DBusDataList: trying to add data with signature %s "
480 "to list with item signature %s",
481 dataSignature.data(), ourSignature.data());
482 }
483 else
484 d->list << data;
485 }
486 else
487 d->list << data;
488
489 return *this;
490}
491
493{
494 return d->list;
495}
496
497TQStringList TQT_DBusDataList::toTQStringList(bool* ok) const
498{
500 {
501 if (ok != 0) *ok = false;
502 return TQStringList();
503 }
504
505 TQStringList result;
506
509 for (; it != endIt; ++it)
510 {
511 result << (*it).toString();
512 }
513
514 if (ok != 0) *ok = true;
515
516 return result;
517}
518
520{
521 if (d->type != TQT_DBusData::Bool)
522 {
523 if (ok != 0) *ok = false;
524 return TQValueList<bool>();
525 }
526
527 TQValueList<bool> result;
528
531 for (; it != endIt; ++it)
532 {
533 result << (*it).toBool();
534 }
535
536 if (ok != 0) *ok = true;
537
538 return result;
539}
540
542{
543 if (d->type != TQT_DBusData::Byte)
544 {
545 if (ok != 0) *ok = false;
546 return TQValueList<TQ_UINT8>();
547 }
548
550
553 for (; it != endIt; ++it)
554 {
555 result << (*it).toByte();
556 }
557
558 if (ok != 0) *ok = true;
559
560 return result;
561}
562
564{
565 if (d->type != TQT_DBusData::Int16)
566 {
567 if (ok != 0) *ok = false;
568 return TQValueList<TQ_INT16>();
569 }
570
572
575 for (; it != endIt; ++it)
576 {
577 result << (*it).toInt16();
578 }
579
580 if (ok != 0) *ok = true;
581
582 return result;
583}
584
586{
588 {
589 if (ok != 0) *ok = false;
590 return TQValueList<TQ_UINT16>();
591 }
592
594
597 for (; it != endIt; ++it)
598 {
599 result << (*it).toUInt16();
600 }
601
602 if (ok != 0) *ok = true;
603
604 return result;
605}
606
608{
609 if (d->type != TQT_DBusData::Int32)
610 {
611 if (ok != 0) *ok = false;
612 return TQValueList<TQ_INT32>();
613 }
614
616
619 for (; it != endIt; ++it)
620 {
621 result << (*it).toInt32();
622 }
623
624 if (ok != 0) *ok = true;
625
626 return result;
627}
628
630{
632 {
633 if (ok != 0) *ok = false;
634 return TQValueList<TQ_UINT32>();
635 }
636
638
641 for (; it != endIt; ++it)
642 {
643 result << (*it).toUInt32();
644 }
645
646 if (ok != 0) *ok = true;
647
648 return result;
649}
650
652{
653 if (d->type != TQT_DBusData::Int64)
654 {
655 if (ok != 0) *ok = false;
656 return TQValueList<TQ_INT64>();
657 }
658
660
663 for (; it != endIt; ++it)
664 {
665 result << (*it).toInt64();
666 }
667
668 if (ok != 0) *ok = true;
669
670 return result;
671}
672
674{
676 {
677 if (ok != 0) *ok = false;
678 return TQValueList<TQ_UINT64>();
679 }
680
682
685 for (; it != endIt; ++it)
686 {
687 result << (*it).toUInt64();
688 }
689
690 if (ok != 0) *ok = true;
691
692 return result;
693}
694
696{
698 {
699 if (ok != 0) *ok = false;
700 return TQValueList<double>();
701 }
702
703 TQValueList<double> result;
704
707 for (; it != endIt; ++it)
708 {
709 result << (*it).toDouble();
710 }
711
712 if (ok != 0) *ok = true;
713
714 return result;
715}
716
718{
719 return toTQStringList(ok);
720}
721
723{
725 {
726 if (ok != 0) *ok = false;
728 }
729
731
734 for (; it != endIt; ++it)
735 {
736 result << (*it).toObjectPath();
737 }
738
739 if (ok != 0) *ok = true;
740
741 return result;
742}
743
745{
747 {
748 if (ok != 0) *ok = false;
750 }
751
753
756 for (; it != endIt; ++it)
757 {
758 result << (*it).toUnixFd();
759 }
760
761 if (ok != 0) *ok = true;
762
763 return result;
764}
765
767{
769 {
770 if (ok != 0) *ok = false;
772 }
773
775
778 for (; it != endIt; ++it)
779 {
780 result << (*it).toVariant();
781 }
782
783 if (ok != 0) *ok = true;
784
785 return result;
786}
Class for accurately representing D-Bus data types.
Definition: tqdbusdata.h:59
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 fromByte(TQ_UINT8 value)
Creates a data object for the given byte (unsigned char) value.
Definition: tqdbusdata.cpp:378
const char * typeName() const
Returns the string representation of the object's Type.
Definition: tqdbusdata.h:385
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
TQCString buildDBusSignature() const
Creates the data objects D-Bus signature.
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
Type
Enum for the data types used in D-Bus messages.
Definition: tqdbusdata.h:74
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
TQT_DBusData::Type type
TQValueList< TQT_DBusData > list
Class to transport lists of D-Bus data types.
void clear()
Clears the list.
TQT_DBusDataList()
Creates an empty and invalid list.
TQValueList< TQT_DBusData > toTQValueList() const
Converts the list object into a TQValueList with TQT_DBusData elements.
TQValueList< TQ_UINT64 > toUInt64List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_UINT64.
TQValueList< TQT_DBusObjectPath > toObjectPathList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of object paths.
TQT_DBusDataList & operator=(const TQT_DBusDataList &other)
Copies from the given other list.
TQT_DBusData containerItemType() const
Returns a container prototype for the list's element type.
TQValueList< TQ_INT64 > toInt64List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_INT64.
TQValueList< double > toDoubleList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of double.
bool hasContainerItemType() const
Checks whether the element type is a data container itself.
TQValueList< TQT_DBusVariant > toVariantList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQT_DBusVariant.
TQStringList toTQStringList(bool *ok=0) const
Tries to get the list object's elements as a TQStringList.
TQValueList< TQ_UINT8 > toByteList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_UINT8.
bool operator!=(const TQT_DBusDataList &other) const
Checks whether the given other list is different from this one.
TQValueList< TQ_UINT32 > toUInt32List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_UINT32.
TQT_DBusData::Type type() const
Returns the element type of the list object.
~TQT_DBusDataList()
Destroys the list object.
bool operator==(const TQT_DBusDataList &other) const
Checks whether the given other list is equal to this one.
bool isEmpty() const
Checks whether this list object has any elements.
TQValueList< TQT_DBusUnixFd > toUnixFdList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQT_DBusUnixFd.
TQValueList< TQString > toStringList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQString.
uint count() const
Returns the number of elements of this list object.
TQValueList< TQ_UINT16 > toUInt16List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_UINT16.
TQValueList< bool > toBoolList(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of bool.
TQValueList< TQ_INT32 > toInt32List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_INT32.
TQT_DBusDataList & operator<<(const TQT_DBusData &data)
Appends a given value to the list.
TQValueList< TQ_INT16 > toInt16List(bool *ok=0) const
Tries to get the list object's elements as a TQValueList of TQ_INT16.