filters

aielement.h
1/* This file is part of the KDE project
2 Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef AIELEMENT_H
21#define AIELEMENT_H
22
23// #include <tqvaluelist.h>
24#include <tqvaluevector.h>
25
26class TQString;
27class TQCString;
28
33class AIElement {
34public:
35 enum Type {
36 Invalid,
37// List,
38 String,
39 Int,
40 UInt,
41 Double,
42 CString,
43 // Custom Types
44 Operator,
45 Reference,
46 ElementArray,
47 Block,
48 ByteArray,
49 Byte
50 };
51
52 AIElement();
53 ~AIElement();
54 AIElement( const AIElement& );
55 AIElement( const TQString&, Type type = String );
56 AIElement( const TQCString& );
57 AIElement( const char* );
58// AIElement( const TQValueList<AIElement>& );
59 AIElement( const TQValueVector<AIElement>&, Type type = ElementArray);
60 AIElement( int );
61 AIElement( uint );
62 AIElement( double );
63 AIElement( const TQByteArray& );
64 AIElement( uchar );
65
67 bool operator==( const AIElement& ) const;
68 bool operator!=( const AIElement& ) const;
69
70 Type type() const;
71 const char* typeName() const;
72
73 bool canCast( Type ) const;
74 bool cast( Type );
75
76 bool isValid() const;
77
78 void clear();
79
80 const TQString toString() const;
81 const TQCString toCString() const;
82 int toInt( bool * ok=0 ) const;
83 uint toUInt( bool * ok=0 ) const;
84 double toDouble( bool * ok=0 ) const;
85// const TQValueList<AIElement> toList() const;
86 const TQValueVector<AIElement> toElementArray() const;
87 const TQValueVector<AIElement> toBlock() const;
88
89 // Custom types
90 const TQString toReference() const;
91 const TQString toOperator() const;
92 const TQByteArray toByteArray() const;
93 uchar toByte( bool * ok=0 ) const;
94
95// TQValueListConstIterator<AIElement> listBegin() const;
96// TQValueListConstIterator<AIElement> listEnd() const;
97 TQString& asString();
98 TQCString& asCString();
99 int& asInt();
100 uint& asUInt();
101 double& asDouble();
102// TQValueList<AIElement>& asList();
103 TQValueVector<AIElement>& asElementArray();
104 TQValueVector<AIElement>& asBlock();
105
106 // Custom types
107 TQString& asReference();
108 TQString& asToken();
109 TQByteArray& asByteArray();
110 uchar& asByte();
111
112 static const char* typeToName( Type typ );
113 static Type nameToType( const char* name );
114
115private:
116 void detach();
117
118 class Private : public TQShared
119 {
120 public:
121 Private();
122 Private( Private* );
123 ~Private();
124
125 void clear();
126
127 Type typ;
128 union
129 {
130 uint u;
131 int i;
132 double d;
133 uchar b;
134 void *ptr;
135 } value;
136 };
137
138 Private* d;
139};
140
141inline AIElement::Type AIElement::type() const
142{
143 return d->typ;
144}
145
146inline bool AIElement::isValid() const
147{
148 return (d->typ != Invalid);
149}
150
151#endif
bool canCast(Type) const
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 & asInt()
uint & asUInt()
int toInt(bool *ok=0) const
uchar & asByte()
static const char * typeToName(Type typ)
double & asDouble()
static Type nameToType(const char *name)
const TQCString toCString() const
bool cast(Type)
Casts the aielement to the requested type.
TQValueVector< AIElement > & asElementArray()
void clear()
const char * typeName() const
bool operator!=(const AIElement &) const