lib
variant.h
00001 /*************************************************************************** 00002 * variant.h 00003 * This file is part of the KDE project 00004 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this program; see the file COPYING. 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 KROSS_API_VARIANT_H 00021 #define KROSS_API_VARIANT_H 00022 00023 #include <qstring.h> 00024 #include <qvariant.h> 00025 00026 #include "object.h" 00027 #include "value.h" 00028 #include "exception.h" 00029 00030 namespace Kross { namespace Api { 00031 00032 class List; 00033 00038 class Variant : public Value<Variant, QVariant> 00039 { 00040 friend class Value<Variant, QVariant>; 00041 public: 00042 00050 Variant(const QVariant& value); 00051 00052 inline operator bool () { return getValue().toBool(); } 00053 inline operator int () { return getValue().toInt(); } 00054 inline operator uint () { return getValue().toUInt(); } 00055 inline operator double () { return getValue().toDouble(); } 00056 inline operator const char* () { return getValue().toString().latin1(); } 00057 00058 inline operator QString () { return getValue().toString(); } 00059 inline operator const QString () { return getValue().toString(); } 00060 inline operator const QString& () { return getValue().asString(); } 00061 00062 inline operator QCString () { return getValue().toCString(); } 00063 inline operator const QCString () { return getValue().toCString(); } 00064 inline operator const QCString& () { return getValue().asCString(); } 00065 00066 inline operator QVariant () { return getValue(); } 00067 inline operator const QVariant () { return getValue(); } 00068 inline operator const QVariant& () { return getValue(); } 00069 00080 inline operator QStringList () { 00081 return toStringList(this); 00082 } 00083 inline operator QValueList<QVariant> () { 00084 return toList(this); 00085 } 00086 00090 virtual ~Variant(); 00091 00093 virtual const QString getClassName() const; 00094 00100 virtual const QString toString(); 00101 00110 static const QVariant& toVariant(Object::Ptr object); 00111 00120 static const QString toString(Object::Ptr object); 00121 00130 static int toInt(Object::Ptr object); 00131 00140 static uint toUInt(Object::Ptr object); 00141 00150 static double toDouble(Object::Ptr object); 00151 00160 static Q_LLONG toLLONG(Object::Ptr object); 00161 00170 static Q_ULLONG toULLONG(Object::Ptr object); 00171 00180 static bool toBool(Object::Ptr object); 00181 00190 static QStringList toStringList(Object::Ptr object); 00191 00200 static QValueList<QVariant> toList(Object::Ptr object); 00201 00202 }; 00203 00204 }} 00205 00206 #endif 00207