stdr_parser.h
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
22 #ifndef STDR_PARSER_BASE
23 #define STDR_PARSER_BASE
24 
31 
36 namespace stdr_parser
37 {
42  class Parser
43  {
44  private:
45 
47  static Node* base_node_;
48 
54  static void parse(std::string file_name);
55 
61  static bool eliminateFilenames(Node* n);
62 
68  static bool mergeNodes(Node* n);
69 
75  static void mergeNodesValues(Node* n);
76 
81  Parser(void);
82 
83  public:
84 
90  template <class T>
91  static T createMessage(std::string file_name)
92  {
93  try
94  {
95  parse(file_name);
96  }
97  catch(ParserException ex)
98  {
99  delete base_node_;
100  throw ex;
101  }
102  T msg = MessageCreator::createMessage<T>(base_node_,0);
103  delete base_node_;
104  return msg;
105  }
106 
113  template <class T>
114  static void saveMessage(T msg,std::string file_name)
115  {
116  if(file_name.find(".xml") != std::string::npos)
117  {
118  XmlFileWriter::messageToFile(msg,file_name);
119  }
120  else if(file_name.find(".yaml") != std::string::npos)
121  {
122  YamlFileWriter::messageToFile(msg,file_name);
123  }
124  }
125 
126  };
127 }
128 #endif
Implements the main functionalities of the high-level parser.
Definition: stdr_parser.h:42
static void messageToFile(T msg, std::string file_name)
Creates an yaml file from a message - template member function.
Parser(void)
Default constructor.
Definition: stdr_parser.cpp:34
static T createMessage(std::string file_name)
Creates a message from a file.
Definition: stdr_parser.h:91
static Node * base_node_
< Base node of the parsed file
Definition: stdr_parser.h:47
The main namespace for STDR GUI XML parser.
static void parse(std::string file_name)
Parses an xml file.
Definition: stdr_parser.cpp:44
static void saveMessage(T msg, std::string file_name)
Saves a stdr_msgs::Noise message to a file.
Definition: stdr_parser.h:114
static bool eliminateFilenames(Node *n)
Recursive function - Expands the &#39;filename&#39; nodes and eliminates them.
Definition: stdr_parser.cpp:94
static void mergeNodesValues(Node *n)
Merges the leaves of the xml tree, which are the value nodes.
static bool mergeNodes(Node *n)
Recursive function - Merges the nodes that do not exist in non_mergable_tags_.
Implements the main functionalities of the stdr parser tree.
static void messageToFile(T msg, std::string file_name)
Creates an xml file from a message - template member function.
Provides a parser exception. Publicly inherits from std::runtime_error. Used in robot handler...


stdr_parser
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Mon Jun 10 2019 15:14:54