source: vendor/trolltech/current/src/tools/qucom.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 14.1 KB
Line 
1/****************************************************************************
2** $Id: qucom.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of the QUcom classes
5**
6** Created : 990101
7**
8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
9**
10** This file is part of the tools module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qucom_p.h"
39
40// Standard types
41
42// {DE56510E-4E9F-4b76-A3C2-D1E2EF42F1AC}
43const QUuid TID_QUType_Null( 0xde56510e, 0x4e9f, 0x4b76, 0xa3, 0xc2, 0xd1, 0xe2, 0xef, 0x42, 0xf1, 0xac );
44const QUuid *QUType_Null::uuid() const { return &TID_QUType_Null; }
45const char *QUType_Null::desc() const { return "null"; }
46bool QUType_Null::canConvertFrom( QUObject *, QUType * ) { return FALSE; }
47bool QUType_Null::canConvertTo( QUObject *, QUType * ) { return FALSE; }
48bool QUType_Null::convertFrom( QUObject *, QUType * ) { return FALSE; }
49bool QUType_Null::convertTo( QUObject *, QUType * ) { return FALSE; }
50void QUType_Null::clear( QUObject *) {};
51int QUType_Null::serializeTo( QUObject *, QUBuffer * ) { return 0; }
52int QUType_Null::serializeFrom( QUObject *, QUBuffer * ) { return 0; };
53QUType_Null static_QUType_Null;
54
55
56// {7EE17B08-5419-47e2-9776-8EEA112DCAEC}
57const QUuid TID_QUType_enum( 0x7ee17b08, 0x5419, 0x47e2, 0x97, 0x76, 0x8e, 0xea, 0x11, 0x2d, 0xca, 0xec );
58QUType_enum static_QUType_enum;
59const QUuid *QUType_enum::uuid() const { return &TID_QUType_enum; }
60const char *QUType_enum::desc() const { return "enum"; }
61void QUType_enum::set( QUObject *o, int v )
62{
63 o->payload.i = v;
64 o->type = this;
65}
66
67bool QUType_enum::canConvertFrom( QUObject *o, QUType *t )
68{
69 if ( isEqual( t, &static_QUType_int ) ) // ## todo unsigned int?
70 return TRUE;
71
72 return t->canConvertTo( o, this );
73}
74
75bool QUType_enum::canConvertTo( QUObject * /*o*/, QUType *t )
76{
77 return isEqual( t, &static_QUType_int );
78}
79
80bool QUType_enum::convertFrom( QUObject *o, QUType *t )
81{
82 if ( isEqual( t, &static_QUType_int ) ) // ## todo unsigned int?
83 ;
84 else
85 return t->convertTo( o, this );
86
87 o->type = this;
88 return TRUE;
89}
90
91bool QUType_enum::convertTo( QUObject *o, QUType *t )
92{
93 if ( isEqual( t, &static_QUType_int ) ) {
94 o->type = &static_QUType_int;
95 return TRUE;
96 }
97 return FALSE;
98}
99
100int QUType_enum::serializeTo( QUObject *, QUBuffer * )
101{
102 return 0;
103}
104
105int QUType_enum::serializeFrom( QUObject *, QUBuffer * )
106{
107 return 0;
108}
109
110// {8AC26448-5AB4-49eb-968C-8F30AB13D732}
111const QUuid TID_QUType_ptr( 0x8ac26448, 0x5ab4, 0x49eb, 0x96, 0x8c, 0x8f, 0x30, 0xab, 0x13, 0xd7, 0x32 );
112QUType_ptr static_QUType_ptr;
113const QUuid *QUType_ptr::uuid() const { return &TID_QUType_ptr; }
114const char *QUType_ptr::desc() const { return "ptr"; }
115
116void QUType_ptr::set( QUObject *o, const void* v )
117{
118 o->payload.ptr = (void*) v;
119 o->type = this;
120}
121
122bool QUType_ptr::canConvertFrom( QUObject *o, QUType *t )
123{
124 return t->canConvertTo( o, this );
125}
126
127bool QUType_ptr::canConvertTo( QUObject *, QUType * )
128{
129 return FALSE;
130}
131
132bool QUType_ptr::convertFrom( QUObject *o, QUType *t )
133{
134 return t->convertTo( o, this );
135}
136
137bool QUType_ptr::convertTo( QUObject *, QUType * )
138{
139 return FALSE;
140}
141
142int QUType_ptr::serializeTo( QUObject *, QUBuffer * )
143{
144 return 0;
145}
146
147int QUType_ptr::serializeFrom( QUObject *, QUBuffer * )
148{
149 return 0;
150}
151
152// {97A2594D-6496-4402-A11E-55AEF2D4D25C}
153const QUuid TID_QUType_iface( 0x97a2594d, 0x6496, 0x4402, 0xa1, 0x1e, 0x55, 0xae, 0xf2, 0xd4, 0xd2, 0x5c );
154QUType_iface static_QUType_iface;
155const QUuid *QUType_iface::uuid() const { return &TID_QUType_iface; }
156const char *QUType_iface::desc() const { return "UnknownInterface"; }
157
158void QUType_iface::set( QUObject *o, QUnknownInterface* iface )
159{
160 o->payload.iface = iface;
161 o->type = this;
162}
163
164bool QUType_iface::canConvertFrom( QUObject *o, QUType *t )
165{
166 return t->canConvertTo( o, this );
167}
168
169bool QUType_iface::canConvertTo( QUObject *, QUType * )
170{
171 return FALSE;
172}
173
174bool QUType_iface::convertFrom( QUObject *o, QUType *t )
175{
176 return t->convertTo( o, this );
177}
178
179bool QUType_iface::convertTo( QUObject *, QUType * )
180{
181 return FALSE;
182}
183
184int QUType_iface::serializeTo( QUObject *, QUBuffer * )
185{
186 return 0;
187}
188
189int QUType_iface::serializeFrom( QUObject *, QUBuffer * )
190{
191 return 0;
192}
193
194// {2F358164-E28F-4bf4-9FA9-4E0CDCABA50B}
195const QUuid TID_QUType_idisp( 0x2f358164, 0xe28f, 0x4bf4, 0x9f, 0xa9, 0x4e, 0xc, 0xdc, 0xab, 0xa5, 0xb );
196QUType_idisp static_QUType_idisp;
197const QUuid *QUType_idisp::uuid() const { return &TID_QUType_idisp; }
198const char *QUType_idisp::desc() const { return "DispatchInterface"; }
199
200void QUType_idisp::set( QUObject *o, QDispatchInterface* idisp )
201{
202 o->payload.idisp = idisp;
203 o->type = this;
204}
205
206bool QUType_idisp::canConvertFrom( QUObject *o, QUType *t )
207{
208 return t->canConvertTo( o, this );
209}
210
211bool QUType_idisp::canConvertTo( QUObject * /*o*/, QUType *t )
212{
213 return isEqual( t, &static_QUType_iface );
214}
215
216bool QUType_idisp::convertFrom( QUObject *o, QUType *t )
217{
218 return t->convertTo( o, this );
219}
220
221bool QUType_idisp::convertTo( QUObject *o, QUType *t )
222{
223#ifndef QT_NO_COMPONENT
224 if ( isEqual( t, &static_QUType_iface ) ) {
225 o->payload.iface = (QUnknownInterface*)o->payload.idisp;
226 o->type = &static_QUType_iface;
227 return TRUE;
228 }
229#endif
230 return FALSE;
231}
232
233int QUType_idisp::serializeTo( QUObject *, QUBuffer * )
234{
235 return 0;
236}
237
238int QUType_idisp::serializeFrom( QUObject *, QUBuffer * )
239{
240 return 0;
241}
242
243// {CA42115D-13D0-456c-82B5-FC10187F313E}
244const QUuid TID_QUType_bool( 0xca42115d, 0x13d0, 0x456c, 0x82, 0xb5, 0xfc, 0x10, 0x18, 0x7f, 0x31, 0x3e );
245QUType_bool static_QUType_bool;
246const QUuid *QUType_bool::uuid() const { return &TID_QUType_bool; }
247const char *QUType_bool::desc() const { return "bool"; }
248
249void QUType_bool::set( QUObject *o, bool v )
250{
251 o->payload.b = v;
252 o->type = this;
253}
254
255bool QUType_bool::canConvertFrom( QUObject *o, QUType *t )
256{
257 return t->canConvertTo( o, this );
258}
259
260bool QUType_bool::canConvertTo( QUObject *, QUType * )
261{
262 return FALSE;
263}
264
265bool QUType_bool::convertFrom( QUObject *o, QUType *t )
266{
267 return t->convertTo( o, this );
268}
269
270bool QUType_bool::convertTo( QUObject *, QUType * )
271{
272 return FALSE;
273}
274
275int QUType_bool::serializeTo( QUObject *, QUBuffer * )
276{
277 return 0;
278}
279
280int QUType_bool::serializeFrom( QUObject *, QUBuffer * )
281{
282 return 0;
283}
284
285// {53C1F3BE-73C3-4c7d-9E05-CCF09EB676B5}
286const QUuid TID_QUType_int( 0x53c1f3be, 0x73c3, 0x4c7d, 0x9e, 0x5, 0xcc, 0xf0, 0x9e, 0xb6, 0x76, 0xb5 );
287QUType_int static_QUType_int;
288const QUuid *QUType_int::uuid() const { return &TID_QUType_int; }
289const char *QUType_int::desc() const { return "int"; }
290
291void QUType_int::set( QUObject *o, int v )
292{
293 o->payload.i = v;
294 o->type = this;
295}
296
297bool QUType_int::canConvertFrom( QUObject *o, QUType *t )
298{
299 if ( isEqual( t, &static_QUType_double ) )
300 return TRUE;
301
302 return t->canConvertTo( o, this );
303}
304
305bool QUType_int::canConvertTo( QUObject * /*o*/, QUType *t )
306{
307 return isEqual( t, &static_QUType_double );
308}
309
310bool QUType_int::convertFrom( QUObject *o, QUType *t )
311{
312 if ( isEqual( t, &static_QUType_double ) )
313 o->payload.i = (long)o->payload.d;
314 else
315 return t->convertTo( o, this );
316
317 o->type = this;
318 return TRUE;
319}
320
321bool QUType_int::convertTo( QUObject *o, QUType *t )
322{
323 if ( isEqual( t, &static_QUType_double ) ) {
324 o->payload.d = (double)o->payload.i;
325 o->type = &static_QUType_double;
326 } else
327 return FALSE;
328 return TRUE;
329}
330
331int QUType_int::serializeTo( QUObject *, QUBuffer * )
332{
333 return 0;
334}
335
336int QUType_int::serializeFrom( QUObject *, QUBuffer * )
337{
338 return 0;
339}
340
341// {2D0974E5-0BA6-4ec2-8837-C198972CB48C}
342const QUuid TID_QUType_double( 0x2d0974e5, 0xba6, 0x4ec2, 0x88, 0x37, 0xc1, 0x98, 0x97, 0x2c, 0xb4, 0x8c );
343QUType_double static_QUType_double;
344const QUuid *QUType_double::uuid() const { return &TID_QUType_double; }
345const char *QUType_double::desc() const {return "double"; }
346
347void QUType_double::set( QUObject *o, double v )
348{
349 o->payload.d = v;
350 o->type = this;
351}
352
353bool QUType_double::canConvertFrom( QUObject *o, QUType *t )
354{
355 if ( isEqual( t, &static_QUType_int ) )
356 return TRUE;
357
358 return t->canConvertTo( o, this );
359}
360
361bool QUType_double::canConvertTo( QUObject * /*o*/, QUType *t )
362{
363 return isEqual( t, &static_QUType_int );
364}
365
366bool QUType_double::convertFrom( QUObject *o, QUType *t )
367{
368 if ( isEqual( t, &static_QUType_int ) )
369 o->payload.d = (double)o->payload.i;
370 else
371 return t->convertTo( o, this );
372
373 o->type = this;
374 return TRUE;
375}
376
377bool QUType_double::convertTo( QUObject *o, QUType *t )
378{
379 if ( isEqual( t, &static_QUType_int ) ) {
380 o->payload.i = (int) o->payload.d;
381 o->type = &static_QUType_int;
382 } else if ( isEqual( t, &static_QUType_double ) ) {
383 o->payload.d = (double) o->payload.f;
384 o->type = &static_QUType_double;
385 } else
386 return FALSE;
387 return TRUE;
388}
389
390int QUType_double::serializeTo( QUObject *, QUBuffer * )
391{
392 return 0;
393}
394
395int QUType_double::serializeFrom( QUObject *, QUBuffer * )
396{
397 return 0;
398}
399
400// {EFCDD1D4-77A3-4b8e-8D46-DC14B8D393E9}
401const QUuid TID_QUType_charstar( 0xefcdd1d4, 0x77a3, 0x4b8e, 0x8d, 0x46, 0xdc, 0x14, 0xb8, 0xd3, 0x93, 0xe9 );
402QUType_charstar static_QUType_charstar;
403const QUuid *QUType_charstar::uuid() const { return &TID_QUType_charstar; }
404const char *QUType_charstar::desc() const { return "char*"; }
405
406void QUType_charstar::set( QUObject *o, const char* v, bool take )
407{
408 if ( take ) {
409 if ( v ) {
410 o->payload.charstar.ptr = new char[ strlen(v) + 1 ];
411 strcpy( o->payload.charstar.ptr, v );
412 } else {
413 o->payload.charstar.ptr = 0;
414 }
415 o->payload.charstar.owner = TRUE;
416 } else {
417 o->payload.charstar.ptr = (char*) v;
418 o->payload.charstar.owner = FALSE;
419 }
420 o->type = this;
421}
422
423bool QUType_charstar::canConvertFrom( QUObject *o, QUType *t )
424{
425 return t->canConvertTo( o, this );
426}
427
428bool QUType_charstar::canConvertTo( QUObject *, QUType * )
429{
430 return FALSE;
431}
432
433bool QUType_charstar::convertFrom( QUObject *o, QUType *t )
434{
435 return t->convertTo( o, this );
436}
437
438bool QUType_charstar::convertTo( QUObject *, QUType * )
439{
440 return FALSE;
441}
442
443void QUType_charstar::clear( QUObject *o )
444{
445 if ( o->payload.charstar.owner )
446 delete [] o->payload.charstar.ptr;
447 o->payload.charstar.ptr = 0;
448}
449
450int QUType_charstar::serializeTo( QUObject *, QUBuffer * )
451{
452 return 0;
453}
454
455int QUType_charstar::serializeFrom( QUObject *, QUBuffer * )
456{
457 return 0;
458}
459
460
461// Qt specific types
462
463// {44C2A547-01E7-4e56-8559-35AF9D2F42B7}
464const QUuid TID_QUType_QString( 0x44c2a547, 0x1e7, 0x4e56, 0x85, 0x59, 0x35, 0xaf, 0x9d, 0x2f, 0x42, 0xb7 );
465QUType_QString static_QUType_QString;
466const QUuid *QUType_QString::uuid() const { return &TID_QUType_QString; }
467const char *QUType_QString::desc() const { return "QString"; }
468
469void QUType_QString::set( QUObject *o, const QString& v )
470{
471 o->payload.ptr = new QString( v );
472 o->type = this;
473}
474
475bool QUType_QString::canConvertFrom( QUObject *o, QUType *t )
476{
477 if ( isEqual( t, &static_QUType_charstar ) ||
478 isEqual( t, &static_QUType_double ) ||
479 isEqual( t, &static_QUType_int ) )
480 return TRUE;
481
482 return t->canConvertTo( o, this );
483}
484
485bool QUType_QString::canConvertTo( QUObject * /*o*/, QUType *t )
486{
487 return isEqual( t, &static_QUType_charstar ) ||
488 isEqual( t, &static_QUType_int ) ||
489 isEqual( t, &static_QUType_double );
490}
491
492bool QUType_QString::convertFrom( QUObject *o, QUType *t )
493{
494 QString *str = 0;
495 if ( isEqual( t, &static_QUType_charstar ) )
496 str = new QString( o->payload.charstar.ptr );
497 else if ( isEqual( t, &static_QUType_double ) )
498 str = new QString( QString::number( o->payload.d ) );
499 else if ( isEqual( t, &static_QUType_int ) )
500 str = new QString( QString::number( o->payload.i ) );
501 else
502 return t->convertTo( o, this );
503
504 o->type->clear( o );
505 o->payload.ptr = str;
506 o->type = this;
507 return TRUE;
508}
509
510bool QUType_QString::convertTo( QUObject *o, QUType *t )
511{
512 QString *str = (QString *)o->payload.ptr;
513 if ( isEqual( t, &static_QUType_charstar ) ) {
514 o->payload.charstar.ptr = qstrdup( str->local8Bit().data() );
515 o->payload.charstar.owner = TRUE;
516 o->type = &static_QUType_charstar;
517 } else if ( isEqual( t, &static_QUType_int ) ) {
518 o->payload.l = str->toLong();
519 o->type = &static_QUType_int;
520 } else if ( isEqual( t, &static_QUType_double ) ) {
521 o->payload.d = str->toDouble();
522 o->type = &static_QUType_double;
523 } else {
524 return FALSE;
525 }
526 delete str;
527 return TRUE;
528}
529
530int QUType_QString::serializeTo( QUObject *, QUBuffer * )
531{
532 return 0;
533}
534
535int QUType_QString::serializeFrom( QUObject *, QUBuffer * )
536{
537 return 0;
538}
539
540void QUType_QString::clear( QUObject *o )
541{
542 delete (QString*)o->payload.ptr;
543 o->payload.ptr = 0;
544}
Note: See TracBrowser for help on using the repository browser.