XMLScenarioParser.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #pragma once
27 
28 #include "../data_structure/Scenario.h"
29 #include "../data_structure/Package.h"
30 #include <string>
31 #include <vector>
33 
34 namespace armarx
35 {
36  class RapidXmlWriterNode;
37 }
38 
40 {
41  /**
42  * @class XMLScenarioParser
43  * @ingroup parser
44  * @brief This class provides different methods to parse and save scenario data in XML-Files.
45  * To save Scenario data between sessions, scenarios should be saved in XML-Files using the following
46  * format:
47  *
48  * <scenario name="name" lastChange="YYYY-MM-DD.hh:mm:ss" creation="YYYY-MM-DD.hh:mm:ss">
49  * ...
50  * <application instance="instanceName" name="applicationName" execPath="./pathToExec"></application>
51  * ...
52  * </scenario>
53  *
54  * This class only parses XML-Files of the specified format.
55  */
57  {
58 
59  public:
60  /**
61  * Finds all .xml scenario files in a folder and returns a list of paths to them
62  * @param folder path to the folder
63  * @return list of paths of the scenario files
64  */
65  static std::vector<std::string> getScenariosFromFolder(const std::string &folder);
66 
67  /**
68  * Parses a .xml scenario file and creates a Scenario object out of it.
69  * @param path to the scenario file
70  * @return a new Scenario object containing the data parsed out of the file
71  */
72  static ScenarioManager::Data_Structure::ScenarioPtr parseScenario(Data_Structure::PackagePtr package, std::string name, std::string subfolder = "");
74 
75  // /**
76  // * @brief parseScenarioByFile parses an scenario file and returns the curresponding ScenarioPtr.
77  // * (Used for CLI, it is possible to create an scenario without an package pointer. Warning Scenario without PackagePtr need to have an dependencie.config of the package in the CacheFolder)
78  // * @param path path to scx file
79  // * @param package (optional else nullptr)
80  // * @return
81  // */
82  // ScenarioManager::Data_Structure::ScenarioPtr parseScenarioByFile(std::string path, Data_Structure::PackagePtr package);
83 
84 
85  /**
86  * Finds the package that contains the given scenario.
87  * @param scenario Scenario whose package is to be searched
88  * @param packages list of packages which are searched for the scenario
89  * @return the Package which contains the Scenario
90  */
92 
93  /**
94  * Creates a new scenario with the given name within the given package
95  * @param name name of the new scenario
96  * @param package package the new scenario is created in
97  * @return new Scenario
98  */
100 
101  /**
102  * Saves a Scenario by recreating its .xml file based on its data
103  * @param scenario Scenario which is to be saved
104  */
105  static void saveScenario(const Data_Structure::ScenarioWPtr &scenario, bool saveApplications);
106 
107  static std::string getPackageNameFromScx(const std::string &path);
108 
109  /**
110  * @brief isScenarioexistent
111  * @param name name of the scenario
112  * @param package package the scenario is located in
113  * @return returns true if the scenario exists in the file system else it returns false
114  */
115  static bool isScenarioexistent(const std::string &name, ScenarioManager::Data_Structure::PackagePtr package, const std::string &subPath = "");
116  private:
117 
118  static void saveScenarioApplications(ScenarioManager::Data_Structure::ScenarioPtr scenario, armarx::RapidXmlWriterNode& scenarioNode, bool saveApplications);
119  static void saveScenarioGlobalConfig(ScenarioManager::Data_Structure::ScenarioPtr scenario);
120  };
121 }
ScenarioManager::Parser::XMLScenarioParser::getPackageNameFromScx
static std::string getPackageNameFromScx(const std::string &path)
Definition: XMLScenarioParser.cpp:369
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::Parser::XMLScenarioParser::parseScenario
static ScenarioManager::Data_Structure::ScenarioPtr parseScenario(Data_Structure::PackagePtr package, std::string name, std::string subfolder="")
Parses a .xml scenario file and creates a Scenario object out of it.
ScenarioManager::Parser::XMLScenarioParser::createNewScenario
static ScenarioManager::Data_Structure::ScenarioPtr createNewScenario(const std::string &name, ScenarioManager::Data_Structure::PackagePtr package)
Creates a new scenario with the given name within the given package.
Definition: XMLScenarioParser.cpp:280
ScenarioManager::Parser::XMLScenarioParser
This class provides different methods to parse and save scenario data in XML-Files....
Definition: XMLScenarioParser.h:56
ScenarioManager::Parser::XMLScenarioParser::saveScenario
static void saveScenario(const Data_Structure::ScenarioWPtr &scenario, bool saveApplications)
Saves a Scenario by recreating its .xml file based on its data.
Definition: XMLScenarioParser.cpp:322
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:122
ScenarioManager::Data_Structure::PackagePtr
std::shared_ptr< Package > PackagePtr
Definition: Package.h:121
ScenarioManager::Parser::XMLScenarioParser::isScenarioexistent
static bool isScenarioexistent(const std::string &name, ScenarioManager::Data_Structure::PackagePtr package, const std::string &subPath="")
isScenarioexistent
Definition: XMLScenarioParser.cpp:273
CMakePackageFinderCache.h
ScenarioManager::Parser
Definition: DependenciesGenerator.h:34
ScenarioManager::Parser::XMLScenarioParser::getScenariosFromFolder
static std::vector< std::string > getScenariosFromFolder(const std::string &folder)
Finds all .xml scenario files in a folder and returns a list of paths to them.
Definition: XMLScenarioParser.cpp:84
ScenarioManager::Data_Structure::ScenarioWPtr
std::weak_ptr< Scenario > ScenarioWPtr
Definition: Scenario.h:37
armarx::RapidXmlWriterNode
Definition: RapidXmlWriter.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ScenarioManager::Parser::XMLScenarioParser::getScenarioPackage
static ScenarioManager::Data_Structure::PackagePtr getScenarioPackage(const ScenarioManager::Data_Structure::ScenarioPtr &scenario, const ScenarioManager::Data_Structure::PackageVectorPtr &packages)
Finds the package that contains the given scenario.
Definition: XMLScenarioParser.cpp:355