-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredicateelement.cpp
170 lines (140 loc) · 4.11 KB
/
predicateelement.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "predicateelement.h"
#include "dynodb.h"
#include "predicate.h"
PredicateElement::PredicateElement(QString predicateElementString)
{
isLiteral_ = false;
isSet_ = false;
isValid_ = false;
isQuery_ = false;
isPredicate_ = false;
predicate_ = 0;
bool isInt;
quint64 lastElementInPredicateStringIndex = predicateElementString.size()-1;
// Try to convert the string to an integer
id_ = predicateElementString.toInt(&isInt);
// If it's not successful, parse it
if(!isInt)
{
// If the first element is a question mark, this is a query variable
if(predicateElementString.at(0) == '?')
{
isQuery_ = true;
predicateElementString.remove(0,1);
if(predicateElementString.isEmpty())
{
isValid_ = true;
return;
}
}
// If this has an open parentheses and ends in a closing parentheses, it might be a predicate
if (predicateElementString.indexOf("(") != -1 && predicateElementString.at(lastElementInPredicateStringIndex) == ')' )
{
isPredicate_ = true;
predicate_ = new Predicate(predicateElementString);
if(predicate_->isValid())
{
isValid_ = true;
}
return;
}
// If this is surrounded by curly braces, it might be a set of giblies
if (predicateElementString.at(0)=='{' && predicateElementString.at(lastElementInPredicateStringIndex) == '}' )
{
//remove the first and last elements since they are curly braces
predicateElementString.remove(lastElementInPredicateStringIndex,1);
predicateElementString.remove(0,1);
//split the string by commas
QStringList predicateElementsStringList = predicateElementString.split(",");
//iterate through the predicate elements string and parse each element as an integer
quint16 predicateElementsStringListIndex;
for (predicateElementsStringListIndex = 0; predicateElementsStringListIndex < predicateElementsStringList.size(); predicateElementsStringListIndex++ )
{
ids_.append(predicateElementsStringList.at(predicateElementsStringListIndex).toInt(&isInt));
if (!isInt) return;
}
isSet_ = true;
}
else if(predicateElementString.length() < 2 ||
predicateElementString.at(0) != '\"' ||
predicateElementString.at(predicateElementString.length() - 1) != '\"')
{
// Check to see if a class with this name exists
Class* dbclass = DynoDB::getInstance()->getClass(predicateElementString);
if(!dbclass)
{
return;
}
id_ = dbclass->getId();
}
else
{
predicateElementString.remove(0,1);
predicateElementString.remove(predicateElementString.length() - 1,1);
isLiteral_ = true;
literal_ = predicateElementString;
}
}
isValid_ = true;
}
PredicateElement::~PredicateElement()
{
if(predicate_ != 0)
{
delete predicate_;
}
}
bool PredicateElement::isValid() const
{
return isValid_;
}
bool PredicateElement::isLiteral() const
{
return isLiteral_;
}
bool PredicateElement::isSet() const
{
return isSet_;
}
bool PredicateElement::isQuery() const
{
if (isPredicate_)
{
if (predicate_->isQuery())
{
return true;
}
}
else return isQuery_;
}
bool PredicateElement::isPredicate() const
{
return isPredicate_;
}
quint32 PredicateElement::getId() const
{
return id_;
}
QList<quint32> PredicateElement::getIds() const
{
return ids_;
}
QVariant PredicateElement::getLiteral() const
{
return literal_;
}
QString PredicateElement::toString() const
{
if(isLiteral())
{
return literal_.toString();
}
else
{
return QString("%1").arg(id_);
}
}
Predicate const* PredicateElement::getPredicate() const
{
return predicate_;
}