Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

rtkvariant.h

00001 /*<<<<<COPYRIGHT*/
00002 /*
00003  * RTK The report toolkit
00004  * Copyright (C) 2003 Francisco Santiago Capel Torres
00005 
00006  * rtkvariant.h RTK Variant like QVariant
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  */
00019 /*>>>>>COPYRIGHT*/
00020 #ifndef RTKVARIANT_H
00021 #define RTKVARIANT_H
00022 
00023 #include <qcolor.h>
00024 #include <qvariant.h>
00025 #include "rtknamespace.h"
00026 #include "rtkmoney.h"
00027 
00028 namespace RTK
00029 {
00030 
00031 
00039 class Variant
00040 {
00041 public:
00042         enum Type {
00043             Invalid,
00044             tBool,
00045             tInt,
00046                 tUInt,
00047             tDouble,
00048             tString,
00049             tDate,
00050             tTime,
00051             tDateTime,
00052             tColor,
00053             tImage,
00054             tByteArray,
00055             tMoney,
00056                 tCFunctionType, // OJO, remove
00057             tVariantRef
00058         };
00059 
00060         Variant() : mType( Invalid ) {}
00061         Variant( Variant *val );
00062         Variant( const Variant &val);
00063         Variant( bool val );
00064         Variant( int val );
00065         Variant( uint val );
00066         Variant( long val );
00067         Variant( double val );
00068         Variant( const QString &val );
00069         Variant( const char *val );
00070         Variant( const QDate &val );
00071         Variant( const QTime &val );
00072         Variant( const QDateTime &val );
00073         Variant( const QColor &val );
00074         Variant( const QImage &val );
00075         Variant( const QByteArray &val );
00076         Variant( const Money &val );
00077         Variant( const QVariant &val );
00078         ~Variant() { clear(); }
00079 
00080         bool toBool() const;
00081         int toInt ( bool * ok = 0 ) const;
00082         uint toUInt( bool * ok = 0 ) const;
00083         double toDouble( bool * ok = 0 ) const;
00084         Measure toMeasure( bool * ok = 0 ) const { return toDouble(ok); }
00085         const QString toString() const;
00086         const QDate toDate() const;
00087         const QTime toTime() const;
00088         const QDateTime toDateTime() const;
00089         const QColor toColor() const;
00090         const QImage *toImage() const;
00091         const QByteArray toByteArray() const;
00092         const Money toMoney( bool *ok = 0 ) const;
00093         const BorderStyle toBorderStyle() const { return BorderStyle(toInt()); }
00094         const AlignmentType toAlignmentType() const { return AlignmentType(toInt()); }
00095         const AdjustmentType toAdjustmentType() const { return AdjustmentType(toInt()); }
00096 
00097         Type type() const { return mType == tVariantRef ? value.pv->type() : mType; }
00098 
00099         Variant& operator+=( const Variant& );
00100         Variant& operator= ( const Variant &val );
00101         bool operator==( const Variant& ) const;
00102         bool operator!=( const Variant& ) const;
00103 
00104         const char* typeName() const;
00105         bool canCast( Type ) const;
00106 
00107         bool isValid() const { return ( mType != Invalid ); }
00108         bool isNull() const { return !isValid(); }
00109         static const char* typeToName( Type typ );
00110         static Type nameToType( const char* name );
00111         static bool isNumeric(Type type);
00112         static Type QVariantTypeToVariantType( QVariant::Type val );
00113 
00114 
00115 private:
00116         void clear();
00117         Type mType;
00118 
00119         union {
00120                 bool b;
00121                 unsigned long u;
00122                 long i;
00123                 double d;
00124                 QString *ps;
00125                 QDate *pd;
00126                 QTime *pt;
00127                 QDateTime *pdt;
00128                 QColor *pc;
00129                 QImage *pi;
00130                 QByteArray *pba;
00131                 Money *pm;
00132                 Variant *pv;
00133         } value;
00134 
00135 }; // class QVariant
00136 
00137 }; // Namespace
00138 #endif // RTKVARIANT_H
00139 

Generated on Tue Feb 22 14:44:37 2005 for RTK. Report ToolKit by  doxygen 1.3.9.1