filters

aielement.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef AIELEMENT_H
00021 #define AIELEMENT_H
00022 
00023 // #include <qvaluelist.h>
00024 #include <qvaluevector.h>
00025 
00026 class QString;
00027 class QCString;
00028 
00033 class AIElement {
00034 public:
00035     enum Type {
00036     Invalid,
00037 //  List,
00038     String,
00039     Int,
00040   UInt,
00041     Double,
00042     CString,
00043   // Custom Types
00044   Operator,
00045   Reference,
00046   ElementArray,
00047   Block,
00048   ByteArray,
00049   Byte
00050     };
00051 
00052     AIElement();
00053     ~AIElement();
00054     AIElement( const AIElement& );
00055     AIElement( const QString&, Type type = String );
00056     AIElement( const QCString& );
00057     AIElement( const char* );
00058 //    AIElement( const QValueList<AIElement>& );
00059     AIElement( const QValueVector<AIElement>&, Type type = ElementArray);
00060     AIElement( int );
00061     AIElement( uint );
00062     AIElement( double );
00063     AIElement( const QByteArray& );
00064     AIElement( uchar );
00065 
00066     AIElement& operator= ( const AIElement& );
00067     bool operator==( const AIElement& ) const;
00068     bool operator!=( const AIElement& ) const;
00069 
00070     Type type() const;
00071     const char* typeName() const;
00072 
00073     bool canCast( Type ) const;
00074     bool cast( Type );
00075 
00076     bool isValid() const;
00077 
00078     void clear();
00079 
00080     const QString toString() const;
00081     const QCString toCString() const;
00082     int toInt( bool * ok=0 ) const;
00083     uint toUInt( bool * ok=0 ) const;
00084     double toDouble( bool * ok=0 ) const;
00085 //    const QValueList<AIElement> toList() const;
00086     const QValueVector<AIElement> toElementArray() const;
00087     const QValueVector<AIElement> toBlock() const;
00088 
00089     // Custom types
00090     const QString toReference() const;
00091     const QString toOperator() const;
00092     const QByteArray toByteArray() const;
00093     uchar toByte( bool * ok=0 ) const;
00094 
00095 //    QValueListConstIterator<AIElement> listBegin() const;
00096 //    QValueListConstIterator<AIElement> listEnd() const;
00097     QString& asString();
00098     QCString& asCString();
00099     int& asInt();
00100     uint& asUInt();
00101     double& asDouble();
00102 //    QValueList<AIElement>& asList();
00103     QValueVector<AIElement>& asElementArray();
00104     QValueVector<AIElement>& asBlock();
00105 
00106     // Custom types
00107     QString& asReference();
00108     QString& asToken();
00109     QByteArray& asByteArray();
00110     uchar& asByte();
00111 
00112     static const char* typeToName( Type typ );
00113     static Type nameToType( const char* name );
00114 
00115 private:
00116     void detach();
00117 
00118     class Private : public QShared
00119     {
00120     public:
00121         Private();
00122         Private( Private* );
00123         ~Private();
00124 
00125         void clear();
00126 
00127         Type typ;
00128         union
00129         {
00130         uint u;
00131         int i;
00132         double d;
00133       uchar b;
00134         void *ptr;
00135         } value;
00136     };
00137 
00138     Private* d;
00139 };
00140 
00141 inline AIElement::Type AIElement::type() const
00142 {
00143     return d->typ;
00144 }
00145 
00146 inline bool AIElement::isValid() const
00147 {
00148     return (d->typ != Invalid);
00149 }
00150 
00151 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys