00001 /****************************************************************************** 00002 STDR Simulator - Simple Two DImensional Robot Simulator 00003 Copyright (C) 2013 STDR Simulator 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 3 of the License, or 00007 (at your option) any later version. 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 00016 Authors : 00017 * Manos Tsardoulias, etsardou@gmail.com 00018 * Aris Thallas, aris.thallas@gmail.com 00019 * Chris Zalidis, zalidis@gmail.com 00020 ******************************************************************************/ 00021 00022 #ifndef STDR_PARSER_BASE 00023 #define STDR_PARSER_BASE 00024 00025 #include "stdr_parser/stdr_parser_msg_creator.h" 00026 #include "stdr_parser/stdr_parser_validator.h" 00027 #include "stdr_parser/stdr_parser_xml_file_writer.h" 00028 #include "stdr_parser/stdr_parser_yaml_file_writer.h" 00029 #include "stdr_parser/stdr_xml_parser.h" 00030 #include "stdr_parser/stdr_yaml_parser.h" 00031 00036 namespace stdr_parser 00037 { 00042 class Parser 00043 { 00044 private: 00045 00047 static Node* base_node_; 00048 00054 static void parse(std::string file_name); 00055 00061 static bool eliminateFilenames(Node* n); 00062 00068 static bool mergeNodes(Node* n); 00069 00075 static void mergeNodesValues(Node* n); 00076 00081 Parser(void); 00082 00083 public: 00084 00090 template <class T> 00091 static T createMessage(std::string file_name) 00092 { 00093 try 00094 { 00095 parse(file_name); 00096 } 00097 catch(ParserException ex) 00098 { 00099 base_node_->unallocateChildren(); 00100 delete base_node_; 00101 throw ex; 00102 } 00103 T msg = MessageCreator::createMessage<T>(base_node_,0); 00104 base_node_->unallocateChildren(); 00105 delete base_node_; 00106 return msg; 00107 } 00108 00115 template <class T> 00116 static void saveMessage(T msg,std::string file_name) 00117 { 00118 if(file_name.find(".xml") != std::string::npos) 00119 { 00120 XmlFileWriter::messageToFile(msg,file_name); 00121 } 00122 else if(file_name.find(".yaml") != std::string::npos) 00123 { 00124 YamlFileWriter::messageToFile(msg,file_name); 00125 } 00126 } 00127 00128 }; 00129 } 00130 #endif