Akonadi

nodetree.cpp
1 /*
2  Copyright (c) 2017 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 
21 #include "nodetree.h"
22 #include "cpphelper.h"
23 #include "typehelper.h"
24 
25 Node::Node(NodeType type, Node *parent)
26  : mParent(parent)
27  , mType(type)
28 {
29  if (parent) {
30  parent->appendNode(this);
31  }
32 }
33 
34 Node::~Node()
35 {
36  qDeleteAll(mChildren);
37 }
38 
39 Node::NodeType Node::type() const
40 {
41  return mType;
42 }
43 
44 Node *Node::parent() const
45 {
46  return mParent;
47 }
48 
49 void Node::appendNode(Node *child)
50 {
51  child->mParent = this;
52  mChildren.push_back(child);
53 }
54 
55 const QVector<Node const *> &Node::children() const
56 {
57  return mChildren;
58 }
59 
60 
61 
62 DocumentNode::DocumentNode(int version)
63  : Node(Document, nullptr)
64  , mVersion(version)
65 {}
66 
67 int DocumentNode::version() const
68 {
69  return mVersion;
70 }
71 
72 
73 
74 
75 
76 
77 ClassNode::ClassNode(const QString &name, ClassType type, DocumentNode *parent)
78  : Node(Node::Class, parent)
79  , mName(name)
80  , mClassType(type)
81 {}
82 
83 QString ClassNode::name() const
84 {
85  return mName;
86 }
87 
88 ClassNode::ClassType ClassNode::classType() const
89 {
90  return mClassType;
91 }
92 
93 QString ClassNode::className() const
94 {
95  switch (mClassType) {
96  case Class: return mName;
97  case Command: return mName + QStringLiteral("Command");
98  case Response: return mName + QStringLiteral("Response");
99  case Notification: return mName + QStringLiteral("Notification");
100  default: Q_ASSERT(false); return QString();
101  }
102 }
103 
104 QString ClassNode::parentClassName() const
105 {
106  switch (mClassType) {
107  case Class: return QString();
108  case Command: return QStringLiteral("Command");
109  case Response: return QStringLiteral("Response");
110  case Notification: return QStringLiteral("ChangeNotification");
111  case Invalid: Q_ASSERT(false); return QString();
112  }
113  Q_UNREACHABLE();
114 }
115 
116 ClassNode::ClassType ClassNode::elementNameToType(const QStringRef &name)
117 {
118  if (name == QLatin1String("class")) {
119  return Class;
120  } else if (name == QLatin1String("command")) {
121  return Command;
122  } else if (name == QLatin1String("response")) {
123  return Response;
124  } else if (name == QLatin1String("notification")) {
125  return Notification;
126  } else {
127  return Invalid;
128  }
129 }
130 
131 QVector<PropertyNode const *> ClassNode::properties() const
132 {
134  for (auto node : qAsConst(mChildren)) {
135  if (node->type() == Node::Property) {
136  rv << static_cast<PropertyNode const *>(node);
137  }
138  }
139  CppHelper::sortMembers(rv);
140  return rv;
141 }
142 
143 
144 
145 
146 
147 CtorNode::CtorNode(const QVector<Argument> &args, ClassNode *parent)
148  : Node(Ctor, parent)
149  , mArgs(args)
150 {}
151 
152 CtorNode::~CtorNode()
153 {}
154 
155 QVector<CtorNode::Argument> CtorNode::arguments() const
156 {
157  return mArgs;
158 }
159 
160 void CtorNode::setArgumentType(const QString &name, const QString &type)
161 {
162  for (auto &arg : mArgs) {
163  if (arg.name == name) {
164  arg.type = type;
165  break;
166  }
167  }
168 }
169 
170 
171 
172 
173 EnumNode::EnumNode(const QString &name, EnumType type, ClassNode *parent)
174  : Node(Enum, parent)
175  , mName(name)
176  , mEnumType(type)
177 {}
178 
179 QString EnumNode::name() const
180 {
181  return mName;
182 }
183 
184 EnumNode::EnumType EnumNode::enumType() const
185 {
186  return mEnumType;
187 }
188 
189 EnumNode::EnumType EnumNode::elementNameToType(const QStringRef &name)
190 {
191  if (name == QLatin1String("enum")) {
192  return TypeEnum;
193  } else if (name == QLatin1String("flag")) {
194  return TypeFlag;
195  } else {
196  return TypeInvalid;
197  }
198 }
199 
200 
201 
202 EnumValueNode::EnumValueNode(const QString &name, EnumNode *parent)
203  : Node(EnumValue, parent)
204  , mName(name)
205  , mValue()
206 {}
207 
208 QString EnumValueNode::name() const
209 {
210  return mName;
211 }
212 
213 void EnumValueNode::setValue(const QString &value)
214 {
215  mValue = value;
216 }
217 
218 QString EnumValueNode::value() const
219 {
220  return mValue;
221 }
222 
223 
224 
225 PropertyNode::PropertyNode(const QString &name, const QString &type, ClassNode *parent)
226  : Node(Property, parent)
227  , mName(name)
228  , mType(type)
229  , mSetter(nullptr)
230  , mReadOnly(false)
231  , mAsReference(false)
232 {}
233 
234 PropertyNode::~PropertyNode()
235 {
236  delete mSetter;
237 }
238 
239 QString PropertyNode::type() const
240 {
241  return mType;
242 }
243 
244 QString PropertyNode::name() const
245 {
246  return mName;
247 }
248 
249 void PropertyNode::setDefaultValue(const QString &defaultValue)
250 {
251  mDefaultValue = defaultValue;
252 }
253 
254 QString PropertyNode::defaultValue() const
255 {
256  return mDefaultValue;
257 }
258 
259 bool PropertyNode::readOnly() const
260 {
261  return mReadOnly;
262 }
263 
264 void PropertyNode::setReadOnly(bool readOnly)
265 {
266  mReadOnly = readOnly;
267 }
268 
269 bool PropertyNode::asReference() const
270 {
271  return mAsReference;
272 }
273 
274 void PropertyNode::setAsReference(bool asReference)
275 {
276  mAsReference = asReference;
277 }
278 
279 bool PropertyNode::isPointer() const
280 {
281  return TypeHelper::isPointerType(mType);
282 }
283 
284 QMultiMap<QString, QString> PropertyNode::dependencies() const
285 {
286  return mDepends;
287 }
288 
289 void PropertyNode::addDependency(const QString &enumVar, const QString &enumValue)
290 {
291  mDepends.insert(enumVar, enumValue);
292 }
293 
294 void PropertyNode::setSetter(Setter *setter)
295 {
296  mSetter = setter;
297 }
298 
299 PropertyNode::Setter *PropertyNode::setter() const
300 {
301  return mSetter;
302 }
303 
304 QString PropertyNode::mVariableName() const
305 {
306  return QStringLiteral("m") + mName[0].toUpper() + mName.midRef(1);
307 }
308 
309 QString PropertyNode::setterName() const
310 {
311  return QStringLiteral("set") + mName[0].toUpper() + mName.midRef(1);
312 }
QString toUpper() const const
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
QStringRef midRef(int position, int n) const const
Property
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 22:43:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.