metaparameter.cpp
1/***************************************************************************
2 * This file is part of the KDE project
3 * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
4 * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include "metaparameter.h"
21#include "exception.h"
22#include "variable.h"
23
24#include <kdebug.h>
25
26using namespace KoMacro;
27
28namespace KoMacro {
29
34 class MetaParameter::Private
35 {
36 public:
37
43 TQString signatureargument;
44
49
54 TQVariant::Type varianttype;
55
56 };
57
58}
59
60MetaParameter::MetaParameter(const TQString& signatureargument)
61 : TDEShared()
62 , d( new Private() ) // create the private d-pointer instance.
63{
64 d->type = TypeNone;
65
66 if(! signatureargument.isNull()) {
67 setSignatureArgument( signatureargument );
68 }
69}
70
72{
73 delete d;
74}
75
77{
78 return d->type;
79}
80
81const TQString MetaParameter::typeName() const
82{
83 switch( d->type ) {
84 case TypeNone:
85 return "None";
86 case TypeVariant:
87 return "Variant";
88 case TypeObject:
89 return "Object";
90 }
91 return TQString();
92}
93
95{
96 d->type = type;
97 d->varianttype = TQVariant::Invalid;
98}
99
100TQVariant::Type MetaParameter::variantType() const
101{
102 return d->varianttype;
103}
104
105void MetaParameter::setVariantType(TQVariant::Type varianttype)
106{
107 d->type = TypeVariant;
108 d->varianttype = varianttype;
109}
110
111void MetaParameter::setSignatureArgument(const TQString& signatureargument)
112{
113 d->signatureargument = signatureargument;
114
115 TQString argument = signatureargument;
116 if(argument.startsWith("const")) {
117 argument = argument.mid(5).stripWhiteSpace();
118 }
119
120 if(argument.endsWith("&")) {
121 argument = argument.left( argument.length() - 1 ).stripWhiteSpace();
122 }
123
124 if(argument.isEmpty()) {
125 throw Exception(TQString("Empty signature argument passed."));
126 }
127 if(argument == "TQVariant") {
128 setVariantType( TQVariant::Invalid );
129 }
130
131 TQVariant::Type type = argument.isNull() ? TQVariant::Invalid : TQVariant::nameToType(argument.latin1());
132 if (type != TQVariant::Invalid) {
134 }
135 else {
137 }
138}
139
140bool MetaParameter::validVariable(TDESharedPtr<Variable> variable) const
141{
142 if( type() != variable->type() ) {
143 return false;
144 }
145 return true;
146}
Base Exception class.
Definition exception.h:35
MetaParameter(const TQString &signatureargument=TQString())
Constructor.
TQVariant::Type variantType() const
void setType(Type type)
Set the MetaParameter::Type this variable is.
Type
Possible types the MetaParameter could provide.
@ TypeObject
The MetaParameter is a TQVariant.
@ TypeVariant
None type, the MetaParameter is empty.
const TQString typeName() const
bool validVariable(TDESharedPtr< Variable > variable) const
void setVariantType(TQVariant::Type varianttype)
Set the MetaParameter::Type this variable is.