kexi

metaparameter.cpp

00001 /***************************************************************************
00002  * This file is part of the KDE project
00003  * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
00004  * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
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 #include "metaparameter.h"
00021 #include "exception.h"
00022 #include "variable.h"
00023 
00024 #include <kdebug.h>
00025 
00026 using namespace KoMacro;
00027 
00028 namespace KoMacro {
00029 
00034     class MetaParameter::Private
00035     {
00036         public:
00037 
00043             QString signatureargument;
00044 
00048             MetaParameter::Type type;
00049 
00054             QVariant::Type varianttype;
00055 
00056     };
00057 
00058 }
00059 
00060 MetaParameter::MetaParameter(const QString& signatureargument)
00061     : KShared()
00062     , d( new Private() ) // create the private d-pointer instance.
00063 {
00064     d->type = TypeNone;
00065 
00066     if(! signatureargument.isNull()) {
00067         setSignatureArgument( signatureargument );
00068     }
00069 }
00070 
00071 MetaParameter::~MetaParameter()
00072 {
00073     delete d;
00074 }
00075 
00076 MetaParameter::Type MetaParameter::type() const
00077 {
00078     return d->type;
00079 }
00080 
00081 const QString MetaParameter::typeName() const
00082 {
00083     switch( d->type ) {
00084         case TypeNone:
00085             return "None";
00086         case TypeVariant:
00087             return "Variant";
00088         case TypeObject:
00089             return "Object";
00090     }
00091     return QString::null;
00092 }
00093 
00094 void MetaParameter::setType(MetaParameter::Type type)
00095 {
00096     d->type = type;
00097     d->varianttype = QVariant::Invalid;
00098 }
00099 
00100 QVariant::Type MetaParameter::variantType() const
00101 {
00102     return d->varianttype;
00103 }
00104 
00105 void MetaParameter::setVariantType(QVariant::Type varianttype)
00106 {
00107     d->type = TypeVariant;
00108     d->varianttype = varianttype;
00109 }
00110 
00111 void MetaParameter::setSignatureArgument(const QString& signatureargument)
00112 {
00113     d->signatureargument = signatureargument;
00114 
00115     QString argument = signatureargument;
00116     if(argument.startsWith("const")) {
00117         argument = argument.mid(5).stripWhiteSpace();
00118     }
00119 
00120     if(argument.endsWith("&")) {
00121         argument = argument.left( argument.length() - 1 ).stripWhiteSpace();
00122     }
00123 
00124     if(argument.isEmpty()) {
00125         throw Exception(QString("Empty signature argument passed."));
00126     }
00127     if(argument == "QVariant") {
00128         setVariantType( QVariant::Invalid );
00129     }
00130     
00131     QVariant::Type type = argument.isNull() ? QVariant::Invalid : QVariant::nameToType(argument.latin1());
00132     if (type != QVariant::Invalid) {
00133         setVariantType( type );
00134     }
00135     else {
00136         setType( TypeObject );
00137     }
00138 }
00139 
00140 bool MetaParameter::validVariable(KSharedPtr<Variable> variable) const
00141 {
00142     if( type() != variable->type() ) {
00143         return false;
00144     }
00145     return true;
00146 }
KDE Home | KDE Accessibility Home | Description of Access Keys