Nut/src/nut/phrases/phrasedata.cpp

118 lines
3.0 KiB
C++
Raw Normal View History

2019-02-28 16:10:41 +08:00
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Nut 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 Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
2019-02-26 17:47:08 +08:00
#include "phrasedata.h"
NUT_BEGIN_NAMESPACE
2020-08-12 20:32:06 +08:00
PhraseData::PhraseData()
: className(""), fieldName(""), type(Field), operatorCond(NotAssign),
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false),
ref(1)
2019-02-26 17:47:08 +08:00
{ }
2020-08-12 20:32:06 +08:00
PhraseData::PhraseData(const char *className, const char *fieldName)
: className(className), fieldName(fieldName), type(Field),
operatorCond(NotAssign), left(nullptr), right(nullptr),
operand(QVariant::Invalid), isNot(false), ref(1)
2019-02-26 17:47:08 +08:00
{ }
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
2020-08-12 20:32:06 +08:00
: className(nullptr), fieldName(nullptr), type(WithoutOperand),
operatorCond(o), left(l), right(nullptr), isNot(false), ref(1)
2019-02-26 17:47:08 +08:00
{
2020-08-12 20:32:06 +08:00
l->ref.ref();
2019-02-26 17:47:08 +08:00
}
2020-08-12 20:32:06 +08:00
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, PhraseData *r)
: className(nullptr), fieldName(nullptr), type(WithOther), operatorCond(o),
left(l), right(r), isNot(false), ref(1)
2019-02-26 17:47:08 +08:00
{
2020-08-12 20:32:06 +08:00
l->ref.ref();
r->ref.ref();
2019-02-26 17:47:08 +08:00
}
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
2020-08-12 20:32:06 +08:00
: className(nullptr), fieldName(nullptr), type(WithVariant),
operatorCond(o), left(l), right(nullptr), operand(r), isNot(false),
ref(1)
2019-02-26 17:47:08 +08:00
{ }
2020-08-12 20:32:06 +08:00
PhraseData::~PhraseData()
{
// if (left && !left->ref.deref())
// delete left;
// if (right && !right->ref.deref())
// delete right;
}
2019-02-26 17:47:08 +08:00
PhraseData *PhraseData::operator =(PhraseData *other)
{
2020-08-12 20:32:06 +08:00
other->ref.ref();
2019-02-26 17:47:08 +08:00
return other;
}
PhraseData &PhraseData::operator =(PhraseData &other)
{
2020-08-12 20:32:06 +08:00
other.ref.ref();
2019-02-26 17:47:08 +08:00
return other;
}
QString PhraseData::toString() const
{
2020-07-30 23:05:11 +08:00
return QStringLiteral("[%1].%2")
.arg(QString::fromUtf8(className), QString::fromUtf8(fieldName));
2019-02-26 17:47:08 +08:00
}
void PhraseData::cleanUp()
{
}
2020-08-12 20:32:06 +08:00
PhraseData *PhraseData::clone() const
{
auto c = new PhraseData;
c->className = className;
c->fieldName = fieldName;
c->type = type;
c->operatorCond = operatorCond;
c->left = left;
c->right = right;
c->operand = operand;
c->isNot = isNot;
// c->parents = parents;
return c;
}
2019-02-26 17:47:08 +08:00
void PhraseData::cleanUp(PhraseData *d)
{
if (d->left)
cleanUp(d->left);
if (d->right)
cleanUp(d->right);
}
NUT_END_NAMESPACE