seprate file for phrases [skip ci]
This commit is contained in:
parent
6663158085
commit
058c34d023
24
nut.pri
24
nut.pri
|
|
@ -29,7 +29,17 @@ HEADERS += \
|
||||||
$$PWD/src/sqlmodel.h \
|
$$PWD/src/sqlmodel.h \
|
||||||
$$PWD/src/sqlmodel_p.h \
|
$$PWD/src/sqlmodel_p.h \
|
||||||
$$PWD/src/phrase.h \
|
$$PWD/src/phrase.h \
|
||||||
$$PWD/src/tuple.h
|
$$PWD/src/tuple.h \
|
||||||
|
$$PWD/src/phrases/conditionalphrase.h \
|
||||||
|
$$PWD/src/phrases/abstractfieldphrase.h \
|
||||||
|
$$PWD/src/phrases/fieldphrase.h \
|
||||||
|
$$PWD/src/phrases/phraselist.h \
|
||||||
|
$$PWD/src/phrases/assignmentphraselist.h \
|
||||||
|
$$PWD/src/phrases/phrasedatalist.h \
|
||||||
|
$$PWD/src/phrases/phrasedata.h \
|
||||||
|
$$PWD/src/phrases/assignmentphrase.h \
|
||||||
|
$$PWD/src/phrases/numericphrase.h \
|
||||||
|
$$PWD/src/phrases/datephrase.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/src/generators/sqlgeneratorbase.cpp \
|
$$PWD/src/generators/sqlgeneratorbase.cpp \
|
||||||
|
|
@ -50,4 +60,14 @@ SOURCES += \
|
||||||
$$PWD/src/serializableobject.cpp \
|
$$PWD/src/serializableobject.cpp \
|
||||||
$$PWD/src/sqlmodel.cpp \
|
$$PWD/src/sqlmodel.cpp \
|
||||||
$$PWD/src/phrase.cpp \
|
$$PWD/src/phrase.cpp \
|
||||||
$$PWD/src/tuple.cpp
|
$$PWD/src/tuple.cpp \
|
||||||
|
$$PWD/src/phrases/conditionalphrase.cpp \
|
||||||
|
$$PWD/src/phrases/abstractfieldphrase.cpp \
|
||||||
|
$$PWD/src/phrases/fieldphrase.cpp \
|
||||||
|
$$PWD/src/phrases/phraselist.cpp \
|
||||||
|
$$PWD/src/phrases/assignmentphraselist.cpp \
|
||||||
|
$$PWD/src/phrases/phrasedatalist.cpp \
|
||||||
|
$$PWD/src/phrases/phrasedata.cpp \
|
||||||
|
$$PWD/src/phrases/assignmentphrase.cpp \
|
||||||
|
$$PWD/src/phrases/numericphrase.cpp \
|
||||||
|
$$PWD/src/phrases/datephrase.cpp
|
||||||
|
|
|
||||||
522
src/phrase.cpp
522
src/phrase.cpp
|
|
@ -24,270 +24,9 @@
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
PhraseData::PhraseData() :
|
|
||||||
className(""), fieldName(""),
|
|
||||||
type(Field), operatorCond(NotAssign),
|
|
||||||
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false), parents(1)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
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), parents(1)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
|
|
||||||
: className(nullptr), fieldName(nullptr),
|
|
||||||
type(WithoutOperand), operatorCond(o), left(l), right(nullptr),
|
|
||||||
isNot(false), parents(1)
|
|
||||||
{
|
|
||||||
l->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
|
||||||
PhraseData *r)
|
|
||||||
: className(nullptr), fieldName(nullptr),
|
|
||||||
type(WithOther), operatorCond(o),
|
|
||||||
left(l), right(r),
|
|
||||||
isNot(false), parents(1)
|
|
||||||
{
|
|
||||||
l->parents++;
|
|
||||||
r->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
|
||||||
: className(nullptr), fieldName(nullptr),
|
|
||||||
type(WithVariant), operatorCond(o), left(l),
|
|
||||||
right(nullptr), operand(r), isNot(false), parents(1)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
PhraseData *PhraseData::operator =(PhraseData *other)
|
|
||||||
{
|
|
||||||
other->parents++;
|
|
||||||
return other;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseData &PhraseData::operator =(PhraseData &other)
|
|
||||||
{
|
|
||||||
other.parents++;
|
|
||||||
return other;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PhraseData::toString() const
|
|
||||||
{
|
|
||||||
return QString("[%1].%2").arg(className, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhraseData::cleanUp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhraseData::cleanUp(PhraseData *d)
|
|
||||||
{
|
|
||||||
if (d->left)
|
|
||||||
cleanUp(d->left);
|
|
||||||
if (d->right)
|
|
||||||
cleanUp(d->right);
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhrase::AbstractFieldPhrase(PhraseData *d) : data(d)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
AbstractFieldPhrase::AbstractFieldPhrase(const char *className,
|
|
||||||
const char *fieldName)
|
|
||||||
:data(new PhraseData(className, fieldName))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhrase::AbstractFieldPhrase(const AbstractFieldPhrase &other)
|
|
||||||
{
|
|
||||||
data = other.data;
|
|
||||||
data->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhrase::AbstractFieldPhrase(AbstractFieldPhrase &&other)
|
|
||||||
{
|
|
||||||
data = other.data;
|
|
||||||
data->parents++;
|
|
||||||
other.data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhrase::~AbstractFieldPhrase()
|
|
||||||
{
|
|
||||||
if (data) {
|
|
||||||
--data->parents;
|
|
||||||
if (data->parents <= 0)
|
|
||||||
delete data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other)
|
|
||||||
{
|
|
||||||
return PhraseList(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase AbstractFieldPhrase::isNull()
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ConditionalPhrase AbstractFieldPhrase::operator ==(const ConditionalPhrase
|
|
||||||
&other)
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Equal,
|
|
||||||
const_cast<ConditionalPhrase&>(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
#define AbstractFieldPhraseOperatorVariant(class, op, cond) \
|
|
||||||
ConditionalPhrase class::operator op(const QVariant &other) \
|
|
||||||
{ \
|
|
||||||
return ConditionalPhrase(this, cond, other); \
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhraseOperatorVariant(AbstractFieldPhrase, ==, PhraseData::Equal)
|
|
||||||
AbstractFieldPhraseOperatorVariant(AbstractFieldPhrase, !=, PhraseData::NotEqual)
|
|
||||||
|
|
||||||
#define AbstractFieldPhraseOperatorField(op, cond) \
|
|
||||||
ConditionalPhrase AbstractFieldPhrase::operator op(const AbstractFieldPhrase &other) \
|
|
||||||
{ \
|
|
||||||
return ConditionalPhrase(this, cond, other); \
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFieldPhraseOperatorField(==, PhraseData::Equal)
|
|
||||||
AbstractFieldPhraseOperatorField(!=, PhraseData::NotEqual)
|
|
||||||
AbstractFieldPhraseOperatorField(< , PhraseData::Less)
|
|
||||||
AbstractFieldPhraseOperatorField(<=, PhraseData::LessEqual)
|
|
||||||
AbstractFieldPhraseOperatorField(> , PhraseData::Greater)
|
|
||||||
AbstractFieldPhraseOperatorField(>=, PhraseData::GreaterEqual)
|
|
||||||
|
|
||||||
AbstractFieldPhrase AbstractFieldPhrase::operator !()
|
|
||||||
{
|
|
||||||
|
|
||||||
AbstractFieldPhrase f(data->className, data->fieldName);
|
|
||||||
f.data->isNot = !data->isNot;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase AbstractFieldPhrase::operator =(const QVariant &other)
|
|
||||||
{
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase AbstractFieldPhrase::operator =(const ConditionalPhrase &other)
|
|
||||||
{
|
|
||||||
return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase AbstractFieldPhrase::operator <<(const QVariant &other)
|
|
||||||
{
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList() : isValid(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(const PhraseList &other) : isValid(true)
|
|
||||||
{
|
|
||||||
data = qMove(other.data);
|
|
||||||
const_cast<PhraseList&>(other).data.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(PhraseList &&other)
|
|
||||||
{
|
|
||||||
data = other.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
|
|
||||||
{
|
|
||||||
data.append(other.data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(const AbstractFieldPhrase *left,
|
|
||||||
const AbstractFieldPhrase &right)
|
|
||||||
: isValid(true)
|
|
||||||
{
|
|
||||||
data.append(left->data);
|
|
||||||
data.append(right.data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
|
|
||||||
{
|
|
||||||
// data = qMove(left->data + right->data);
|
|
||||||
data.append(left->data);
|
|
||||||
data.append(right->data);
|
|
||||||
// left->data.clear();
|
|
||||||
// right->data.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
|
|
||||||
: isValid(true)
|
|
||||||
{
|
|
||||||
data.append(left->data);
|
|
||||||
data.append(right->data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList &PhraseList::operator =(const PhraseList &other)
|
|
||||||
{
|
|
||||||
data.append(const_cast<PhraseList&>(other).data);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) {
|
|
||||||
return PhraseList(this, &other);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhraseList::incAllDataParents()
|
|
||||||
{
|
|
||||||
// foreach (PhraseData *d, data)
|
|
||||||
// d->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseList PhraseList::operator |(PhraseList &other) {
|
|
||||||
return PhraseList(this, &other);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase::AssignmentPhrase(PhraseData *d) : data(d)
|
|
||||||
{
|
|
||||||
d->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase::AssignmentPhrase(AbstractFieldPhrase *l, const QVariant r)
|
|
||||||
{
|
|
||||||
|
|
||||||
data = new PhraseData(l->data, PhraseData::Equal, r);
|
|
||||||
// l->data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase::AssignmentPhrase(AbstractFieldPhrase *l,
|
|
||||||
const AssignmentPhrase *r)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, PhraseData::Equal, r->data);
|
|
||||||
// l->data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *ph, const QVariant &v)
|
|
||||||
{
|
|
||||||
data = new PhraseData(ph->data, PhraseData::Equal, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
//AssignmentPhrase::AssignmentPhrase(AssignmentPhrase &other)
|
|
||||||
//{
|
|
||||||
// data = other.data;
|
|
||||||
// other.data = 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
AssignmentPhrase::~AssignmentPhrase()
|
|
||||||
{
|
|
||||||
if (data)
|
|
||||||
if (!--data->parents)
|
|
||||||
delete data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *l, const AssignmentPhrase *r)
|
//AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *l, const AssignmentPhrase *r)
|
||||||
//{
|
//{
|
||||||
|
|
@ -295,271 +34,10 @@ AssignmentPhrase::~AssignmentPhrase()
|
||||||
// qFatal("SS");
|
// qFatal("SS");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
AssignmentPhraseList AssignmentPhrase::operator &(const AssignmentPhrase &other)
|
|
||||||
{
|
|
||||||
return AssignmentPhraseList(this, &other);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList::AssignmentPhraseList(const AssignmentPhrase &l)
|
|
||||||
{
|
|
||||||
data.append(l.data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList::AssignmentPhraseList(AssignmentPhraseList *l,
|
|
||||||
const AssignmentPhrase *r)
|
|
||||||
{
|
|
||||||
data.append(l->data);
|
|
||||||
data.append(r->data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList::AssignmentPhraseList(AssignmentPhrase *l,
|
|
||||||
const AssignmentPhrase *r)
|
|
||||||
{
|
|
||||||
data.append(l->data);
|
|
||||||
data.append(r->data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList::AssignmentPhraseList(const AssignmentPhrase &r,
|
|
||||||
const AssignmentPhrase &l)
|
|
||||||
{
|
|
||||||
data.append(l.data);
|
|
||||||
data.append(r.data);
|
|
||||||
incAllDataParents();
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList AssignmentPhraseList::operator &(const AssignmentPhrase
|
|
||||||
&ph)
|
|
||||||
{
|
|
||||||
return AssignmentPhraseList(this, &ph);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhraseList::~AssignmentPhraseList()
|
|
||||||
{
|
|
||||||
foreach (PhraseData *d, data)
|
|
||||||
if (!--d->parents)
|
|
||||||
delete d;
|
|
||||||
// qDeleteAll(data);
|
|
||||||
// data.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssignmentPhraseList::incAllDataParents()
|
|
||||||
{
|
|
||||||
foreach (PhraseData *d, data)
|
|
||||||
d->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase() : data(nullptr)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
|
|
||||||
{
|
|
||||||
data = other.data;
|
|
||||||
data->parents++;
|
|
||||||
// const_cast<ConditionalPhrase&>(other).data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef Q_COMPILER_RVALUE_REFS
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &&other)
|
|
||||||
{
|
|
||||||
this->data = qMove(other.data);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
|
|
||||||
{
|
|
||||||
this->data = const_cast<PhraseData*>(data);
|
|
||||||
this->data->parents++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
|
||||||
PhraseData::Condition cond)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
const QVariant &v)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
const AbstractFieldPhrase &other)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, other.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
ConditionalPhrase &r)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, r.data);
|
|
||||||
r.data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
const AbstractFieldPhrase &r)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, r.data);
|
|
||||||
l->data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
const QVariant &r)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, r);
|
|
||||||
l->data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
|
||||||
PhraseData::Condition cond,
|
|
||||||
ConditionalPhrase &r)
|
|
||||||
{
|
|
||||||
data = new PhraseData(l->data, cond, r.data);
|
|
||||||
l->data = nullptr;
|
|
||||||
r.data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::~ConditionalPhrase()
|
|
||||||
{
|
|
||||||
if (data) {
|
|
||||||
data->cleanUp();
|
|
||||||
if (!--data->parents)
|
|
||||||
delete data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase &ConditionalPhrase::operator =(const ConditionalPhrase &other)
|
|
||||||
{
|
|
||||||
data = other.data;
|
|
||||||
data->parents++;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Equal, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
//ConditionalPhrase ConditionalPhrase::operator ==(const AbstractFieldPhrase &other)
|
|
||||||
//{
|
|
||||||
// return ConditionalPhrase(this, PhraseData::Equal, other);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//ConditionalPhrase ConditionalPhrase::operator &&(const ConditionalPhrase &other)
|
|
||||||
//{
|
|
||||||
// return ConditionalPhrase(this, PhraseData::And,
|
|
||||||
// const_cast<ConditionalPhrase&>(other));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//ConditionalPhrase ConditionalPhrase::operator ||(const ConditionalPhrase &other)
|
|
||||||
//{
|
|
||||||
// return ConditionalPhrase(this, PhraseData::Or,
|
|
||||||
// const_cast<ConditionalPhrase&>(other));
|
|
||||||
//}
|
|
||||||
|
|
||||||
#define DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(op, cond) \
|
|
||||||
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
|
||||||
const ConditionalPhrase &r) \
|
|
||||||
{ \
|
|
||||||
ConditionalPhrase p; \
|
|
||||||
p.data = new PhraseData; \
|
|
||||||
p.data->operatorCond = cond; \
|
|
||||||
p.data->left = l.data; \
|
|
||||||
p.data->right = r.data; \
|
|
||||||
l.data->parents++; \
|
|
||||||
r.data->parents++; \
|
|
||||||
return p; \
|
|
||||||
} \
|
|
||||||
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
|
||||||
ConditionalPhrase &&r) \
|
|
||||||
{ \
|
|
||||||
ConditionalPhrase p; \
|
|
||||||
p.data = new PhraseData; \
|
|
||||||
p.data->operatorCond = cond; \
|
|
||||||
p.data->left = l.data; \
|
|
||||||
p.data->right = r.data; \
|
|
||||||
l.data->parents++; \
|
|
||||||
r.data->parents++; \
|
|
||||||
return p; \
|
|
||||||
} \
|
|
||||||
ConditionalPhrase operator op(ConditionalPhrase &&l, \
|
|
||||||
const ConditionalPhrase &r) \
|
|
||||||
{ \
|
|
||||||
ConditionalPhrase p; \
|
|
||||||
p.data = new PhraseData; \
|
|
||||||
p.data->operatorCond = cond; \
|
|
||||||
p.data->left = l.data; \
|
|
||||||
p.data->right = r.data; \
|
|
||||||
l.data->parents++; \
|
|
||||||
r.data->parents++; \
|
|
||||||
return p; \
|
|
||||||
} \
|
|
||||||
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r) \
|
|
||||||
{ \
|
|
||||||
ConditionalPhrase p; \
|
|
||||||
p.data = new PhraseData; \
|
|
||||||
p.data->operatorCond = cond; \
|
|
||||||
p.data->left = l.data; \
|
|
||||||
p.data->right = r.data; \
|
|
||||||
l.data->parents++; \
|
|
||||||
r.data->parents++; \
|
|
||||||
return p; \
|
|
||||||
}
|
|
||||||
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(==, PhraseData::Equal)
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(||, PhraseData::Or)
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(&&, PhraseData::And)
|
|
||||||
|
|
||||||
ConditionalPhrase ConditionalPhrase::operator !()
|
|
||||||
{
|
|
||||||
ConditionalPhrase f(data);
|
|
||||||
f.data->isNot = !data->isNot;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseDataList::PhraseDataList() : QList<PhraseData*>()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseDataList::PhraseDataList(const PhraseDataList &other) : QList<PhraseData*>()
|
|
||||||
{
|
|
||||||
// auto &o = const_cast<PhraseDataList&>(other);
|
|
||||||
PhraseDataList::const_iterator i;
|
|
||||||
for (i = other.constBegin(); i != other.constEnd(); ++i)
|
|
||||||
append(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhraseDataList::append(PhraseData *d)
|
|
||||||
{
|
|
||||||
d->parents++;
|
|
||||||
QList<PhraseData*>::append(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhraseDataList::append(QList<PhraseData *> &dl)
|
|
||||||
{
|
|
||||||
foreach (PhraseData *d, dl)
|
|
||||||
d->parents++;
|
|
||||||
QList<PhraseData*>::append(dl);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhraseDataList::~PhraseDataList()
|
|
||||||
{
|
|
||||||
QList<PhraseData*>::iterator i;
|
|
||||||
for (i = begin(); i != end(); ++i) {
|
|
||||||
(*i)->cleanUp();
|
|
||||||
if (!--(*i)->parents)
|
|
||||||
delete *i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r)
|
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r)
|
||||||
//{
|
//{
|
||||||
|
|
|
||||||
452
src/phrase.h
452
src/phrase.h
|
|
@ -21,15 +21,16 @@
|
||||||
#ifndef PHRASE_H
|
#ifndef PHRASE_H
|
||||||
#define PHRASE_H
|
#define PHRASE_H
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include "phrases/conditionalphrase.h"
|
||||||
#include <QString>
|
#include "phrases/abstractfieldphrase.h"
|
||||||
#include <QVariant>
|
#include "phrases/fieldphrase.h"
|
||||||
#include <QtGlobal>
|
#include "phrases/phraselist.h"
|
||||||
#ifdef Q_COMPILER_INITIALIZER_LISTS
|
#include "phrases/assignmentphraselist.h"
|
||||||
# include <initializer_list>
|
#include "phrases/phrasedatalist.h"
|
||||||
#endif
|
#include "phrases/phrasedata.h"
|
||||||
|
#include "phrases/assignmentphrase.h"
|
||||||
#include "defines.h"
|
#include "phrases/numericphrase.h"
|
||||||
|
#include "phrases/datephrase.h"
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -43,432 +44,29 @@ class AbstractFieldPhrase;
|
||||||
class AssignmentPhrase;
|
class AssignmentPhrase;
|
||||||
class PhraseList;
|
class PhraseList;
|
||||||
|
|
||||||
class PhraseData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Condition {
|
|
||||||
NotAssign = 0,
|
|
||||||
Equal,
|
|
||||||
Less,
|
|
||||||
LessEqual,
|
|
||||||
Null,
|
|
||||||
In,
|
|
||||||
Like,
|
|
||||||
|
|
||||||
Not = 10,
|
|
||||||
NotEqual,
|
|
||||||
GreaterEqual,
|
|
||||||
Greater,
|
|
||||||
NotNull,
|
|
||||||
NotIn,
|
|
||||||
NotLike,
|
|
||||||
|
|
||||||
And = 20,
|
|
||||||
Or,
|
|
||||||
|
|
||||||
Add,
|
|
||||||
Minus,
|
|
||||||
Multiple,
|
|
||||||
Divide,
|
|
||||||
Mod,
|
|
||||||
|
|
||||||
Between,
|
|
||||||
|
|
||||||
//date and time
|
|
||||||
AddYears,
|
|
||||||
AddMonths,
|
|
||||||
AddDays,
|
|
||||||
AddHours,
|
|
||||||
AddMinutes,
|
|
||||||
AddSeconds
|
|
||||||
// // special types
|
|
||||||
// Distance
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Type { Field, WithVariant, WithOther, WithoutOperand };
|
|
||||||
|
|
||||||
const char *className;
|
|
||||||
const char *fieldName;
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
Condition operatorCond;
|
|
||||||
|
|
||||||
PhraseData *left;
|
|
||||||
PhraseData *right;
|
|
||||||
|
|
||||||
QVariant operand;
|
|
||||||
bool isNot;
|
|
||||||
quint16 parents;
|
|
||||||
|
|
||||||
PhraseData();
|
|
||||||
PhraseData(const char *className, const char *fieldName);
|
|
||||||
PhraseData(PhraseData *l, Condition o);
|
|
||||||
PhraseData(PhraseData *l, Condition o, PhraseData *r);
|
|
||||||
PhraseData(PhraseData *l, Condition o, QVariant r);
|
|
||||||
// explicit PhraseData(const PhraseData &other);
|
|
||||||
// explicit PhraseData(const PhraseData *other);
|
|
||||||
|
|
||||||
PhraseData *operator =(PhraseData *other);
|
|
||||||
PhraseData &operator =(PhraseData &other);
|
|
||||||
|
|
||||||
QString toString() const;
|
|
||||||
|
|
||||||
~PhraseData() = default;
|
|
||||||
|
|
||||||
void cleanUp();
|
|
||||||
private:
|
|
||||||
void cleanUp(PhraseData *d);
|
|
||||||
};
|
|
||||||
|
|
||||||
class PhraseDataList : public QList<PhraseData*>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhraseDataList();
|
|
||||||
PhraseDataList(const PhraseDataList &other);
|
|
||||||
void append(PhraseData *d);
|
|
||||||
void append(QList<PhraseData*> &dl);
|
|
||||||
virtual ~PhraseDataList();
|
|
||||||
};
|
|
||||||
|
|
||||||
class AssignmentPhraseList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QList<PhraseData*> data;
|
|
||||||
explicit AssignmentPhraseList() = default;
|
|
||||||
AssignmentPhraseList(const AssignmentPhrase &l);
|
|
||||||
AssignmentPhraseList(AssignmentPhraseList *l, const AssignmentPhrase *r);
|
|
||||||
AssignmentPhraseList(AssignmentPhrase *l, const AssignmentPhrase *r);
|
|
||||||
AssignmentPhraseList(const AssignmentPhrase &r, const AssignmentPhrase &l);
|
|
||||||
|
|
||||||
AssignmentPhraseList operator &(const AssignmentPhrase &ph);
|
|
||||||
|
|
||||||
~AssignmentPhraseList();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void incAllDataParents();
|
|
||||||
};
|
|
||||||
|
|
||||||
class AssignmentPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhraseData *data;
|
|
||||||
explicit AssignmentPhrase(PhraseData *d);
|
|
||||||
explicit AssignmentPhrase(AbstractFieldPhrase *l, const QVariant r);
|
|
||||||
explicit AssignmentPhrase(AbstractFieldPhrase *l, const AssignmentPhrase *r);
|
|
||||||
explicit AssignmentPhrase(AssignmentPhrase *ph, const QVariant &v);
|
|
||||||
// explicit AssignmentPhrase(AssignmentPhrase &other);
|
|
||||||
~AssignmentPhrase();
|
|
||||||
// AssignmentPhrase(AssignmentPhrase *l, const AssignmentPhrase *r);
|
|
||||||
|
|
||||||
AssignmentPhraseList operator &(const AssignmentPhrase &other);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r);
|
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r);
|
||||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, AssignmentPhrase &&r);
|
//AssignmentPhraseList operator &(const AssignmentPhrase &l, AssignmentPhrase &&r);
|
||||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, const AssignmentPhrase &r);
|
//AssignmentPhraseList operator &(AssignmentPhrase &&l, const AssignmentPhrase &r);
|
||||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, AssignmentPhrase &&r);
|
//AssignmentPhraseList operator &(AssignmentPhrase &&l, AssignmentPhrase &&r);
|
||||||
|
|
||||||
class PhraseList{
|
|
||||||
public:
|
|
||||||
bool isValid;
|
|
||||||
PhraseDataList data;
|
|
||||||
explicit PhraseList();
|
|
||||||
PhraseList(const PhraseList &other);
|
|
||||||
PhraseList(PhraseList &&other);
|
|
||||||
PhraseList(const AbstractFieldPhrase &other);
|
|
||||||
PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right);
|
|
||||||
PhraseList(PhraseList *left, PhraseList *right);
|
|
||||||
PhraseList(PhraseList *left, const AbstractFieldPhrase *right);
|
|
||||||
virtual ~PhraseList() = default;
|
|
||||||
|
|
||||||
PhraseList &operator =(const PhraseList &other);
|
//ConditionalPhrase operator <(AbstractFieldPhrase &l, ConditionalPhrase &&other)
|
||||||
PhraseList operator |(PhraseList &other);
|
//{
|
||||||
PhraseList operator |(const AbstractFieldPhrase &other);
|
// return ConditionalPhrase(&l, PhraseData::Less, other);
|
||||||
|
//}
|
||||||
|
|
||||||
private:
|
//template<typename T>
|
||||||
void incAllDataParents();
|
//class FieldPhrase : public AbstractFieldPhrase
|
||||||
};
|
//{
|
||||||
|
//public:
|
||||||
|
// FieldPhrase(const char *className, const char *s) :
|
||||||
|
// AbstractFieldPhrase(className, s)
|
||||||
|
// {}
|
||||||
|
|
||||||
class ConditionalPhrase
|
// AssignmentPhrase operator =(const QVariant &other) {
|
||||||
{
|
// return AssignmentPhrase(this, other);
|
||||||
public:
|
// }
|
||||||
PhraseData *data;
|
//};
|
||||||
// QSharedPointer<PhraseData> leftDataPointer;
|
|
||||||
// QSharedPointer<PhraseData> rightDataPointer;
|
|
||||||
ConditionalPhrase();
|
|
||||||
ConditionalPhrase(const ConditionalPhrase &other);
|
|
||||||
#ifdef Q_COMPILER_RVALUE_REFS
|
|
||||||
ConditionalPhrase(const ConditionalPhrase &&other);
|
|
||||||
#endif
|
|
||||||
ConditionalPhrase(const PhraseData *data);
|
|
||||||
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition);
|
|
||||||
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const QVariant &v);
|
|
||||||
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const AbstractFieldPhrase &v);
|
|
||||||
ConditionalPhrase(AbstractFieldPhrase *l, PhraseData::Condition cond, ConditionalPhrase &r);
|
|
||||||
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, const AbstractFieldPhrase &r);
|
|
||||||
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, const QVariant &r);
|
|
||||||
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, ConditionalPhrase &r);
|
|
||||||
virtual ~ConditionalPhrase();
|
|
||||||
|
|
||||||
ConditionalPhrase &operator =(const ConditionalPhrase &other);
|
|
||||||
ConditionalPhrase operator ==(const QVariant &other);
|
|
||||||
// ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
|
||||||
// ConditionalPhrase operator &&(const ConditionalPhrase &other);
|
|
||||||
// ConditionalPhrase operator ||(const ConditionalPhrase &other);
|
|
||||||
ConditionalPhrase operator !();
|
|
||||||
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DECLARE_CONDITIONALPHRASE_OPERATORS(op) \
|
|
||||||
ConditionalPhrase operator op(const ConditionalPhrase &l, const ConditionalPhrase &r); \
|
|
||||||
ConditionalPhrase operator op(const ConditionalPhrase &l, ConditionalPhrase &&r); \
|
|
||||||
ConditionalPhrase operator op(ConditionalPhrase &&l, const ConditionalPhrase &r); \
|
|
||||||
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
|
||||||
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS(==)
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS(&&)
|
|
||||||
DECLARE_CONDITIONALPHRASE_OPERATORS(||)
|
|
||||||
|
|
||||||
class AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhraseData *data;
|
|
||||||
explicit AbstractFieldPhrase(PhraseData *d);
|
|
||||||
AbstractFieldPhrase(const char *className, const char *fieldName);
|
|
||||||
AbstractFieldPhrase(const AbstractFieldPhrase &other);
|
|
||||||
AbstractFieldPhrase(AbstractFieldPhrase &&other);
|
|
||||||
|
|
||||||
virtual ~AbstractFieldPhrase();
|
|
||||||
|
|
||||||
PhraseList operator |(const AbstractFieldPhrase &other);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ConditionalPhrase in(QList<T> list)
|
|
||||||
{
|
|
||||||
QVariantList vlist;
|
|
||||||
foreach (T t, list)
|
|
||||||
vlist.append(QVariant::fromValue(t));
|
|
||||||
|
|
||||||
return ConditionalPhrase(this, PhraseData::In, vlist);
|
|
||||||
}
|
|
||||||
#ifdef Q_COMPILER_INITIALIZER_LISTS
|
|
||||||
ConditionalPhrase in(std::initializer_list<int> list) {
|
|
||||||
QVariantList vlist;
|
|
||||||
std::initializer_list<int>::iterator it;
|
|
||||||
for (it = list.begin(); it != list.end(); ++it)
|
|
||||||
vlist.append(*it);
|
|
||||||
return ConditionalPhrase(this, PhraseData::In, vlist);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ConditionalPhrase isNull();
|
|
||||||
|
|
||||||
ConditionalPhrase operator ==(const QVariant &other);
|
|
||||||
ConditionalPhrase operator ==(const ConditionalPhrase &other);
|
|
||||||
//why?
|
|
||||||
ConditionalPhrase operator !=(const QVariant &other);
|
|
||||||
|
|
||||||
ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
|
||||||
ConditionalPhrase operator !=(const AbstractFieldPhrase &other);
|
|
||||||
ConditionalPhrase operator <(const AbstractFieldPhrase &other);
|
|
||||||
ConditionalPhrase operator >(const AbstractFieldPhrase &other);
|
|
||||||
ConditionalPhrase operator <=(const AbstractFieldPhrase &other);
|
|
||||||
ConditionalPhrase operator >=(const AbstractFieldPhrase &other);
|
|
||||||
|
|
||||||
AbstractFieldPhrase operator !();
|
|
||||||
AssignmentPhrase operator =(const QVariant &other);
|
|
||||||
AssignmentPhrase operator =(const ConditionalPhrase &other);
|
|
||||||
AssignmentPhrase operator <<(const QVariant &other);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class FieldPhrase : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
AssignmentPhrase operator =(const QVariant &other) {
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class FieldPhrase<QString> : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
ConditionalPhrase like(const QString &term) {
|
|
||||||
return ConditionalPhrase(this, PhraseData::Like, term);
|
|
||||||
}
|
|
||||||
|
|
||||||
AssignmentPhrase operator =(const QVariant &v) {
|
|
||||||
return AssignmentPhrase(this, v);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SPECIALIZATION_NUMERIC(type) \
|
|
||||||
template<> \
|
|
||||||
class FieldPhrase<type> : public AbstractFieldPhrase \
|
|
||||||
{ \
|
|
||||||
public: \
|
|
||||||
FieldPhrase(const char *className, const char *s) : \
|
|
||||||
AbstractFieldPhrase(className, s) \
|
|
||||||
{} \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, %, PhraseData::Mod) \
|
|
||||||
\
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, +, PhraseData::Add) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, -, PhraseData::Minus) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, *, PhraseData::Multiple) \
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, /, PhraseData::Divide) \
|
|
||||||
AssignmentPhrase operator =(const QVariant &other) { \
|
|
||||||
return AssignmentPhrase(this, other); \
|
|
||||||
} \
|
|
||||||
AssignmentPhrase operator =(const ConditionalPhrase &other) { \
|
|
||||||
return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data)); \
|
|
||||||
} \
|
|
||||||
ConditionalPhrase between(const QVariant &min, const QVariant &max) \
|
|
||||||
{ \
|
|
||||||
return ConditionalPhrase(this, PhraseData::Between, \
|
|
||||||
QVariantList() << min << max); \
|
|
||||||
} \
|
|
||||||
};
|
|
||||||
|
|
||||||
SPECIALIZATION_NUMERIC(qint8)
|
|
||||||
SPECIALIZATION_NUMERIC(qint16)
|
|
||||||
SPECIALIZATION_NUMERIC(qint32)
|
|
||||||
SPECIALIZATION_NUMERIC(qint64)
|
|
||||||
|
|
||||||
SPECIALIZATION_NUMERIC(quint8)
|
|
||||||
SPECIALIZATION_NUMERIC(quint16)
|
|
||||||
SPECIALIZATION_NUMERIC(quint32)
|
|
||||||
SPECIALIZATION_NUMERIC(quint64)
|
|
||||||
|
|
||||||
SPECIALIZATION_NUMERIC(qreal)
|
|
||||||
|
|
||||||
//Date and time
|
|
||||||
#define CONDITIONAL_VARIANT_METHOD(name, cond) \
|
|
||||||
ConditionalPhrase name(int val) \
|
|
||||||
{ \
|
|
||||||
return ConditionalPhrase(this, cond, val); \
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class FieldPhrase<bool> : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
|
|
||||||
AssignmentPhrase operator =(const bool &other) {
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldPhrase<bool> operator !()
|
|
||||||
{
|
|
||||||
FieldPhrase<bool> f(data->className, data->fieldName);
|
|
||||||
// f.data = new PhraseData(data);
|
|
||||||
f.data->isNot = !data->isNot;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator ConditionalPhrase()
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Equal, !data->isNot);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class FieldPhrase<QDate> : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
|
||||||
AssignmentPhrase operator =(const QDate &other) {
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
ConditionalPhrase between(const QDate &min, const QDate &max)
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Between,
|
|
||||||
QVariantList() << min << max);
|
|
||||||
}
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class FieldPhrase<QTime> : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
|
||||||
AssignmentPhrase operator =(const QTime &other) {
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
ConditionalPhrase between(const QTime &min, const QTime &max)
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Between,
|
|
||||||
QVariantList() << min << max);
|
|
||||||
}
|
|
||||||
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class FieldPhrase<QDateTime> : public AbstractFieldPhrase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FieldPhrase(const char *className, const char *s) :
|
|
||||||
AbstractFieldPhrase(className, s)
|
|
||||||
{}
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
|
||||||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
|
||||||
AssignmentPhrase operator =(const QDateTime &other) {
|
|
||||||
return AssignmentPhrase(this, other);
|
|
||||||
}
|
|
||||||
ConditionalPhrase between(const QDateTime &min, const QDateTime &max)
|
|
||||||
{
|
|
||||||
return ConditionalPhrase(this, PhraseData::Between,
|
|
||||||
QVariantList() << min << max);
|
|
||||||
}
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
|
|
||||||
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
|
|
||||||
CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
|
|
||||||
};
|
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
#include "abstractfieldphrase.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
AbstractFieldPhrase::AbstractFieldPhrase(PhraseData *d) : data(d)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
AbstractFieldPhrase::AbstractFieldPhrase(const char *className,
|
||||||
|
const char *fieldName)
|
||||||
|
:data(new PhraseData(className, fieldName))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFieldPhrase::AbstractFieldPhrase(const AbstractFieldPhrase &other)
|
||||||
|
{
|
||||||
|
data = other.data;
|
||||||
|
data->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFieldPhrase::AbstractFieldPhrase(AbstractFieldPhrase &&other)
|
||||||
|
{
|
||||||
|
data = other.data;
|
||||||
|
data->parents++;
|
||||||
|
other.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFieldPhrase::~AbstractFieldPhrase()
|
||||||
|
{
|
||||||
|
if (data) {
|
||||||
|
--data->parents;
|
||||||
|
if (data->parents <= 0)
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other)
|
||||||
|
{
|
||||||
|
return PhraseList(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase AbstractFieldPhrase::isNull()
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ConditionalPhrase AbstractFieldPhrase::operator ==(const ConditionalPhrase
|
||||||
|
&other)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Equal,
|
||||||
|
const_cast<ConditionalPhrase&>(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AssignmentPhrase AbstractFieldPhrase::operator =(const QVariant &other)
|
||||||
|
{
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase AbstractFieldPhrase::operator =(const ConditionalPhrase &other)
|
||||||
|
{
|
||||||
|
return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase AbstractFieldPhrase::operator <<(const QVariant &other)
|
||||||
|
{
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define AbstractFieldPhraseOperatorVariant(class, op, cond) \
|
||||||
|
ConditionalPhrase class::operator op(const QVariant &other) \
|
||||||
|
{ \
|
||||||
|
return ConditionalPhrase(this, cond, other); \
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFieldPhraseOperatorVariant(AbstractFieldPhrase, ==, PhraseData::Equal)
|
||||||
|
AbstractFieldPhraseOperatorVariant(AbstractFieldPhrase, !=, PhraseData::NotEqual)
|
||||||
|
|
||||||
|
#define AbstractFieldPhraseOperatorField(op, cond) \
|
||||||
|
ConditionalPhrase AbstractFieldPhrase::operator op(const AbstractFieldPhrase &other) \
|
||||||
|
{ \
|
||||||
|
return ConditionalPhrase(this, cond, other); \
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFieldPhraseOperatorField(==, PhraseData::Equal)
|
||||||
|
AbstractFieldPhraseOperatorField(!=, PhraseData::NotEqual)
|
||||||
|
AbstractFieldPhraseOperatorField(< , PhraseData::Less)
|
||||||
|
AbstractFieldPhraseOperatorField(<=, PhraseData::LessEqual)
|
||||||
|
AbstractFieldPhraseOperatorField(> , PhraseData::Greater)
|
||||||
|
AbstractFieldPhraseOperatorField(>=, PhraseData::GreaterEqual)
|
||||||
|
|
||||||
|
AbstractFieldPhrase AbstractFieldPhrase::operator !()
|
||||||
|
{
|
||||||
|
AbstractFieldPhrase f(data->className, data->fieldName);
|
||||||
|
f.data->isNot = !data->isNot;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
#ifndef ABSTRACTFIELDPHRASE_H
|
||||||
|
#define ABSTRACTFIELDPHRASE_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
#include "assignmentphrase.h"
|
||||||
|
#include "conditionalphrase.h"
|
||||||
|
#include "phraselist.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseData;
|
||||||
|
class AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhraseData *data;
|
||||||
|
explicit AbstractFieldPhrase(PhraseData *d);
|
||||||
|
AbstractFieldPhrase(const char *className, const char *fieldName);
|
||||||
|
AbstractFieldPhrase(const AbstractFieldPhrase &other);
|
||||||
|
AbstractFieldPhrase(AbstractFieldPhrase &&other);
|
||||||
|
|
||||||
|
virtual ~AbstractFieldPhrase();
|
||||||
|
|
||||||
|
PhraseList operator |(const AbstractFieldPhrase &other);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ConditionalPhrase in(QList<T> list)
|
||||||
|
{
|
||||||
|
QVariantList vlist;
|
||||||
|
foreach (T t, list)
|
||||||
|
vlist.append(QVariant::fromValue(t));
|
||||||
|
|
||||||
|
return ConditionalPhrase(this, PhraseData::In, vlist);
|
||||||
|
}
|
||||||
|
#ifdef Q_COMPILER_INITIALIZER_LISTS
|
||||||
|
ConditionalPhrase in(std::initializer_list<int> list) {
|
||||||
|
QVariantList vlist;
|
||||||
|
std::initializer_list<int>::iterator it;
|
||||||
|
for (it = list.begin(); it != list.end(); ++it)
|
||||||
|
vlist.append(*it);
|
||||||
|
return ConditionalPhrase(this, PhraseData::In, vlist);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ConditionalPhrase isNull();
|
||||||
|
|
||||||
|
ConditionalPhrase operator ==(const QVariant &other);
|
||||||
|
ConditionalPhrase operator ==(const ConditionalPhrase &other);
|
||||||
|
//why?
|
||||||
|
ConditionalPhrase operator !=(const QVariant &other);
|
||||||
|
|
||||||
|
ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
||||||
|
ConditionalPhrase operator !=(const AbstractFieldPhrase &other);
|
||||||
|
ConditionalPhrase operator <(const AbstractFieldPhrase &other);
|
||||||
|
ConditionalPhrase operator >(const AbstractFieldPhrase &other);
|
||||||
|
ConditionalPhrase operator <=(const AbstractFieldPhrase &other);
|
||||||
|
ConditionalPhrase operator >=(const AbstractFieldPhrase &other);
|
||||||
|
|
||||||
|
AbstractFieldPhrase operator !();
|
||||||
|
AssignmentPhrase operator =(const QVariant &other);
|
||||||
|
AssignmentPhrase operator =(const ConditionalPhrase &other);
|
||||||
|
AssignmentPhrase operator <<(const QVariant &other);
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // ABSTRACTFIELDPHRASE_H
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include "abstractfieldphrase.h"
|
||||||
|
#include "assignmentphrase.h"
|
||||||
|
#include "phrasedata.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
AssignmentPhrase::AssignmentPhrase(PhraseData *d) : data(d)
|
||||||
|
{
|
||||||
|
d->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase::AssignmentPhrase(AbstractFieldPhrase *l, const QVariant r)
|
||||||
|
{
|
||||||
|
|
||||||
|
data = new PhraseData(l->data, PhraseData::Equal, r);
|
||||||
|
// l->data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase::AssignmentPhrase(AbstractFieldPhrase *l,
|
||||||
|
const AssignmentPhrase *r)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, PhraseData::Equal, r->data);
|
||||||
|
// l->data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *ph, const QVariant &v)
|
||||||
|
{
|
||||||
|
data = new PhraseData(ph->data, PhraseData::Equal, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//AssignmentPhrase::AssignmentPhrase(AssignmentPhrase &other)
|
||||||
|
//{
|
||||||
|
// data = other.data;
|
||||||
|
// other.data = 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
AssignmentPhrase::~AssignmentPhrase()
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
if (!--data->parents)
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef ASSIGNMENTPHRASE_H
|
||||||
|
#define ASSIGNMENTPHRASE_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
#include "assignmentphraselist.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseData;
|
||||||
|
class AbstractFieldPhrase;
|
||||||
|
class AssignmentPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhraseData *data;
|
||||||
|
explicit AssignmentPhrase(PhraseData *d);
|
||||||
|
explicit AssignmentPhrase(AbstractFieldPhrase *l, const QVariant r);
|
||||||
|
explicit AssignmentPhrase(AbstractFieldPhrase *l, const AssignmentPhrase *r);
|
||||||
|
explicit AssignmentPhrase(AssignmentPhrase *ph, const QVariant &v);
|
||||||
|
// explicit AssignmentPhrase(AssignmentPhrase &other);
|
||||||
|
~AssignmentPhrase();
|
||||||
|
// AssignmentPhrase(AssignmentPhrase *l, const AssignmentPhrase *r);
|
||||||
|
|
||||||
|
AssignmentPhraseList operator &(const AssignmentPhrase &other);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // ASSIGNMENTPHRASE_H
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
#include "assignmentphraselist.h"
|
||||||
|
#include "phrasedata.h"
|
||||||
|
#include <phrase.h>
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
|
AssignmentPhraseList AssignmentPhrase::operator &(const AssignmentPhrase &other)
|
||||||
|
{
|
||||||
|
return AssignmentPhraseList(this, &other);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList::AssignmentPhraseList(const AssignmentPhrase &l)
|
||||||
|
{
|
||||||
|
data.append(l.data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList::AssignmentPhraseList(AssignmentPhraseList *l,
|
||||||
|
const AssignmentPhrase *r)
|
||||||
|
{
|
||||||
|
data.append(l->data);
|
||||||
|
data.append(r->data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList::AssignmentPhraseList(AssignmentPhrase *l,
|
||||||
|
const AssignmentPhrase *r)
|
||||||
|
{
|
||||||
|
data.append(l->data);
|
||||||
|
data.append(r->data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList::AssignmentPhraseList(const AssignmentPhrase &r,
|
||||||
|
const AssignmentPhrase &l)
|
||||||
|
{
|
||||||
|
data.append(l.data);
|
||||||
|
data.append(r.data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList AssignmentPhraseList::operator &(const AssignmentPhrase
|
||||||
|
&ph)
|
||||||
|
{
|
||||||
|
return AssignmentPhraseList(this, &ph);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhraseList::~AssignmentPhraseList()
|
||||||
|
{
|
||||||
|
foreach (PhraseData *d, data)
|
||||||
|
if (!--d->parents)
|
||||||
|
delete d;
|
||||||
|
// qDeleteAll(data);
|
||||||
|
// data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignmentPhraseList::incAllDataParents()
|
||||||
|
{
|
||||||
|
foreach (PhraseData *d, data)
|
||||||
|
d->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef ASSIGNMENTPHRASELIST_H
|
||||||
|
#define ASSIGNMENTPHRASELIST_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseData;
|
||||||
|
class AssignmentPhrase;
|
||||||
|
class AssignmentPhraseList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QList<PhraseData*> data;
|
||||||
|
explicit AssignmentPhraseList() = default;
|
||||||
|
AssignmentPhraseList(const AssignmentPhrase &l);
|
||||||
|
AssignmentPhraseList(AssignmentPhraseList *l, const AssignmentPhrase *r);
|
||||||
|
AssignmentPhraseList(AssignmentPhrase *l, const AssignmentPhrase *r);
|
||||||
|
AssignmentPhraseList(const AssignmentPhrase &r, const AssignmentPhrase &l);
|
||||||
|
|
||||||
|
AssignmentPhraseList operator &(const AssignmentPhrase &ph);
|
||||||
|
|
||||||
|
~AssignmentPhraseList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void incAllDataParents();
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // ASSIGNMENTPHRASELIST_H
|
||||||
|
|
@ -0,0 +1,221 @@
|
||||||
|
#include "abstractfieldphrase.h"
|
||||||
|
#include "conditionalphrase.h"
|
||||||
|
#include "phrasedata.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase() : data(nullptr)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
|
||||||
|
{
|
||||||
|
data = other.data;
|
||||||
|
data->parents++;
|
||||||
|
// const_cast<ConditionalPhrase&>(other).data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_COMPILER_RVALUE_REFS
|
||||||
|
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &&other)
|
||||||
|
{
|
||||||
|
this->data = qMove(other.data);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
|
||||||
|
{
|
||||||
|
this->data = const_cast<PhraseData*>(data);
|
||||||
|
this->data->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
||||||
|
PhraseData::Condition cond)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
const QVariant &v)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
const AbstractFieldPhrase &other)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, other.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
ConditionalPhrase &r)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, r.data);
|
||||||
|
r.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
const AbstractFieldPhrase &r)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, r.data);
|
||||||
|
l->data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
const QVariant &r)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, r);
|
||||||
|
l->data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase *l,
|
||||||
|
PhraseData::Condition cond,
|
||||||
|
ConditionalPhrase &r)
|
||||||
|
{
|
||||||
|
data = new PhraseData(l->data, cond, r.data);
|
||||||
|
l->data = nullptr;
|
||||||
|
r.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase::~ConditionalPhrase()
|
||||||
|
{
|
||||||
|
if (data) {
|
||||||
|
data->cleanUp();
|
||||||
|
if (!--data->parents)
|
||||||
|
delete data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase &ConditionalPhrase::operator =(const ConditionalPhrase &other)
|
||||||
|
{
|
||||||
|
data = other.data;
|
||||||
|
data->parents++;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
//ConditionalPhrase ConditionalPhrase::operator ==(const AbstractFieldPhrase &other)
|
||||||
|
//{
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//ConditionalPhrase ConditionalPhrase::operator &&(const ConditionalPhrase &other)
|
||||||
|
//{
|
||||||
|
// return ConditionalPhrase(this, PhraseData::And,
|
||||||
|
// const_cast<ConditionalPhrase&>(other));
|
||||||
|
//}
|
||||||
|
|
||||||
|
//ConditionalPhrase ConditionalPhrase::operator ||(const ConditionalPhrase &other)
|
||||||
|
//{
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Or,
|
||||||
|
// const_cast<ConditionalPhrase&>(other));
|
||||||
|
//}
|
||||||
|
|
||||||
|
#define DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(op, cond) \
|
||||||
|
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
||||||
|
const ConditionalPhrase &r) \
|
||||||
|
{ \
|
||||||
|
ConditionalPhrase p; \
|
||||||
|
p.data = new PhraseData; \
|
||||||
|
p.data->operatorCond = cond; \
|
||||||
|
p.data->left = l.data; \
|
||||||
|
p.data->right = r.data; \
|
||||||
|
l.data->parents++; \
|
||||||
|
r.data->parents++; \
|
||||||
|
return p; \
|
||||||
|
} \
|
||||||
|
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
||||||
|
ConditionalPhrase &&r) \
|
||||||
|
{ \
|
||||||
|
ConditionalPhrase p; \
|
||||||
|
p.data = new PhraseData; \
|
||||||
|
p.data->operatorCond = cond; \
|
||||||
|
p.data->left = l.data; \
|
||||||
|
p.data->right = r.data; \
|
||||||
|
l.data->parents++; \
|
||||||
|
r.data->parents++; \
|
||||||
|
return p; \
|
||||||
|
} \
|
||||||
|
ConditionalPhrase operator op(ConditionalPhrase &&l, \
|
||||||
|
const ConditionalPhrase &r) \
|
||||||
|
{ \
|
||||||
|
ConditionalPhrase p; \
|
||||||
|
p.data = new PhraseData; \
|
||||||
|
p.data->operatorCond = cond; \
|
||||||
|
p.data->left = l.data; \
|
||||||
|
p.data->right = r.data; \
|
||||||
|
l.data->parents++; \
|
||||||
|
r.data->parents++; \
|
||||||
|
return p; \
|
||||||
|
} \
|
||||||
|
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r) \
|
||||||
|
{ \
|
||||||
|
ConditionalPhrase p; \
|
||||||
|
p.data = new PhraseData; \
|
||||||
|
p.data->operatorCond = cond; \
|
||||||
|
p.data->left = l.data; \
|
||||||
|
p.data->right = r.data; \
|
||||||
|
l.data->parents++; \
|
||||||
|
r.data->parents++; \
|
||||||
|
return p; \
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(==, PhraseData::Equal)
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(||, PhraseData::Or)
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(&&, PhraseData::And)
|
||||||
|
|
||||||
|
ConditionalPhrase ConditionalPhrase::operator !()
|
||||||
|
{
|
||||||
|
ConditionalPhrase f(data);
|
||||||
|
f.data->isNot = !data->isNot;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator <(AbstractFieldPhrase &l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::Less, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator <=(AbstractFieldPhrase &l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::LessEqual, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator >(AbstractFieldPhrase &l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::Greater, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator >=(AbstractFieldPhrase &l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::GreaterEqual, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator <(ConditionalPhrase &&l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::Less, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator <=(ConditionalPhrase &&l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::LessEqual, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator >(ConditionalPhrase &&l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::Greater, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator >=(ConditionalPhrase &&l, ConditionalPhrase &&r)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(&l, PhraseData::GreaterEqual, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
#ifndef CONDITIONALPHRASE_H
|
||||||
|
#define CONDITIONALPHRASE_H
|
||||||
|
|
||||||
|
#include "phrasedata.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseData;
|
||||||
|
class AbstractFieldPhrase;
|
||||||
|
|
||||||
|
#define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \
|
||||||
|
ConditionalPhrase operator op(const QVariant &other) \
|
||||||
|
{ \
|
||||||
|
return ConditionalPhrase(this, cond, other); \
|
||||||
|
}
|
||||||
|
class ConditionalPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhraseData *data;
|
||||||
|
// QSharedPointer<PhraseData> leftDataPointer;
|
||||||
|
// QSharedPointer<PhraseData> rightDataPointer;
|
||||||
|
ConditionalPhrase();
|
||||||
|
ConditionalPhrase(const ConditionalPhrase &other);
|
||||||
|
#ifdef Q_COMPILER_RVALUE_REFS
|
||||||
|
ConditionalPhrase(const ConditionalPhrase &&other);
|
||||||
|
#endif
|
||||||
|
ConditionalPhrase(const PhraseData *data);
|
||||||
|
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition);
|
||||||
|
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const QVariant &v);
|
||||||
|
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const AbstractFieldPhrase &v);
|
||||||
|
ConditionalPhrase(AbstractFieldPhrase *l, PhraseData::Condition cond, ConditionalPhrase &r);
|
||||||
|
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, const AbstractFieldPhrase &r);
|
||||||
|
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, const QVariant &r);
|
||||||
|
ConditionalPhrase(ConditionalPhrase *l, PhraseData::Condition cond, ConditionalPhrase &r);
|
||||||
|
virtual ~ConditionalPhrase();
|
||||||
|
|
||||||
|
ConditionalPhrase &operator =(const ConditionalPhrase &other);
|
||||||
|
ConditionalPhrase operator ==(const QVariant &other);
|
||||||
|
// ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
||||||
|
// ConditionalPhrase operator &&(const ConditionalPhrase &other);
|
||||||
|
// ConditionalPhrase operator ||(const ConditionalPhrase &other);
|
||||||
|
ConditionalPhrase operator !();
|
||||||
|
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define DECLARE_CONDITIONALPHRASE_OPERATORS(op) \
|
||||||
|
ConditionalPhrase operator op(const ConditionalPhrase &l, const ConditionalPhrase &r); \
|
||||||
|
ConditionalPhrase operator op(const ConditionalPhrase &l, ConditionalPhrase &&r); \
|
||||||
|
ConditionalPhrase operator op(ConditionalPhrase &&l, const ConditionalPhrase &r); \
|
||||||
|
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||||
|
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS(==)
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS(&&)
|
||||||
|
DECLARE_CONDITIONALPHRASE_OPERATORS(||)
|
||||||
|
|
||||||
|
ConditionalPhrase operator <(AbstractFieldPhrase &l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator <=(AbstractFieldPhrase &l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator >(AbstractFieldPhrase &l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator >=(AbstractFieldPhrase &l, ConditionalPhrase &&r);
|
||||||
|
|
||||||
|
ConditionalPhrase operator <(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator <=(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator >(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||||
|
ConditionalPhrase operator >=(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||||
|
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // CONDITIONALPHRASE_H
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
#include "datephrase.h"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,151 @@
|
||||||
|
#ifndef DATEPHRASE_H
|
||||||
|
#define DATEPHRASE_H
|
||||||
|
|
||||||
|
#include "fieldphrase.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
struct __is_date_helper
|
||||||
|
: public std::false_type { };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct __is_date_helper<QTime>
|
||||||
|
: public std::true_type { };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct __is_date_helper<QDate>
|
||||||
|
: public std::true_type { };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct __is_date_helper<QDateTime>
|
||||||
|
: public std::true_type { };
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
struct is_date
|
||||||
|
: public __is_date_helper<typename std::remove_cv<_Tp>::type>::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
|
||||||
|
template <class T, class P>
|
||||||
|
inline bool is_valid_template() {return false;}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool is_valid_template<QDateTime, QTime>() {return true;}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool is_valid_template<QDateTime, QDate>() {return true;}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool is_valid_template<QDate, QDate>() {return true;}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool is_valid_template<QTime, QTime>() {return true;}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class FieldPhrase<T, typename std::enable_if<is_date<T>::value>::type>
|
||||||
|
: public AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FieldPhrase(const char *className, const char *s) :
|
||||||
|
AbstractFieldPhrase(className, s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
AssignmentPhrase operator =(const T &other) {
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase operator <(const QVariant &other) {
|
||||||
|
return ConditionalPhrase(this, PhraseData::Less, other);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator <=(const QVariant &other) {
|
||||||
|
return ConditionalPhrase(this, PhraseData::LessEqual, other);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator >(const QVariant &other) {
|
||||||
|
return ConditionalPhrase(this, PhraseData::Greater, other);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator >=(const QVariant &other) {
|
||||||
|
return ConditionalPhrase(this, PhraseData::GreaterEqual, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase between(const QVariant &min, const QVariant &max)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Between,
|
||||||
|
QVariantList() << min << max);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase addYears(int val) {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddYears, val);
|
||||||
|
}
|
||||||
|
ConditionalPhrase addMonths(int val) {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddMonths, val);
|
||||||
|
}
|
||||||
|
ConditionalPhrase addDays(int val) {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddDays, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase addHours(int val) {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddHours, val);
|
||||||
|
}
|
||||||
|
ConditionalPhrase addMinutes(int val) {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddMinutes, val);
|
||||||
|
}
|
||||||
|
ConditionalPhrase addSeconds(int val) {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::AddSeconds, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalPhrase year() {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartYear);
|
||||||
|
}
|
||||||
|
ConditionalPhrase month() {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartMonth);
|
||||||
|
}
|
||||||
|
ConditionalPhrase day() {
|
||||||
|
if (!is_valid_template<T, QDate>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartDay);
|
||||||
|
}
|
||||||
|
ConditionalPhrase hour() {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartHour);
|
||||||
|
}
|
||||||
|
ConditionalPhrase minute() {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartMinute);
|
||||||
|
}
|
||||||
|
ConditionalPhrase second() {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartSecond);
|
||||||
|
}
|
||||||
|
ConditionalPhrase msec() {
|
||||||
|
if (!is_valid_template<T, QTime>())
|
||||||
|
return ConditionalPhrase();
|
||||||
|
return ConditionalPhrase(this, PhraseData::DatePartMilisecond);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // DATEPHRASE_H
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
#include "fieldphrase.h"
|
||||||
|
|
@ -0,0 +1,204 @@
|
||||||
|
#ifndef FIELDPHRASE_H
|
||||||
|
#define FIELDPHRASE_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
#include "abstractfieldphrase.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
template<typename T, typename enable = void>
|
||||||
|
class FieldPhrase : public AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FieldPhrase(const char *className, const char *s) :
|
||||||
|
AbstractFieldPhrase(className, s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
AssignmentPhrase operator =(const QVariant &other) {
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class FieldPhrase<QString> : public AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FieldPhrase(const char *className, const char *s) :
|
||||||
|
AbstractFieldPhrase(className, s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
ConditionalPhrase like(const QString &term) {
|
||||||
|
return ConditionalPhrase(this, PhraseData::Like, term);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignmentPhrase operator =(const QVariant &v) {
|
||||||
|
return AssignmentPhrase(this, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//#define SPECIALIZATION_NUMERIC(type) \
|
||||||
|
//template<> \
|
||||||
|
//class FieldPhrase<type> : public AbstractFieldPhrase \
|
||||||
|
//{ \
|
||||||
|
// public: \
|
||||||
|
// FieldPhrase(const char *className, const char *s) : \
|
||||||
|
// AbstractFieldPhrase(className, s) \
|
||||||
|
// {} \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, %, PhraseData::Mod) \
|
||||||
|
// \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, +, PhraseData::Add) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, -, PhraseData::Minus) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, *, PhraseData::Multiple) \
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, /, PhraseData::Divide) \
|
||||||
|
// AssignmentPhrase operator =(const QVariant &other) { \
|
||||||
|
// return AssignmentPhrase(this, other); \
|
||||||
|
// } \
|
||||||
|
// AssignmentPhrase operator =(const ConditionalPhrase &other) { \
|
||||||
|
// return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data)); \
|
||||||
|
// } \
|
||||||
|
// ConditionalPhrase between(const QVariant &min, const QVariant &max) \
|
||||||
|
// { \
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Between, \
|
||||||
|
// QVariantList() << min << max); \
|
||||||
|
// } \
|
||||||
|
// ConditionalPhrase operator ++() \
|
||||||
|
// {return ConditionalPhrase(this, PhraseData::Add, 1);} \
|
||||||
|
// ConditionalPhrase operator --() \
|
||||||
|
// {return ConditionalPhrase(this, PhraseData::Minus, 1);} \
|
||||||
|
// ConditionalPhrase operator ++(int) \
|
||||||
|
// {return ConditionalPhrase(this, PhraseData::Add, 1);} \
|
||||||
|
// ConditionalPhrase operator --(int) \
|
||||||
|
// {return ConditionalPhrase(this, PhraseData::Minus, 1);} \
|
||||||
|
//};
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC(qint8)
|
||||||
|
//SPECIALIZATION_NUMERIC(qint16)
|
||||||
|
//SPECIALIZATION_NUMERIC(qint32)
|
||||||
|
//SPECIALIZATION_NUMERIC(qint64)
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC(quint8)
|
||||||
|
//SPECIALIZATION_NUMERIC(quint16)
|
||||||
|
//SPECIALIZATION_NUMERIC(quint32)
|
||||||
|
//SPECIALIZATION_NUMERIC(quint64)
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC(qreal)
|
||||||
|
|
||||||
|
//Date and time
|
||||||
|
#define CONDITIONAL_VARIANT_METHOD(name, cond) \
|
||||||
|
ConditionalPhrase name(int val) \
|
||||||
|
{ \
|
||||||
|
return ConditionalPhrase(this, cond, val); \
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class FieldPhrase<bool> : public AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FieldPhrase(const char *className, const char *s) :
|
||||||
|
AbstractFieldPhrase(className, s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
AssignmentPhrase operator =(const bool &other) {
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldPhrase<bool> operator !()
|
||||||
|
{
|
||||||
|
FieldPhrase<bool> f(data->className, data->fieldName);
|
||||||
|
// f.data = new PhraseData(data);
|
||||||
|
f.data->isNot = !data->isNot;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator ConditionalPhrase()
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Equal, !data->isNot);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//template<>
|
||||||
|
//class FieldPhrase<QDate> : public AbstractFieldPhrase
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// FieldPhrase(const char *className, const char *s) :
|
||||||
|
// AbstractFieldPhrase(className, s)
|
||||||
|
// {}
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||||
|
// AssignmentPhrase operator =(const QDate &other) {
|
||||||
|
// return AssignmentPhrase(this, other);
|
||||||
|
// }
|
||||||
|
// ConditionalPhrase between(const QDate &min, const QDate &max)
|
||||||
|
// {
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Between,
|
||||||
|
// QVariantList() << min << max);
|
||||||
|
// }
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
|
||||||
|
//};
|
||||||
|
|
||||||
|
//template<>
|
||||||
|
//class FieldPhrase<QTime> : public AbstractFieldPhrase
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// FieldPhrase(const char *className, const char *s) :
|
||||||
|
// AbstractFieldPhrase(className, s)
|
||||||
|
// {}
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||||
|
// AssignmentPhrase operator =(const QTime &other) {
|
||||||
|
// return AssignmentPhrase(this, other);
|
||||||
|
// }
|
||||||
|
// ConditionalPhrase between(const QTime &min, const QTime &max)
|
||||||
|
// {
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Between,
|
||||||
|
// QVariantList() << min << max);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
|
||||||
|
//};
|
||||||
|
|
||||||
|
//template<>
|
||||||
|
//class FieldPhrase<QDateTime> : public AbstractFieldPhrase
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// FieldPhrase(const char *className, const char *s) :
|
||||||
|
// AbstractFieldPhrase(className, s)
|
||||||
|
// {}
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
||||||
|
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||||
|
// AssignmentPhrase operator =(const QDateTime &other) {
|
||||||
|
// return AssignmentPhrase(this, other);
|
||||||
|
// }
|
||||||
|
// ConditionalPhrase between(const QDateTime &min, const QDateTime &max)
|
||||||
|
// {
|
||||||
|
// return ConditionalPhrase(this, PhraseData::Between,
|
||||||
|
// QVariantList() << min << max);
|
||||||
|
// }
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
|
||||||
|
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
|
||||||
|
// CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
|
||||||
|
//};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // FIELDPHRASE_H
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
#include "numericphrase.h"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
#ifndef NUMERICPHRASE_H
|
||||||
|
#define NUMERICPHRASE_H
|
||||||
|
|
||||||
|
#include "fieldphrase.h"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
#define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \
|
||||||
|
ConditionalPhrase operator op(const QVariant &other) \
|
||||||
|
{ \
|
||||||
|
return ConditionalPhrase(this, cond, other); \
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class FieldPhrase<T, typename std::enable_if<std::is_integral<T>::value>::type>
|
||||||
|
: public AbstractFieldPhrase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FieldPhrase(const char *className, const char *s) :
|
||||||
|
AbstractFieldPhrase(className, s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, %, PhraseData::Mod)
|
||||||
|
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, +, PhraseData::Add)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, -, PhraseData::Minus)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, *, PhraseData::Multiple)
|
||||||
|
SPECIALIZATION_NUMERIC_MEMBER(type, /, PhraseData::Divide)
|
||||||
|
|
||||||
|
AssignmentPhrase operator =(const QVariant &other) {
|
||||||
|
return AssignmentPhrase(this, other);
|
||||||
|
}
|
||||||
|
AssignmentPhrase operator =(ConditionalPhrase &&other) {
|
||||||
|
return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data));
|
||||||
|
}
|
||||||
|
ConditionalPhrase between(const QVariant &min, const QVariant &max)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Between,
|
||||||
|
QVariantList() << min << max);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator ++()
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Add, 1);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator --()
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Minus, 1);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator ++(int)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Add, 1);
|
||||||
|
}
|
||||||
|
ConditionalPhrase operator --(int)
|
||||||
|
{
|
||||||
|
return ConditionalPhrase(this, PhraseData::Minus, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SPECIALIZATION_NUMERIC_TYPE(type) \
|
||||||
|
template<> \
|
||||||
|
class FieldPhrase<type> : public NumericPhrase \
|
||||||
|
{ \
|
||||||
|
public: \
|
||||||
|
FieldPhrase(const char *className, const char *s) : \
|
||||||
|
NumericPhrase(className, s) \
|
||||||
|
{} \
|
||||||
|
};
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(qint8)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(qint16)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(qint32)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(qint64)
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(quint8)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(quint16)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(quint32)
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(quint64)
|
||||||
|
|
||||||
|
//SPECIALIZATION_NUMERIC_TYPE(qreal)
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // NUMERICPHRASE_H
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
#include "phrasedata.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
PhraseData::PhraseData() :
|
||||||
|
className(""), fieldName(""),
|
||||||
|
type(Field), operatorCond(NotAssign),
|
||||||
|
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false), parents(1)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
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), parents(1)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
|
||||||
|
: className(nullptr), fieldName(nullptr),
|
||||||
|
type(WithoutOperand), operatorCond(o), left(l), right(nullptr),
|
||||||
|
isNot(false), parents(1)
|
||||||
|
{
|
||||||
|
l->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
||||||
|
PhraseData *r)
|
||||||
|
: className(nullptr), fieldName(nullptr),
|
||||||
|
type(WithOther), operatorCond(o),
|
||||||
|
left(l), right(r),
|
||||||
|
isNot(false), parents(1)
|
||||||
|
{
|
||||||
|
l->parents++;
|
||||||
|
r->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
||||||
|
: className(nullptr), fieldName(nullptr),
|
||||||
|
type(WithVariant), operatorCond(o), left(l),
|
||||||
|
right(nullptr), operand(r), isNot(false), parents(1)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
PhraseData *PhraseData::operator =(PhraseData *other)
|
||||||
|
{
|
||||||
|
other->parents++;
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseData &PhraseData::operator =(PhraseData &other)
|
||||||
|
{
|
||||||
|
other.parents++;
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PhraseData::toString() const
|
||||||
|
{
|
||||||
|
return QString("[%1].%2").arg(className, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhraseData::cleanUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhraseData::cleanUp(PhraseData *d)
|
||||||
|
{
|
||||||
|
if (d->left)
|
||||||
|
cleanUp(d->left);
|
||||||
|
if (d->right)
|
||||||
|
cleanUp(d->right);
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
#ifndef PHRASEDATA_H
|
||||||
|
#define PHRASEDATA_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Condition {
|
||||||
|
NotAssign = 0,
|
||||||
|
Equal,
|
||||||
|
Less,
|
||||||
|
LessEqual,
|
||||||
|
Null,
|
||||||
|
In,
|
||||||
|
Like,
|
||||||
|
|
||||||
|
Not = 10,
|
||||||
|
NotEqual,
|
||||||
|
GreaterEqual,
|
||||||
|
Greater,
|
||||||
|
NotNull,
|
||||||
|
NotIn,
|
||||||
|
NotLike,
|
||||||
|
|
||||||
|
And = 20,
|
||||||
|
Or,
|
||||||
|
|
||||||
|
Add,
|
||||||
|
Minus,
|
||||||
|
Multiple,
|
||||||
|
Divide,
|
||||||
|
Mod,
|
||||||
|
|
||||||
|
Between,
|
||||||
|
|
||||||
|
//date and time
|
||||||
|
AddYears,
|
||||||
|
AddMonths,
|
||||||
|
AddDays,
|
||||||
|
AddHours,
|
||||||
|
AddMinutes,
|
||||||
|
AddSeconds,
|
||||||
|
|
||||||
|
DatePartYear,
|
||||||
|
DatePartMonth,
|
||||||
|
DatePartDay,
|
||||||
|
DatePartHour,
|
||||||
|
DatePartMinute,
|
||||||
|
DatePartSecond,
|
||||||
|
DatePartMilisecond
|
||||||
|
// // special types
|
||||||
|
// Distance
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Type { Field, WithVariant, WithOther, WithoutOperand };
|
||||||
|
|
||||||
|
const char *className;
|
||||||
|
const char *fieldName;
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
|
||||||
|
Condition operatorCond;
|
||||||
|
|
||||||
|
PhraseData *left;
|
||||||
|
PhraseData *right;
|
||||||
|
|
||||||
|
QVariant operand;
|
||||||
|
bool isNot;
|
||||||
|
quint16 parents;
|
||||||
|
|
||||||
|
PhraseData();
|
||||||
|
PhraseData(const char *className, const char *fieldName);
|
||||||
|
PhraseData(PhraseData *l, Condition o);
|
||||||
|
PhraseData(PhraseData *l, Condition o, PhraseData *r);
|
||||||
|
PhraseData(PhraseData *l, Condition o, QVariant r);
|
||||||
|
// explicit PhraseData(const PhraseData &other);
|
||||||
|
// explicit PhraseData(const PhraseData *other);
|
||||||
|
|
||||||
|
PhraseData *operator =(PhraseData *other);
|
||||||
|
PhraseData &operator =(PhraseData &other);
|
||||||
|
|
||||||
|
QString toString() const;
|
||||||
|
|
||||||
|
~PhraseData() = default;
|
||||||
|
|
||||||
|
void cleanUp();
|
||||||
|
private:
|
||||||
|
void cleanUp(PhraseData *d);
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // PHRASEDATA_H
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "phrasedatalist.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
PhraseDataList::PhraseDataList() : QList<PhraseData*>()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseDataList::PhraseDataList(const PhraseDataList &other) : QList<PhraseData*>()
|
||||||
|
{
|
||||||
|
// auto &o = const_cast<PhraseDataList&>(other);
|
||||||
|
PhraseDataList::const_iterator i;
|
||||||
|
for (i = other.constBegin(); i != other.constEnd(); ++i)
|
||||||
|
append(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhraseDataList::append(PhraseData *d)
|
||||||
|
{
|
||||||
|
d->parents++;
|
||||||
|
QList<PhraseData*>::append(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhraseDataList::append(QList<PhraseData *> &dl)
|
||||||
|
{
|
||||||
|
foreach (PhraseData *d, dl)
|
||||||
|
d->parents++;
|
||||||
|
QList<PhraseData*>::append(dl);
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseDataList::~PhraseDataList()
|
||||||
|
{
|
||||||
|
QList<PhraseData*>::iterator i;
|
||||||
|
for (i = begin(); i != end(); ++i) {
|
||||||
|
(*i)->cleanUp();
|
||||||
|
if (!--(*i)->parents)
|
||||||
|
delete *i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef PHRASEDATALIST_H
|
||||||
|
#define PHRASEDATALIST_H
|
||||||
|
|
||||||
|
#include "phrasedata.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class PhraseDataList : public QList<PhraseData*>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhraseDataList();
|
||||||
|
PhraseDataList(const PhraseDataList &other);
|
||||||
|
void append(PhraseData *d);
|
||||||
|
void append(QList<PhraseData*> &dl);
|
||||||
|
virtual ~PhraseDataList();
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // PHRASEDATALIST_H
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
#include "abstractfieldphrase.h"
|
||||||
|
#include "phraselist.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
PhraseList::PhraseList() : isValid(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(const PhraseList &other) : isValid(true)
|
||||||
|
{
|
||||||
|
data = qMove(other.data);
|
||||||
|
const_cast<PhraseList&>(other).data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(PhraseList &&other)
|
||||||
|
{
|
||||||
|
data = other.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
|
||||||
|
{
|
||||||
|
data.append(other.data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(const AbstractFieldPhrase *left,
|
||||||
|
const AbstractFieldPhrase &right)
|
||||||
|
: isValid(true)
|
||||||
|
{
|
||||||
|
data.append(left->data);
|
||||||
|
data.append(right.data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
|
||||||
|
{
|
||||||
|
// data = qMove(left->data + right->data);
|
||||||
|
data.append(left->data);
|
||||||
|
data.append(right->data);
|
||||||
|
// left->data.clear();
|
||||||
|
// right->data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
|
||||||
|
: isValid(true)
|
||||||
|
{
|
||||||
|
data.append(left->data);
|
||||||
|
data.append(right->data);
|
||||||
|
incAllDataParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList &PhraseList::operator =(const PhraseList &other)
|
||||||
|
{
|
||||||
|
data.append(const_cast<PhraseList&>(other).data);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) {
|
||||||
|
return PhraseList(this, &other);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhraseList::incAllDataParents()
|
||||||
|
{
|
||||||
|
// foreach (PhraseData *d, data)
|
||||||
|
// d->parents++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList PhraseList::operator |(PhraseList &other) {
|
||||||
|
return PhraseList(this, &other);
|
||||||
|
}
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef PHRASELIST_H
|
||||||
|
#define PHRASELIST_H
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
|
||||||
|
#include "phrasedatalist.h"
|
||||||
|
|
||||||
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class AbstractFieldPhrase;
|
||||||
|
class PhraseList{
|
||||||
|
public:
|
||||||
|
bool isValid;
|
||||||
|
PhraseDataList data;
|
||||||
|
explicit PhraseList();
|
||||||
|
PhraseList(const PhraseList &other);
|
||||||
|
PhraseList(PhraseList &&other);
|
||||||
|
PhraseList(const AbstractFieldPhrase &other);
|
||||||
|
PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right);
|
||||||
|
PhraseList(PhraseList *left, PhraseList *right);
|
||||||
|
PhraseList(PhraseList *left, const AbstractFieldPhrase *right);
|
||||||
|
virtual ~PhraseList() = default;
|
||||||
|
|
||||||
|
PhraseList &operator =(const PhraseList &other);
|
||||||
|
PhraseList operator |(PhraseList &other);
|
||||||
|
PhraseList operator |(const AbstractFieldPhrase &other);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void incAllDataParents();
|
||||||
|
};
|
||||||
|
|
||||||
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // PHRASELIST_H
|
||||||
22
src/src.pro
22
src/src.pro
|
|
@ -30,7 +30,16 @@ HEADERS += \
|
||||||
$$PWD/serializableobject.h \
|
$$PWD/serializableobject.h \
|
||||||
$$PWD/sqlmodel.h \
|
$$PWD/sqlmodel.h \
|
||||||
$$PWD/sqlmodel_p.h \
|
$$PWD/sqlmodel_p.h \
|
||||||
$$PWD/phrase.h
|
$$PWD/phrase.h \
|
||||||
|
$$PWD/phrases/abstractfieldphrase.h \
|
||||||
|
$$PWD/phrases/assignmentphrase.h \
|
||||||
|
$$PWD/phrases/assignmentphraselist.h \
|
||||||
|
$$PWD/phrases/conditionalphrase.h \
|
||||||
|
$$PWD/phrases/fieldphrase.h \
|
||||||
|
$$PWD/phrases/phrasedata.h \
|
||||||
|
$$PWD/phrases/phrasedatalist.h \
|
||||||
|
$$PWD/phrases/phraselist.h \
|
||||||
|
../../../../Dev/Qt/Nut/src/phrases/datephrase.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/generators/sqlgeneratorbase.cpp \
|
$$PWD/generators/sqlgeneratorbase.cpp \
|
||||||
|
|
@ -50,6 +59,15 @@ SOURCES += \
|
||||||
$$PWD/database.cpp \
|
$$PWD/database.cpp \
|
||||||
$$PWD/serializableobject.cpp \
|
$$PWD/serializableobject.cpp \
|
||||||
$$PWD/sqlmodel.cpp \
|
$$PWD/sqlmodel.cpp \
|
||||||
$$PWD/phrase.cpp
|
$$PWD/phrase.cpp \
|
||||||
|
$$PWD/phrases/abstractfieldphrase.cpp \
|
||||||
|
$$PWD/phrases/assignmentphrase.cpp \
|
||||||
|
$$PWD/phrases/assignmentphraselist.cpp \
|
||||||
|
$$PWD/phrases/conditionalphrase.cpp \
|
||||||
|
$$PWD/phrases/fieldphrase.cpp \
|
||||||
|
$$PWD/phrases/phrasedata.cpp \
|
||||||
|
$$PWD/phrases/phrasedatalist.cpp \
|
||||||
|
$$PWD/phrases/phraselist.cpp \
|
||||||
|
../../../../Dev/Qt/Nut/src/phrases/datephrase.cpp
|
||||||
|
|
||||||
include($$PWD/../3rdparty/serializer/src/src.pri)
|
include($$PWD/../3rdparty/serializer/src/src.pri)
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,15 @@ void MainTest::numeric()
|
||||||
auto p4 = n < 1;
|
auto p4 = n < 1;
|
||||||
auto p5 = n > 1;
|
auto p5 = n > 1;
|
||||||
auto p6 = n != 1;
|
auto p6 = n != 1;
|
||||||
|
auto p7 = n = n + 1;
|
||||||
|
auto p8 = n < n + 1;
|
||||||
|
auto p9 = n <= n + 1;
|
||||||
|
auto p10 = n > n + 1;
|
||||||
|
auto p11 = n >= n + 1;
|
||||||
|
auto p12 = n + 1 > n - 2;
|
||||||
|
auto p13 = ++n;
|
||||||
|
auto p14 = n++;
|
||||||
|
auto p15 = n.between(1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::string()
|
void MainTest::string()
|
||||||
|
|
@ -73,6 +82,14 @@ void MainTest::datetime()
|
||||||
auto p5 = datetime > QDateTime::currentDateTime();
|
auto p5 = datetime > QDateTime::currentDateTime();
|
||||||
auto p6 = datetime.addMonths(1) >= QDateTime::currentDateTime();
|
auto p6 = datetime.addMonths(1) >= QDateTime::currentDateTime();
|
||||||
auto p7 = time.between(QTime::currentTime().addSecs(-100), QTime::currentTime());
|
auto p7 = time.between(QTime::currentTime().addSecs(-100), QTime::currentTime());
|
||||||
|
auto p8 = time.hour() == 3;
|
||||||
|
auto p9 = time = QTime::currentTime();
|
||||||
|
|
||||||
|
auto pi1 = time.addYears(1);
|
||||||
|
auto pi2 = date.addMinutes(3);
|
||||||
|
|
||||||
|
QTEST_ASSERT(!pi1.data);
|
||||||
|
QTEST_ASSERT(!pi2.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::extra()
|
void MainTest::extra()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue