• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • parsers
osdparser.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2010, 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "osdparser.h"
24 
25 #include "datainformationfactory.h"
26 #include "../datatypes/array/arraydatainformation.h"
27 #include "../datatypes/uniondatainformation.h"
28 #include "../datatypes/structuredatainformation.h"
29 #include "../datatypes/strings/stringdatainformation.h"
30 #include "../datatypes/strings/stringdata.h"
31 #include "../datatypes/primitivefactory.h"
32 #include "../datatypes/topleveldatainformation.h"
33 #include "../datatypes/dummydatainformation.h"
34 #include "../structuredefinitionfile.h"
35 #include "../script/scriptlogger.h"
36 #include "../script/scriptengineinitializer.h"
37 
38 #include <QFile>
39 #include <QFileInfo>
40 
41 #include <QDomDocument>
42 #include <QScriptEngine>
43 
44 #include <KDebug>
45 
46 using namespace ParserStrings;
47 
48 OsdParser::OsdParser(const QString& pluginName, const QString& absolutePath)
49  : AbstractStructureParser(pluginName, absolutePath)
50 {
51 }
52 
53 OsdParser::OsdParser(const QString& xml)
54  : AbstractStructureParser(QString(), QString()), mXmlString(xml)
55 {
56 }
57 
58 OsdParser::~OsdParser()
59 {
60 }
61 
62 QDomDocument OsdParser::openDoc(ScriptLogger* logger) const
63 {
64  return mXmlString.isEmpty() ? openDocFromFile(logger) : openDocFromString(logger);
65 }
66 
67 QDomDocument OsdParser::openDocFromString(ScriptLogger * logger) const
68 {
69  Q_CHECK_PTR(logger);
70  Q_ASSERT(!mXmlString.isEmpty());
71  int errorLine, errorColumn;
72  QString errorMsg;
73  QDomDocument doc;
74  if (!doc.setContent(mXmlString, false, &errorMsg, &errorLine, &errorColumn))
75  {
76  const QString errorOutput = QString(
77  QLatin1String("error reading XML: %1\n error line=%2\nerror column=%3"))
78  .arg(errorMsg, QString::number(errorLine), QString::number(errorColumn));
79  logger->error() << errorOutput;
80  logger->info() << "XML was:" << mXmlString;
81 
82  return QDomDocument();
83  }
84  return doc;
85 }
86 
87 QDomDocument OsdParser::openDocFromFile(ScriptLogger* logger) const
88 {
89  Q_CHECK_PTR(logger);
90  QFileInfo fileInfo(mAbsolutePath);
91  if (!fileInfo.exists())
92  {
93  logger->error() << "File" << mAbsolutePath << "does not exist!";
94  return QDomDocument();
95  }
96  QFile file(fileInfo.absoluteFilePath());
97  if (!file.open(QIODevice::ReadOnly))
98  {
99  const QString errorOutput = QLatin1String("Could not open file ") + mAbsolutePath;
100  logger->error() << errorOutput;
101  return QDomDocument();
102  }
103  int errorLine, errorColumn;
104  QString errorMsg;
105  QDomDocument doc;
106  if (!doc.setContent(&file, false, &errorMsg, &errorLine, &errorColumn))
107  {
108  const QString errorOutput = QString(
109  QLatin1String("error reading XML: %1\n error line=%2\nerror column=%3"))
110  .arg(errorMsg, QString::number(errorLine), QString::number(errorColumn));
111  logger->error() << errorOutput;
112  logger->info() << "File was:" << mAbsolutePath;
113  }
114  file.close();
115  return doc;
116 }
117 
118 QStringList OsdParser::parseStructureNames() const
119 {
120  QStringList ret;
121  QScopedPointer<ScriptLogger> rootLogger(new ScriptLogger); //only needed if we get an error right now
122  rootLogger->setLogToStdOut(true); //we cannot get our messages into the script console, so do this instead
123  QDomDocument document = openDoc(rootLogger.data());
124  if (document.isNull())
125  return QStringList();
126  QDomElement rootElem = document.firstChildElement(QLatin1String("data"));
127  if (rootElem.isNull())
128  return QStringList();
129  for (QDomElement childElement = rootElem.firstChildElement();
130  !childElement.isNull(); childElement = childElement.nextSiblingElement())
131  {
132  QString tag = childElement.tagName();
133  if (tag == TYPE_STRUCT || tag == TYPE_ARRAY || tag == TYPE_BITFIELD || tag == TYPE_PRIMITIVE
134  || tag == TYPE_UNION || tag == TYPE_ENUM || tag == TYPE_FLAGS || tag == TYPE_STRING)
135  {
136  //TODO allow e.g. <uint8 name="asfd">
137  ret.append(readProperty(childElement, PROPERTY_NAME, i18n("&lt;invalid name&gt;")));
138  }
139  else
140  {
141  rootLogger->error(QString()).nospace() << "Unknown tag name in plugin " << mPluginName << " :"
142  << tag;
143  }
144  }
145  return ret;
146 }
147 
148 QVector<TopLevelDataInformation*> OsdParser::parseStructures() const
149 {
150  QFileInfo fileInfo(mAbsolutePath);
151 
152  QVector<TopLevelDataInformation*> structures;
153  QScopedPointer<ScriptLogger> rootLogger(new ScriptLogger()); //only needed in we get an error right now
154  QDomDocument document = openDoc(rootLogger.data());
155  if (document.isNull())
156  {
157  structures.append(new TopLevelDataInformation(
158  new DummyDataInformation(0, fileInfo.fileName()), rootLogger.take(), 0, fileInfo));
159  return structures;
160  }
161 
162  QDomElement rootElem = document.firstChildElement(QLatin1String("data"));
163  if (rootElem.isNull())
164  {
165  rootLogger->error() << "Missing top level <data> element!";
166  structures.append(new TopLevelDataInformation(
167  new DummyDataInformation(0, fileInfo.fileName()), rootLogger.take(), 0, fileInfo));
168  return structures;
169  }
170  int count = 1;
171  for (QDomElement elem = rootElem.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
172  {
173  if (elem.tagName() == TYPE_ENUMDEF)
174  continue; //skip enum defs
175 
176  QScriptEngine* eng = ScriptEngineInitializer::newEngine(); //we need this for dynamic arrays
177  ScriptLogger* logger = new ScriptLogger();
178  QVector<EnumDefinition::Ptr> enums = parseEnums(rootElem, logger);
179  OsdParserInfo info(QString(), logger, 0, eng, enums);
180 
181  DataInformation* data = parseElement(elem, info);
182 
183  if (!data)
184  {
185  QString name = readProperty(elem, PROPERTY_NAME);
186  if (name.isEmpty())
187  name = fileInfo.absoluteFilePath() + QLatin1String("_element") + QString::number(count);
188  kDebug() << "Failed to parse element" << elem.tagName() << name;
189  kDebug() << "Parsing messages were:" << logger->messages();
190  data = new DummyDataInformation(0, name);
191  }
192  TopLevelDataInformation* topData = new TopLevelDataInformation(data, logger, eng, fileInfo);
193  QString lockOffsetStr = readProperty(elem, PROPERTY_DEFAULT_LOCK_OFFSET);
194  if (!lockOffsetStr.isEmpty())
195  {
196  ParsedNumber<quint64> offset = ParserUtils::uint64FromString(lockOffsetStr);
197  if (!offset.isValid)
198  data->logError() << "Default lock offset is not a valid number:" << offset.string;
199  else
200  {
201  data->logInfo() << "Default lock offset is " << offset.string;
202  topData->setDefaultLockOffset(offset.value);
203  }
204  }
205  structures.append(topData);
206  count++;
207  }
208  return structures;
209 }
210 
211 //TODO make type depend on the user not the definition
212 QVector<EnumDefinition::Ptr> OsdParser::parseEnums(const QDomElement& rootElem, ScriptLogger* logger)
213 {
214  QVector<EnumDefinition::Ptr> ret;
215  for (QDomElement elem = rootElem.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
216  {
217  if (elem.tagName() != TYPE_ENUMDEF)
218  continue;
219 
220  QMap<AllPrimitiveTypes, QString> defs;
221  const QString enumName = readProperty(elem, PROPERTY_NAME, i18n("&lt;invalid name&gt;"));
222  const QString typeStr = readProperty(elem, PROPERTY_TYPE);
223  if (typeStr.isEmpty())
224  {
225  logger->error(enumName) << "Skipping enum definition, since no type attribute was found.";
226  continue;
227  }
228  LoggerWithContext lwc(logger, QLatin1String("enum values (") + enumName + QLatin1Char(')'));
229  PrimitiveDataType type = PrimitiveFactory::typeStringToType(typeStr, lwc);
230  //handle all entries
231  for (QDomElement child = elem.firstChildElement(); !child.isNull(); child =
232  child.nextSiblingElement())
233  {
234  if (child.tagName() != QLatin1String("entry"))
235  continue;
236 
237  QString name = readProperty(child, PROPERTY_NAME);
238  if (name.isEmpty())
239  {
240  lwc.warn() << "Entry is missing name, skipping it!";
241  continue;
242  }
243  QString value = readProperty(child, PROPERTY_VALUE);
244  QPair<AllPrimitiveTypes, QString> converted =
245  EnumDefinition::convertToEnumEntry(name, value, lwc, type);
246  if (converted == QPair<AllPrimitiveTypes, QString>())
247  continue;
248  defs.insert(converted.first, converted.second);
249  }
250  //now add this enum to the list of enums
251  if (defs.isEmpty())
252  {
253  lwc.error() << "Enum definition contains no valid elements!";
254  }
255  else
256  {
257  EnumDefinition::Ptr enumDef = EnumDefinition::Ptr(new EnumDefinition(defs, enumName, type));
258  ret.append(enumDef);
259  }
260  }
261  return ret;
262 }
263 
264 //Datatypes
265 
266 ArrayDataInformation* OsdParser::arrayFromXML(const QDomElement& xmlElem, const OsdParserInfo& info)
267 {
268  ArrayParsedData apd(info);
269  QString lengthStr = readProperty(xmlElem, PROPERTY_LENGTH);
270  if (lengthStr.isEmpty())
271  {
272  info.error() << "No array length specified!";
273  return 0;
274  }
275  //must wrap in parentheses, cannot just evaluate. See https://bugreports.qt-project.org/browse/QTBUG-5757
276  const QScriptValue lengthFunc = ParserUtils::functionSafeEval(info.engine, lengthStr);
277  if (lengthFunc.isValid()) {
278  apd.length = lengthFunc;
279  }
280  else {
281  apd.length = QScriptValue(lengthStr);
282  }
283  //first check whether there is a <type> element and use the inner element
284  //if that doesn't exist use the first child element as the type, but only if there is only one child
285  apd.arrayType = parseType(xmlElem, info, NAME_ARRAY_TYPE);
286  if (!apd.arrayType) {
287  //was not specified as <type> element or type="attribute", use first child
288  DummyDataInformation dummy(info.parent, info.name); //dummy so that we have a proper chain
289  OsdChildrenParser typeParser(info, xmlElem.firstChildElement());
290  typeParser.setParent(&dummy);
291  if (typeParser.hasNext())
292  {
293  apd.arrayType = typeParser.next();
294  if (typeParser.hasNext())
295  {
296  info.error() << "More than one possible type for array!";
297  delete apd.arrayType;
298  apd.arrayType = 0;
299  return 0;
300  }
301  }
302  }
303  return DataInformationFactory::newArray(apd);
304 }
305 
306 DataInformation* OsdParser::parseChildElement(const QDomElement& xmlElem, const OsdParserInfo& info, const QString& name)
307 {
308  OsdParserInfo newInfo(info);
309  //instanciate a dummy so that a propert chain up to the root element exists
310  DummyDataInformation dummy(info.parent, info.name);
311  newInfo.parent = &dummy;
312  newInfo.name = name;
313  return parseElement(xmlElem, newInfo);
314 }
315 
316 
317 DataInformation* OsdParser::parseType(const QDomElement& xmlElem, const OsdParserInfo& info, const QString& name)
318 {
319  const QString typeAttribute = xmlElem.attribute(PROPERTY_TYPE);
320  if (!typeAttribute.isEmpty()) {
321  //type was specified as a primitive string
322  LoggerWithContext lwc(info.logger, info.context() + name);
323  DataInformation* ret = PrimitiveFactory::newInstance(name, typeAttribute, lwc);
324  if (!ret) {
325  info.error() << typeAttribute << "is not a valid type identifier";
326  }
327  return ret;
328  }
329  //we have to parse the first child element of the <type> element
330  const QDomElement toParse = xmlElem.firstChildElement(PROPERTY_TYPE).firstChildElement();
331  if (toParse.isNull())
332  {
333  //don't log an error here, it may be okay (i.e. in arrays <type> can be omitted)
334  return 0;
335  }
336  if (!toParse.nextSiblingElement().isNull()) {
337  info.warn() << "<type> element has more than one child!";
338  }
339  //TODO have this newInfo code only in one location
340  DataInformation* ret = parseChildElement(toParse, info, name);
341  if (!ret) {
342  info.error() << "Failed to parse element defined in <type>";
343  }
344  return ret;
345 }
346 
347 
348 PointerDataInformation* OsdParser::pointerFromXML(const QDomElement& xmlElem, const OsdParserInfo& info)
349 {
350  PointerParsedData ppd(info);
351 
352  ppd.valueType = parseType(xmlElem, info, NAME_POINTER_VALUE_TYPE);
353 
354  //first check whether there is a <target> element and use the inner element
355  //if that doesn't exist use the first child element as the type, but only if there is only one child
356  QDomElement childElement = xmlElem.firstChildElement(PROPERTY_TARGET).firstChildElement();
357  if (childElement.isNull())
358  {
359  childElement = xmlElem.firstChildElement();
360  if (childElement.isNull())
361  {
362  info.error() << "Pointer target is missing! Please add a <target> child element.";
363  return 0;
364  }
365  else if (childElement != xmlElem.lastChildElement())
366  {
367  //there is more than one child element
368  info.error() << "There is more than one child element, cannot determine which one "
369  "is the pointer target. Wrap the correct one in a <target> element.";
370  return 0;
371  }
372  }
373  ppd.pointerTarget = parseChildElement(childElement, info, NAME_POINTER_TARGET);
374  return DataInformationFactory::newPointer(ppd);
375 }
376 
377 PrimitiveDataInformation* OsdParser::primitiveFromXML(const QDomElement& xmlElem, const OsdParserInfo& info)
378 {
379  PrimitiveParsedData ppd(info);
380  ppd.type = readProperty(xmlElem, PROPERTY_TYPE);
381  return DataInformationFactory::newPrimitive(ppd);
382 }
383 
384 AbstractBitfieldDataInformation* OsdParser::bitfieldFromXML(const QDomElement& xmlElem,
385  const OsdParserInfo& info)
386 {
387  BitfieldParsedData bpd(info);
388  bpd.type = readProperty(xmlElem, PROPERTY_TYPE);
389  QString width = readProperty(xmlElem, PROPERTY_WIDTH);
390  bpd.width = ParserUtils::intFromString(width);
391  return DataInformationFactory::newBitfield(bpd);
392 }
393 
394 inline UnionDataInformation* OsdParser::unionFromXML(const QDomElement& xmlElem, const OsdParserInfo& info)
395 {
396  StructOrUnionParsedData supd(info);
397  supd.children.reset(new OsdChildrenParser(info, xmlElem.firstChildElement()));
398  return DataInformationFactory::newUnion(supd);
399 }
400 
401 inline StructureDataInformation* OsdParser::structFromXML(const QDomElement& xmlElem, const OsdParserInfo& info)
402 {
403  StructOrUnionParsedData supd(info);
404  supd.children.reset(new OsdChildrenParser(info, xmlElem.firstChildElement()));
405  return DataInformationFactory::newStruct(supd);
406 }
407 
408 EnumDataInformation* OsdParser::enumFromXML(const QDomElement& xmlElem, bool isFlags,
409  const OsdParserInfo& info)
410 {
411  EnumParsedData epd(info);
412  epd.type = readProperty(xmlElem, PROPERTY_TYPE);
413  epd.enumName = readProperty(xmlElem, PROPERTY_ENUM_NAME);
414  if (epd.enumName.isEmpty())
415  epd.enumName = readProperty(xmlElem, TYPE_ENUM); //used again here as property
416  epd.enumDef = findEnum(epd.enumName, info);
417  if (!epd.enumDef)
418  {
419  info.error().nospace() << "Enum definition '" << epd.enumName << "' does not exist!";
420  return 0;
421  }
422 
423  if (isFlags)
424  return DataInformationFactory::newFlags(epd);
425  else
426  return DataInformationFactory::newEnum(epd);
427 }
428 
429 StringDataInformation* OsdParser::stringFromXML(const QDomElement& xmlElem,
430  const OsdParserInfo& info)
431 {
432  StringParsedData spd(info);
433  spd.encoding = readProperty(xmlElem, PROPERTY_ENCODING);
434  spd.termination = ParserUtils::uintFromString(readProperty(xmlElem, PROPERTY_TERMINATED_BY));
435  spd.maxByteCount = ParserUtils::uintFromString(readProperty(xmlElem, PROPERTY_MAX_BYTE_COUNT));
436  spd.maxCharCount = ParserUtils::uintFromString(readProperty(xmlElem, PROPERTY_MAX_CHAR_COUNT));
437  return DataInformationFactory::newString(spd);
438 }
439 
440 DataInformation* OsdParser::parseElement(const QDomElement& elem, const OsdParserInfo& oldInfo)
441 {
442  Q_ASSERT(!elem.isNull());
443  DataInformation* data = 0;
444  const QString tag = elem.tagName();
445  OsdParserInfo info(oldInfo);
446  info.name = readProperty(elem, PROPERTY_NAME, QLatin1String("<anonymous>"));
447  if (tag == TYPE_STRUCT)
448  data = structFromXML(elem, info);
449  else if (tag == TYPE_ARRAY)
450  data = arrayFromXML(elem, info);
451  else if (tag == TYPE_BITFIELD)
452  data = bitfieldFromXML(elem, info);
453  else if (tag == TYPE_PRIMITIVE)
454  data = primitiveFromXML(elem, info);
455  else if (tag == TYPE_UNION)
456  data = unionFromXML(elem, info);
457  else if (tag == TYPE_ENUM)
458  data = enumFromXML(elem, false, info);
459  else if (tag == TYPE_FLAGS)
460  data = enumFromXML(elem, true, info);
461  else if (tag == TYPE_STRING)
462  data = stringFromXML(elem, info);
463  else if (tag == TYPE_POINTER)
464  data = pointerFromXML(elem, info);
465  else if (tag == TYPE_TAGGED_UNION)
466  data = taggedUnionFromXML(elem, info);
467  else {
468  LoggerWithContext lwc(info.logger, info.context());
469  //use the type tag as a primitive type
470  data = PrimitiveFactory::newInstance(info.name, tag, lwc);
471  if (!data) {
472  info.error() << "Cannot parse unknown tag: " << tag;
473  }
474  }
475 
476  if (data)
477  {
478  CommonParsedData cpd(info);
479  QString byteOrderStr = readProperty(elem, PROPERTY_BYTEORDER);
480  if (!byteOrderStr.isEmpty())
481  cpd.endianess = ParserUtils::byteOrderFromString(byteOrderStr,
482  LoggerWithContext(info.logger, info.context()));
483  cpd.updateFunc = ParserUtils::functionSafeEval(info.engine, readProperty(elem, PROPERTY_UPDATE_FUNC));
484  cpd.validationFunc = ParserUtils::functionSafeEval(info.engine, readProperty(elem, PROPERTY_VALIDATION_FUNC));
485  cpd.toStringFunc = ParserUtils::functionSafeEval(info.engine, readProperty(elem, PROPERTY_TO_STRING_FUNC));
486  cpd.customTypeName = readProperty(elem, PROPERTY_CUSTOM_TYPE_NAME);
487  if (!DataInformationFactory::commonInitialization(data, cpd))
488  {
489  delete data; //error message has already been logged
490  return 0;
491  }
492  }
493  return data;
494 }
495 
496 EnumDefinition::Ptr OsdParser::findEnum(const QString& defName, const OsdParserInfo& info)
497 {
498  for (int i = 0; i < info.enums.size(); ++i)
499  {
500  const EnumDefinition::Ptr def = info.enums.at(i);
501  if (def->name() == defName)
502  return def;
503  }
504  info.error() << "Could not find enum definition with name" << defName;
505  return EnumDefinition::Ptr(0);
506 }
507 
508 QString OsdParser::readProperty(const QDomElement& elem, const QString& property, const QString& defaultVal)
509 {
510  const QString attrib = elem.attribute(property);
511  if (!attrib.isEmpty())
512  return attrib;
513  //check for element now
514  const QDomElement childElem = elem.firstChildElement(property);
515  if (!elem.isNull())
516  return elem.text();
517  else
518  return defaultVal;
519 }
520 
521 TaggedUnionDataInformation* OsdParser::taggedUnionFromXML(const QDomElement& xmlElem,
522  const OsdParserInfo& info)
523 {
524  TaggedUnionParsedData tpd(info);
525  //can be null
526  QDomElement defaultChildren = xmlElem.firstChildElement(PROPERTY_DEFAULT_CHILDREN).firstChildElement();
527  if (defaultChildren.isNull())
528  info.info() << "No default fields specified, defaulting to none.";
529  tpd.defaultFields.reset(new OsdChildrenParser(info, defaultChildren));
530  tpd.children.reset(new OsdChildrenParser(info, xmlElem.firstChildElement()));
531  //now handle alternatives
532  QDomElement alternatives = xmlElem.firstChildElement(PROPERTY_ALTERNATIVES);
533  if (alternatives.isNull())
534  {
535  info.error() << "Missing <alternatives> element, tagged union cannot exist without at least one alternative";
536  return 0;
537  }
538  for (QDomElement elem = alternatives.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
539  {
540  TaggedUnionParsedData::Alternatives alt;
541  alt.name = readProperty(elem, PROPERTY_STRUCT_NAME);
542  QString selectIfStr = readProperty(elem, PROPERTY_SELECT_IF);
543  QScriptValue selectIf = ParserUtils::functionSafeEval(info.engine, selectIfStr);
544  if (!selectIf.isValid())
545  selectIf = selectIfStr;
546  alt.selectIf = selectIf;
547  if (elem.tagName() == TYPE_GROUP)
548  alt.fields = QSharedPointer<ChildrenParser>(new OsdChildrenParser(info, elem.firstChildElement()));
549  else
550  alt.fields = QSharedPointer<ChildrenParser>(new SingleElementOsdChildrenParser(info, elem));
551  tpd.alternatives.append(alt);
552  }
553 
554  return DataInformationFactory::newTaggedUnion(tpd);
555 }
556 
557 OsdChildrenParser::OsdChildrenParser(const OsdParserInfo& info, QDomElement firstChild)
558  : mInfo(info), mElem(firstChild)
559 {
560 }
561 
562 DataInformation* OsdChildrenParser::next()
563 {
564  Q_ASSERT(!mElem.isNull());
565  //skip all known properties
566  while (ALL_PROPERTIES.contains(mElem.tagName()))
567  mElem = mElem.nextSiblingElement();
568  if (mElem.isNull())
569  {
570  mInfo.warn() << "Reached end of fields, but next() was requested!";
571  return 0;
572  }
573  DataInformation* ret = OsdParser::parseElement(mElem, mInfo);
574  mElem = mElem.nextSiblingElement();
575  return ret;
576 }
577 
578 OsdChildrenParser::~OsdChildrenParser()
579 {
580 }
581 
582 bool OsdChildrenParser::hasNext()
583 {
584  if (mElem.isNull())
585  return false;
586  while (ALL_PROPERTIES.contains(mElem.tagName()))
587  mElem = mElem.nextSiblingElement(); //skip known properties
588  return !mElem.isNull();
589 }
590 
591 void OsdChildrenParser::setParent(DataInformation* newParent)
592 {
593  mInfo.parent = newParent;
594 }
595 
596 SingleElementOsdChildrenParser::SingleElementOsdChildrenParser(const OsdParserInfo& info, QDomElement element)
597  : OsdChildrenParser(info, element), mParsed(false)
598 {
599  if (mElem.isNull())
600  info.warn() << "Null Element passed to child parser!";
601 }
602 
603 SingleElementOsdChildrenParser::~SingleElementOsdChildrenParser()
604 {
605 }
606 
607 DataInformation* SingleElementOsdChildrenParser::next()
608 {
609  Q_ASSERT(!mParsed);
610  mParsed = true;
611  return OsdParser::parseElement(mElem, mInfo);
612 }
613 
614 bool SingleElementOsdChildrenParser::hasNext()
615 {
616  return !mParsed && !mElem.isNull();
617 }
ParserInfo::info
QDebug info() const
Definition: parserutils.h:67
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
DataInformationFactory::commonInitialization
bool commonInitialization(DataInformation *data, const CommonParsedData &pd)
Definition: datainformationfactory.cpp:300
OsdChildrenParser
Definition: osdparser.h:100
LoggerWithContext
Definition: scriptlogger.h:94
ParserStrings::NAME_POINTER_VALUE_TYPE
const QString NAME_POINTER_VALUE_TYPE
Definition: parserutils.h:168
ParserStrings::PROPERTY_TARGET
const QString PROPERTY_TARGET
Definition: parserutils.h:149
DataInformationFactory::newString
StringDataInformation * newString(const StringParsedData &pd)
Definition: datainformationfactory.cpp:249
OsdChildrenParser::mElem
QDomElement mElem
Definition: osdparser.h:109
DummyDataInformation
Definition: dummydatainformation.h:30
ParserStrings::TYPE_PRIMITIVE
const QString TYPE_PRIMITIVE
Definition: parserutils.h:100
SingleElementOsdChildrenParser::mParsed
bool mParsed
Definition: osdparser.h:119
ParserStrings::PROPERTY_MAX_BYTE_COUNT
const QString PROPERTY_MAX_BYTE_COUNT
Definition: parserutils.h:143
OsdParserInfo::enums
QVector< EnumDefinition::Ptr > enums
Definition: osdparser.h:50
ParserStrings::TYPE_BITFIELD
const QString TYPE_BITFIELD
Definition: parserutils.h:97
OsdParser::parseStructures
virtual QVector< TopLevelDataInformation * > parseStructures() const
Definition: osdparser.cpp:148
datainformationfactory.h
OsdChildrenParser::hasNext
virtual bool hasNext()
Definition: osdparser.cpp:582
PointerDataInformation
Definition: pointerdatainformation.h:30
ParserStrings::NAME_POINTER_TARGET
const QString NAME_POINTER_TARGET
Definition: parserutils.h:169
DataInformationFactory::newPointer
PointerDataInformation * newPointer(const PointerParsedData &pd)
Definition: datainformationfactory.cpp:346
SingleElementOsdChildrenParser::next
virtual DataInformation * next()
Definition: osdparser.cpp:607
ParserInfo::engine
QScriptEngine * engine
Definition: parserutils.h:61
TaggedUnionParsedData::Alternatives
Definition: datainformationfactory.h:110
ParsedNumber::value
T value
Definition: parserutils.h:88
DataInformationFactory::newFlags
FlagDataInformation * newFlags(const EnumParsedData &pd)
Definition: datainformationfactory.cpp:198
OsdChildrenParser::mInfo
OsdParserInfo mInfo
Definition: osdparser.h:108
OsdParser::~OsdParser
virtual ~OsdParser()
Definition: osdparser.cpp:58
ParserUtils::functionSafeEval
QScriptValue functionSafeEval(QScriptEngine *engine, const QString &str)
This essentially calls engine->evaluate(str), but ensures it can be a function (QTBUG-5757) ...
Definition: parserutils.cpp:184
ParserStrings::NAME_ARRAY_TYPE
const QString NAME_ARRAY_TYPE
Definition: parserutils.h:170
ParsedNumber::string
QString string
Definition: parserutils.h:87
OsdChildrenParser::OsdChildrenParser
OsdChildrenParser(const OsdParserInfo &info, QDomElement firstChild)
Definition: osdparser.cpp:557
ParserStrings::TYPE_FLAGS
const QString TYPE_FLAGS
Definition: parserutils.h:99
ParsedNumber
Holds a number that was converted either from a QScriptValue or a QString.
Definition: parserutils.h:84
osdparser.h
SingleElementOsdChildrenParser::hasNext
virtual bool hasNext()
Definition: osdparser.cpp:614
EnumDataInformation
Definition: enumdatainformation.h:29
TaggedUnionParsedData::Alternatives::selectIf
QScriptValue selectIf
Definition: datainformationfactory.h:112
EnumDefinition::convertToEnumEntry
static QPair< AllPrimitiveTypes, QString > convertToEnumEntry(const QString &name, const QVariant &value, const LoggerWithContext &logger, PrimitiveDataType type)
Definition: enumdefinition.cpp:59
ParserStrings::PROPERTY_CUSTOM_TYPE_NAME
const QString PROPERTY_CUSTOM_TYPE_NAME
Definition: parserutils.h:124
ParserStrings::TYPE_ENUM
const QString TYPE_ENUM
Definition: parserutils.h:98
QVector
Definition: scriptvalueconverter.h:30
DataInformationFactory::newTaggedUnion
TaggedUnionDataInformation * newTaggedUnion(const TaggedUnionParsedData &pd)
Definition: datainformationfactory.cpp:373
ParserStrings::PROPERTY_TO_STRING_FUNC
const QString PROPERTY_TO_STRING_FUNC
Definition: parserutils.h:122
ParserStrings::PROPERTY_DEFAULT_LOCK_OFFSET
const QString PROPERTY_DEFAULT_LOCK_OFFSET
Definition: parserutils.h:112
ScriptLogger::messages
QStringList messages(LogLevel minLevel=LogInfo) const
Definition: scriptlogger.cpp:135
ParserStrings::PROPERTY_VALUE
const QString PROPERTY_VALUE
Definition: parserutils.h:147
OsdParser::parseElement
static DataInformation * parseElement(const QDomElement &node, const OsdParserInfo &info)
Definition: osdparser.cpp:440
ParserUtils::intFromString
ParsedNumber< int > intFromString(const QString &str)
If string starts with 0x, the remainder is interpreted as a hexadecimal (unsigned) number otherwise i...
Definition: parserutils.cpp:27
CommonParsedData::toStringFunc
QScriptValue toStringFunc
Definition: datainformationfactory.h:49
TaggedUnionParsedData::Alternatives::fields
QSharedPointer< ChildrenParser > fields
Definition: datainformationfactory.h:113
ParserStrings::PROPERTY_WIDTH
const QString PROPERTY_WIDTH
Definition: parserutils.h:134
TaggedUnionDataInformation
A class holding the data of a struct for Okteta.
Definition: taggeduniondatainformation.h:31
ParserStrings::PROPERTY_SELECT_IF
const QString PROPERTY_SELECT_IF
Definition: parserutils.h:153
EnumParsedData
Definition: datainformationfactory.h:71
EnumDefinition::Ptr
QSharedDataPointer< EnumDefinition > Ptr
Definition: enumdefinition.h:40
ArrayDataInformation
Definition: arraydatainformation.h:36
PrimitiveDataType
Definition: primitivedatatype.h:54
BitfieldParsedData
Definition: datainformationfactory.h:56
ParserStrings::PROPERTY_ENCODING
const QString PROPERTY_ENCODING
Definition: parserutils.h:145
CommonParsedData
Definition: datainformationfactory.h:44
ParserStrings::PROPERTY_TYPE
const QString PROPERTY_TYPE
Definition: parserutils.h:130
ParserStrings::PROPERTY_LENGTH
const QString PROPERTY_LENGTH
Definition: parserutils.h:132
TopLevelDataInformation
Definition: topleveldatainformation.h:46
DataInformation::logInfo
QDebug logInfo() const
just a shorthand for logger->info(this)
Definition: datainformation.h:314
SingleElementOsdChildrenParser::~SingleElementOsdChildrenParser
virtual ~SingleElementOsdChildrenParser()
Definition: osdparser.cpp:603
ParserInfo::logger
ScriptLogger * logger
Definition: parserutils.h:59
DataInformationFactory::newPrimitive
PrimitiveDataInformation * newPrimitive(const PrimitiveParsedData &pd)
Definition: datainformationfactory.cpp:68
ParserStrings::PROPERTY_UPDATE_FUNC
const QString PROPERTY_UPDATE_FUNC
Definition: parserutils.h:120
ScriptEngineInitializer::newEngine
QScriptEngine * newEngine()
Definition: scriptengineinitializer.cpp:106
ParserInfo::parent
DataInformation * parent
Definition: parserutils.h:60
DataInformationFactory::newUnion
UnionDataInformation * newUnion(const StructOrUnionParsedData &pd)
Definition: datainformationfactory.cpp:290
ParserStrings::TYPE_TAGGED_UNION
const QString TYPE_TAGGED_UNION
Definition: parserutils.h:105
PrimitiveFactory::typeStringToType
PrimitiveDataType typeStringToType(const QString &string, const LoggerWithContext &logger)
Converts typeStr to a PrimitiveDataType case-insensitively.
Definition: primitivefactory.cpp:30
ParserStrings::TYPE_ENUMDEF
const QString TYPE_ENUMDEF
Only needed for .osd.
Definition: parserutils.h:107
ScriptLogger
NOT THREAD SAFE!
Definition: scriptlogger.h:35
OsdChildrenParser::~OsdChildrenParser
virtual ~OsdChildrenParser()
Definition: osdparser.cpp:578
DataInformationFactory::newEnum
EnumDataInformation * newEnum(const EnumParsedData &pd)
Definition: datainformationfactory.cpp:193
ParserInfo::context
QString context() const
Definition: parserutils.h:63
ParserStrings::TYPE_ARRAY
const QString TYPE_ARRAY
Definition: parserutils.h:96
UnionDataInformation
A class holding the data of a union for Okteta.
Definition: uniondatainformation.h:28
ParserStrings::PROPERTY_ENUM_NAME
const QString PROPERTY_ENUM_NAME
Definition: parserutils.h:128
PrimitiveFactory::newInstance
PrimitiveDataInformation * newInstance(const QString &name, PrimitiveDataType type, const LoggerWithContext &logger, DataInformation *parent)
Definition: primitivefactory.cpp:66
ParserUtils::uint64FromString
ParsedNumber< quint64 > uint64FromString(const QString &str)
Definition: parserutils.cpp:56
SingleElementOsdChildrenParser
Definition: osdparser.h:112
ParserUtils::uintFromString
ParsedNumber< uint > uintFromString(const QString &str)
Definition: parserutils.cpp:45
TopLevelDataInformation::setDefaultLockOffset
void setDefaultLockOffset(Okteta::Address offset)
Definition: topleveldatainformation.cpp:217
ScriptLogger::info
QDebug info(const DataInformation *origin)
Definition: scriptlogger.h:66
ParserStrings::TYPE_STRING
const QString TYPE_STRING
Definition: parserutils.h:101
ParserStrings::PROPERTY_VALIDATION_FUNC
const QString PROPERTY_VALIDATION_FUNC
Definition: parserutils.h:121
PrimitiveParsedData
Definition: datainformationfactory.h:64
ParserStrings::ALL_PROPERTIES
const QStringList ALL_PROPERTIES
Definition: parserutils.h:158
OsdChildrenParser::setParent
virtual void setParent(DataInformation *newParent)
Definition: osdparser.cpp:591
EnumDefinition
Definition: enumdefinition.h:37
AbstractStructureParser::mPluginName
const QString mPluginName
Definition: abstractstructureparser.h:45
ScriptLogger::error
QDebug error(const DataInformation *origin)
Definition: scriptlogger.h:68
CommonParsedData::updateFunc
QScriptValue updateFunc
Definition: datainformationfactory.h:47
OsdParser::OsdParser
OsdParser(const QString &pluginName, const QString &absolutePath)
construct a parser which opens parses absolutePath
Definition: osdparser.cpp:48
ParserStrings::PROPERTY_BYTEORDER
const QString PROPERTY_BYTEORDER
Definition: parserutils.h:115
ParserStrings::TYPE_POINTER
const QString TYPE_POINTER
Definition: parserutils.h:104
ParserStrings::TYPE_UNION
const QString TYPE_UNION
Definition: parserutils.h:103
TaggedUnionParsedData
Definition: datainformationfactory.h:109
OsdChildrenParser::next
virtual DataInformation * next()
Definition: osdparser.cpp:562
ParserStrings::TYPE_GROUP
const QString TYPE_GROUP
Definition: parserutils.h:109
CommonParsedData::customTypeName
QString customTypeName
Definition: datainformationfactory.h:50
ParserInfo::error
QDebug error() const
Definition: parserutils.h:69
AbstractStructureParser::mAbsolutePath
const QString mAbsolutePath
Definition: abstractstructureparser.h:46
DataInformationFactory::newStruct
StructureDataInformation * newStruct(const StructOrUnionParsedData &pd)
Definition: datainformationfactory.cpp:295
OsdParser::parseStructureNames
virtual QStringList parseStructureNames() const
Definition: osdparser.cpp:118
PointerParsedData
Definition: datainformationfactory.h:101
ParserUtils::byteOrderFromString
DataInformation::DataInformationEndianess byteOrderFromString(const QString &string, const LoggerWithContext &logger)
Definition: parserutils.cpp:67
ParserInfo::name
QString name
Definition: parserutils.h:58
OsdParserInfo
Definition: osdparser.h:44
ParserStrings::PROPERTY_STRUCT_NAME
const QString PROPERTY_STRUCT_NAME
Definition: parserutils.h:154
DataInformationFactory::newArray
ArrayDataInformation * newArray(const ArrayParsedData &pd)
Definition: datainformationfactory.cpp:203
CommonParsedData::validationFunc
QScriptValue validationFunc
Definition: datainformationfactory.h:48
ParserStrings::PROPERTY_MAX_CHAR_COUNT
const QString PROPERTY_MAX_CHAR_COUNT
Definition: parserutils.h:142
StructOrUnionParsedData
Definition: datainformationfactory.h:123
ParserStrings::PROPERTY_NAME
const QString PROPERTY_NAME
Definition: parserutils.h:114
ParserStrings::PROPERTY_ALTERNATIVES
const QString PROPERTY_ALTERNATIVES
Definition: parserutils.h:151
ParsedNumber::isValid
bool isValid
Definition: parserutils.h:89
AbstractBitfieldDataInformation
Definition: abstractbitfielddatainformation.h:28
PrimitiveDataInformation
A base class for all primitive data elements (e.g.
Definition: primitivedatainformation.h:34
ArrayParsedData
Definition: datainformationfactory.h:93
ParserStrings::TYPE_STRUCT
const QString TYPE_STRUCT
Definition: parserutils.h:102
CommonParsedData::endianess
DataInformation::DataInformationEndianess endianess
Definition: datainformationfactory.h:51
StringParsedData
Definition: datainformationfactory.h:82
StringDataInformation
Definition: stringdatainformation.h:39
QMap< AllPrimitiveTypes, QString >
ParserStrings::PROPERTY_TERMINATED_BY
const QString PROPERTY_TERMINATED_BY
Definition: parserutils.h:144
DataInformation::logError
QDebug logError() const
just a shorthand for logger->error(this)
Definition: datainformation.h:324
SingleElementOsdChildrenParser::SingleElementOsdChildrenParser
SingleElementOsdChildrenParser(const OsdParserInfo &info, QDomElement element)
Definition: osdparser.cpp:596
TaggedUnionParsedData::Alternatives::name
QString name
Definition: datainformationfactory.h:111
ParserInfo::warn
QDebug warn() const
Definition: parserutils.h:68
StructureDataInformation
A class holding the data of a struct for Okteta.
Definition: structuredatainformation.h:28
ParserStrings::PROPERTY_DEFAULT_CHILDREN
const QString PROPERTY_DEFAULT_CHILDREN
Definition: parserutils.h:152
AbstractStructureParser
Definition: abstractstructureparser.h:36
DataInformationFactory::newBitfield
AbstractBitfieldDataInformation * newBitfield(const BitfieldParsedData &pd)
Definition: datainformationfactory.cpp:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal