2008-11-05 19:48:16 +01:00
|
|
|
/**
|
|
|
|
* This file is part of the KDE project
|
|
|
|
* Copyright (C) 2008 Kevin Ottens <ervin@kde.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "value.h"
|
2008-11-05 19:48:16 +01:00
|
|
|
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
#include <QtCore/QVariant>
|
|
|
|
|
|
|
|
#include "sodephelpers_p.h"
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
namespace Jolie
|
|
|
|
{
|
|
|
|
|
|
|
|
class ValuePrivate
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
QVariant content;
|
2009-04-25 15:50:35 +02:00
|
|
|
QMap<QString, QList<Value> > children;
|
2008-11-05 19:48:16 +01:00
|
|
|
};
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
} // namespace Jolie
|
|
|
|
|
|
|
|
using namespace Jolie;
|
|
|
|
|
|
|
|
Value::Value()
|
|
|
|
: d(new ValuePrivate)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value::Value(const QString &content)
|
|
|
|
: d(new ValuePrivate)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
d->content = content;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value::Value(qint32 content)
|
|
|
|
: d(new ValuePrivate)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
d->content = content;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value::Value(double content)
|
|
|
|
: d(new ValuePrivate)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
d->content = content;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value::Value(const Value &other)
|
|
|
|
: d(new ValuePrivate)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
*d = *other.d;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value::~Value()
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Value &Value::operator=(const Value &other)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
*d = *other.d;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QStringList Value::childrenNames() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->children.keys();
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QList<Value> & Value::children(const QString &name)
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->children[name];
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
const QList<Value> & Value::children(const QString &name) const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->children[name];
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QString Value::toString() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
if (isString()) {
|
|
|
|
return d->content.toString();
|
|
|
|
} else {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
qint32 Value::toInt() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
if (isInt()) {
|
|
|
|
return d->content.toInt();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
double Value::toDouble() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
if (isDouble()) {
|
|
|
|
return d->content.toDouble();
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
bool Value::isString() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->content.type()==QVariant::String;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
bool Value::isInt() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->content.type()==QVariant::Int;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
bool Value::isDouble() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return d->content.type()==QVariant::Double;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
bool Value::isValid() const
|
2008-11-05 19:48:16 +01:00
|
|
|
{
|
|
|
|
return isString() || isInt() || isDouble();
|
|
|
|
}
|
2009-04-25 15:50:35 +02:00
|
|
|
|