plasma-framework/private/qtjolie-branch/qtjolie/value.cpp
Kevin Ottens 177be5f6af I really wonder what I had in mind when I put QStrings everywhere...
Of course SODEP says nothing about encoding so it's really byte arrays
that we send/receive.

MetaService being higher level I'll assume UTF8 encoding though (it's
apparently what it's using.


svn path=/branches/work/~ervin/qtjolie/; revision=975435
2009-05-30 08:44:34 +00:00

144 lines
2.6 KiB
C++

/**
* 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.
*/
#include "value.h"
#include <QtCore/QVariant>
#include "sodephelpers_p.h"
namespace Jolie
{
class ValuePrivate
{
public:
QVariant content;
QMap<QByteArray, QList<Value> > children;
};
} // namespace Jolie
using namespace Jolie;
Value::Value()
: d(new ValuePrivate)
{
}
Value::Value(const QByteArray &content)
: d(new ValuePrivate)
{
d->content = content;
}
Value::Value(qint32 content)
: d(new ValuePrivate)
{
d->content = content;
}
Value::Value(double content)
: d(new ValuePrivate)
{
d->content = content;
}
Value::Value(const Value &other)
: d(new ValuePrivate)
{
*d = *other.d;
}
Value::~Value()
{
delete d;
}
Value &Value::operator=(const Value &other)
{
*d = *other.d;
return *this;
}
QList<QByteArray> Value::childrenNames() const
{
return d->children.keys();
}
QList<Value> & Value::children(const QByteArray &name)
{
return d->children[name];
}
const QList<Value> & Value::children(const QByteArray &name) const
{
return d->children[name];
}
QByteArray Value::toByteArray() const
{
if (isByteArray()) {
return d->content.toByteArray();
} else {
return QByteArray();
}
}
qint32 Value::toInt() const
{
if (isInt()) {
return d->content.toInt();
} else {
return 0;
}
}
double Value::toDouble() const
{
if (isDouble()) {
return d->content.toDouble();
} else {
return 0.0;
}
}
bool Value::isByteArray() const
{
return d->content.type()==QVariant::ByteArray;
}
bool Value::isInt() const
{
return d->content.type()==QVariant::Int;
}
bool Value::isDouble() const
{
return d->content.type()==QVariant::Double;
}
bool Value::isValid() const
{
return isByteArray() || isInt() || isDouble();
}