23AIElement::Private::Private()
25 typ = AIElement::Invalid;
28AIElement::Private::Private( Private* d )
32 case AIElement::Invalid:
34 case AIElement::String:
35 case AIElement::Reference:
36 case AIElement::Operator:
37 value.ptr =
new TQString( *((TQString*)d->value.ptr) );
39 case AIElement::CString:
41 value.ptr =
new TQCString( *((TQCString*)d->value.ptr) );
46 case AIElement::ElementArray:
47 value.ptr =
new TQValueVector<AIElement>( *((TQValueVector<AIElement>*)d->value.ptr) );
49 case AIElement::Block:
50 value.ptr =
new TQValueVector<AIElement>( *((TQValueVector<AIElement>*)d->value.ptr) );
52 case AIElement::ByteArray:
53 value.ptr =
new TQByteArray( *((TQByteArray*)d->value.ptr) );
61 case AIElement::Double:
74AIElement::Private::~Private()
79void AIElement::Private::clear()
83 case AIElement::String:
84 case AIElement::Operator:
85 case AIElement::Reference:
86 delete (TQString*)value.ptr;
88 case AIElement::CString:
89 delete (TQCString*)value.ptr;
94 case AIElement::ElementArray:
95 delete (TQValueVector<AIElement>*)value.ptr;
97 case AIElement::Block:
98 delete (TQValueVector<AIElement>*)value.ptr;
100 case AIElement::ByteArray:
101 delete (TQByteArray*)value.ptr;
103 case AIElement::Invalid:
105 case AIElement::UInt:
106 case AIElement::Double:
107 case AIElement::Byte:
111 typ = AIElement::Invalid;
154 d->value.ptr =
new TQString( val );
168 d->value.ptr =
new TQCString( val );
183 d->value.ptr =
new TQCString( val );
241 d->value.ptr =
new TQValueVector<AIElement>( val );
248 d->value.ptr =
new TQByteArray( val );
274void AIElement::detach()
280 d =
new Private( d );
309static const int ntypes = 11;
310static const char*
const type_map[ntypes] =
321 "TQValueVector<AIElement>",
334 return type_map[typ];
346 for (
int i = 0; i < ntypes; i++ ) {
347 if ( !qstrcmp( type_map[i], name ) )
362 if ( d->typ == CString )
363 return TQString::fromLatin1(
toCString() );
365 return TQString::number(
toInt() );
366 if ( d->typ == UInt )
367 return TQString::number(
toUInt() );
368 if ( d->typ == Double )
369 return TQString::number(
toDouble() );
370 if ( d->typ == Byte )
371 return TQString::number( toByte() );
372 if ( d->typ != String )
374 return *((TQString*)d->value.ptr);
377const TQString AIElement::toReference()
const
379 if ( d->typ != Reference )
381 return *((TQString*)d->value.ptr);
384const TQString AIElement::toOperator()
const
386 if ( d->typ != Operator )
388 return *((TQString*)d->value.ptr);
399 if ( d->typ == CString )
400 return *((TQCString*)d->value.ptr);
401 if ( d->typ == String )
402 return ((TQString*)d->value.ptr)->latin1();
403 if ( d->typ == Operator )
404 return ((TQString*)d->value.ptr)->latin1();
405 if ( d->typ == Reference )
406 return ((TQString*)d->value.ptr)->latin1();
423 if( d->typ == String )
424 return ((TQString*)d->value.ptr)->toInt( ok );
425 if ( d->typ == CString )
426 return ((TQCString*)d->value.ptr)->toInt( ok );
432 return (
int)d->value.u;
434 return (
int)d->value.b;
435 if ( d->typ == Double )
436 return (
int)d->value.d;
440uchar AIElement::toByte(
bool * ok )
const
442 if( d->typ == String )
443 return ((TQString*)d->value.ptr)->toShort( ok );
444 if ( d->typ == CString )
445 return ((TQCString*)d->value.ptr)->toShort( ok );
451 return (uchar)d->value.i;
453 return (uchar)d->value.u;
454 if ( d->typ == Double )
455 return (uchar)d->value.d;
471 if( d->typ == String )
472 return ((TQString*)d->value.ptr)->toUInt( ok );
473 if ( d->typ == CString )
474 return ((TQCString*)d->value.ptr)->toUInt( ok );
480 return (
int)d->value.u;
482 return (
int)d->value.b;
483 if ( d->typ == Double )
484 return (
int)d->value.d;
500 if( d->typ == String )
501 return ((TQString*)d->value.ptr)->toDouble( ok );
502 if ( d->typ == CString )
503 return ((TQCString*)d->value.ptr)->toDouble( ok );
506 if ( d->typ == Double )
509 return (
double)d->value.i;
510 if ( d->typ == UInt )
511 return (
double)d->value.u;
512 if ( d->typ == Byte )
513 return (
double)d->value.b;
543 if ( d->typ == ElementArray )
544 return *((TQValueVector<AIElement>*)d->value.ptr);
545 return TQValueVector<AIElement>();
548const TQValueVector<AIElement> AIElement::toBlock()
const
550 if ( d->typ == Block )
551 return *((TQValueVector<AIElement>*)d->value.ptr);
552 return TQValueVector<AIElement>();
556const TQByteArray AIElement::toByteArray()
const
558 if ( d->typ == ByteArray )
559 return *((TQByteArray*)d->value.ptr);
560 return TQByteArray();
563#define TQ_VARIANT_AS( f ) TQ##f& AIElement::as##f() { \
564 if ( d->typ != f ) *this = AIElement( to##f() ); else detach(); return *((TQ##f*)d->value.ptr);}
567TQ_VARIANT_AS(CString)
575 if ( d->typ != Int ) {
590 if ( d->typ != UInt ) {
604 if ( d->typ != Double ) {
619 if ( d->typ != Byte ) {
652 if ( d->typ != ElementArray )
654 return *((TQValueVector<AIElement>*)d->value.ptr);
657TQValueVector<AIElement>& AIElement::asBlock()
659 if ( d->typ != Block )
661 return *((TQValueVector<AIElement>*)d->value.ptr);
665TQByteArray& AIElement::asByteArray()
667 if ( d->typ != ByteArray )
669 return *((TQByteArray*)d->value.ptr);
690 if ( t == Int && ( d->typ == String || d->typ == Double || d->typ == UInt || d->typ == Byte) )
692 if ( t == UInt && ( d->typ == String || d->typ == Double || d->typ == Int || d->typ == Byte) )
694 if ( t == Double && ( d->typ == String || d->typ == Int || d->typ == UInt || d->typ == Byte) )
696 if ( t == CString && d->typ == String )
698 if ( t == String && ( d->typ == CString || d->typ == Int || d->typ == UInt || d->typ == Double || d->typ == Byte) )
725 case AIElement::ElementArray:
728 case AIElement::Block:
731 case AIElement::String:
737 case AIElement::UInt:
740 case AIElement::Double:
743 case AIElement::CString:
746 case AIElement::Byte:
749 case AIElement::ByteArray:
753 case AIElement::Invalid:
773 return v.toBlock() == toBlock();
775 return v.toByteArray() == toByteArray();
780 return v.toOperator() == toOperator();
782 return v.toReference() == toReference();
790 return v.toByte() == toByte();
803 return !( v == *this );
bool operator==(const AIElement &) const
AIElement & operator=(const AIElement &)
const TQValueVector< AIElement > toElementArray() const
double toDouble(bool *ok=0) const
uint toUInt(bool *ok=0) const
const TQString toString() const
int toInt(bool *ok=0) const
static const char * typeToName(Type typ)
static Type nameToType(const char *name)
const TQCString toCString() const
bool cast(Type)
Casts the aielement to the requested type.
TQValueVector< AIElement > & asElementArray()
const char * typeName() const
bool operator!=(const AIElement &) const