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

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • LoadSave
  • Plugins
  • gmlFileFormat
GmlGrammar.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
4  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "GmlGrammar.h"
21 
22 #include "GmlGraphParsingHelper.h"
23 #include "Document.h"
24 
25 #include <KDebug>
26 
27 
28 #define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<size_t>::max()
29 #define BOOST_SPIRIT_DEBUG 1
30 
31 namespace GmlParser
32 {
33 
34 GmlGraphParsingHelper* phelper = 0;
35 std::string lastKey = "";
36 QObject * lastInserted = 0;
37 DataStructurePtr actualdataType;
38 DataPtr actualNode;
39 PointerPtr actualEdge;
40 Document *document = 0;
41 
42 void beginList()
43 {
44  phelper->startList(QString::fromStdString(lastKey));
45 }
46 
47 void endList()
48 {
49  phelper->endList();
50 }
51 
52 void gotKey(const std::string& key)
53 {
54  lastKey = key.c_str();
55 // QString k = key.c_str();
56 // if (k.compare("dataType", Qt::CaseInsensitive) == 0){
57 // kDebug() << "create a graph";
58 // actualGraph = document->addGraph("new");
59 // lastInserted = actualGraph;
60 // }else if (k.compare("node", Qt::CaseInsensitive) == 0){
61 // kDebug() << "create a node";
62 // actualNode = actualGraph->addNode("new");
63 // lastInserted = actualNode;
64 // }else if (k.compare("edge", Qt::CaseInsensitive) == 0){
65 // kDebug() << "create a edge";
66 // }else {
67 // kDebug() << "Process atribute " << k;
68 // lastKey = key;
69 // }
70 
71 }
72 
73 void gotValue(const std::string& Value)
74 {
75  if (Value.empty()) {
76  return; //end of the list.
77  } else {
78  phelper->setAttribute(QString::fromStdString(lastKey), QString::fromStdString(Value));
79 // if (lastInserted){
80  if (!lastInserted) {
81  kError() << "Cannot specify data node value: internal error";
82  return;
83  }
84  if (lastKey == "id" && lastInserted){
85  lastInserted->setProperty("name", Value.c_str());
86  phelper->dataMap.insert(QString::fromStdString(Value), phelper->actualNode);
87  }
88 // lastInserted->setProperty(lastKey.c_str(), Value.c_str());
89 // }else{
90 // kDebug() << "ignoring keyvalue: "<< lastKey.c_str() << Value.c_str();
91 // }
92  }
93 }
94 
95 
96 void t()
97 {
98  std::cout << "Found whitespace.\n";
99 }
100 void t1(const std::string &key)
101 {
102  std::cout << "Found " << key << ".\n";
103 }
104 
105 bool parse(const QString& content, Document * doc)
106 {
107  QString tmpContent = content;
108  unsigned result;
109  phelper = new GmlGraphParsingHelper;
110  phelper->gd = doc;
111  typedef std::string::const_iterator iterator_type;
112  typedef GmlParser::roman<iterator_type> roman;
113 
114  roman roman_parser; // Our grammar
115 
116  int index;
117  while ((index = tmpContent.indexOf('#')) != -1) {
118  tmpContent.remove(index, tmpContent.indexOf('\n', index) - index);
119  }
120  std::string str = tmpContent.toStdString();
121  iterator_type iter = str.begin();
122  iterator_type end = str.end();
123 
124  bool r = parse(iter, end, roman_parser, result);
125 
126  if (r && iter == end) {
127  std::cout << "-------------------------\n";
128  std::cout << "Parsing succeeded\n";
129  std::cout << "result = " << result << std::endl;
130  std::cout << "-------------------------\n";
131  } else {
132  std::string rest(iter, end);
133  std::cout << "-------------------------\n";
134  std::cout << "Parsing failed\n";
135  std::cout << "stopped at: \": " << rest << "\"\n";
136  std::cout << "-------------------------\n";
137  }
138 
139  delete phelper;
140  return r;
141 }
142 }
GmlParser::GmlGraphParsingHelper::endList
void endList()
Definition: GmlGraphParsingHelper.cpp:69
GmlParser::gotValue
void gotValue(const std::string &Value)
Definition: GmlGrammar.cpp:73
GmlParser::GmlGraphParsingHelper::actualNode
DataPtr actualNode
Definition: GmlGraphParsingHelper.h:56
GmlParser::lastKey
std::string lastKey
Definition: GmlGrammar.cpp:35
DataStructurePtr
boost::shared_ptr< DataStructure > DataStructurePtr
Definition: CoreTypes.h:38
GmlParser::document
Document * document
Definition: GmlGrammar.cpp:40
GmlParser::GmlGraphParsingHelper::gd
Document * gd
Definition: GmlGraphParsingHelper.h:58
GmlParser::phelper
GmlGraphParsingHelper * phelper
Definition: GmlGrammar.cpp:34
QObject
GmlParser::GmlGraphParsingHelper::dataMap
QMap< QString, DataPtr > dataMap
Definition: GmlGraphParsingHelper.h:61
Document.h
GmlParser::parse
bool parse(const QString &content, Document *doc)
Definition: GmlGrammar.cpp:105
GmlParser::actualdataType
DataStructurePtr actualdataType
Definition: GmlGrammar.cpp:37
GmlParser::beginList
void beginList()
Definition: GmlGrammar.cpp:42
PointerPtr
boost::shared_ptr< Pointer > PointerPtr
Definition: CoreTypes.h:35
GmlParser::t1
void t1(const std::string &key)
Definition: GmlGrammar.cpp:100
GmlParser::gotKey
void gotKey(const std::string &key)
Definition: GmlGrammar.cpp:52
GmlParser::GmlGraphParsingHelper::setAttribute
void setAttribute(const QString &key, const QString &value)
Definition: GmlGraphParsingHelper.cpp:102
GmlGrammar.h
GmlParser::endList
void endList()
Definition: GmlGrammar.cpp:47
Document
Definition: Document.h:41
GmlParser::lastInserted
QObject * lastInserted
Definition: GmlGrammar.cpp:36
GmlParser::actualEdge
PointerPtr actualEdge
Definition: GmlGrammar.cpp:39
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
GmlParser::GmlGraphParsingHelper::startList
void startList(const QString &key)
Definition: GmlGraphParsingHelper.cpp:50
GmlParser::t
void t()
Definition: GmlGrammar.cpp:96
GmlParser::actualNode
DataPtr actualNode
Definition: GmlGrammar.cpp:38
GmlParser::roman
Definition: GmlGrammar.h:57
GmlParser::GmlGraphParsingHelper
Definition: GmlGraphParsingHelper.h:37
GmlGraphParsingHelper.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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