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 <string>
29#include <vector>
30
32
35
36namespace armarx
37{
39}
40
42{
43 /**
44 * @class XMLScenarioParser
45 * @ingroup parser
46 * @brief This class provides different methods to parse and save scenario data in XML-Files.
47 * To save Scenario data between sessions, scenarios should be saved in XML-Files using the following
48 * format:
49 *
50 * <scenario name="name" lastChange="YYYY-MM-DD.hh:mm:ss" creation="YYYY-MM-DD.hh:mm:ss">
51 * ...
52 * <application instance="instanceName" name="applicationName" execPath="./pathToExec"></application>
53 * ...
54 * </scenario>
55 *
56 * This class only parses XML-Files of the specified format.
57 */
59 {
60
61 public:
62 /**
63 * Finds all .xml scenario files in a folder and returns a list of paths to them
64 * @param folder path to the folder
65 * @return list of paths of the scenario files
66 */
67 static std::vector<std::string> getScenariosFromFolder(const std::string& folder);
68
69 /**
70 * Parses a .xml scenario file and creates a Scenario object out of it.
71 * @param path to the scenario file
72 * @return a new Scenario object containing the data parsed out of the file
73 */
76 std::string name,
77 std::string subfolder = "");
80
81 // /**
82 // * @brief parseScenarioByFile parses an scenario file and returns the curresponding ScenarioPtr.
83 // * (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)
84 // * @param path path to scx file
85 // * @param package (optional else nullptr)
86 // * @return
87 // */
88 // ScenarioManager::Data_Structure::ScenarioPtr parseScenarioByFile(std::string path, Data_Structure::PackagePtr package);
89
90
91 /**
92 * Finds the package that contains the given scenario.
93 * @param scenario Scenario whose package is to be searched
94 * @param packages list of packages which are searched for the scenario
95 * @return the Package which contains the Scenario
96 */
100
101 /**
102 * Creates a new scenario with the given name within the given package
103 * @param name name of the new scenario
104 * @param package package the new scenario is created in
105 * @return new Scenario
106 */
108 createNewScenario(const std::string& name,
110
111 /**
112 * Saves a Scenario by recreating its .xml file based on its data
113 * @param scenario Scenario which is to be saved
114 */
115 static void saveScenario(const Data_Structure::ScenarioWPtr& scenario,
116 bool saveApplications);
117
118 static std::string getPackageNameFromScx(const std::string& path);
119
120 /**
121 * @brief isScenarioexistent
122 * @param name name of the scenario
123 * @param package package the scenario is located in
124 * @return returns true if the scenario exists in the file system else it returns false
125 */
126 static bool isScenarioexistent(const std::string& name,
128 const std::string& subPath = "");
129
130 private:
131 static void saveScenarioApplications(ScenarioManager::Data_Structure::ScenarioPtr scenario,
132 armarx::RapidXmlWriterNode& scenarioNode,
133 bool saveApplications);
134 static void saveScenarioGlobalConfig(ScenarioManager::Data_Structure::ScenarioPtr scenario);
135 };
136} // namespace ScenarioManager::Parser
This class provides different methods to parse and save scenario data in XML-Files.
static std::string getPackageNameFromScx(const std::string &path)
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.
static void saveScenario(const Data_Structure::ScenarioWPtr &scenario, bool saveApplications)
Saves a Scenario by recreating its .xml file based on its data.
static ScenarioManager::Data_Structure::PackagePtr getScenarioPackage(const ScenarioManager::Data_Structure::ScenarioPtr &scenario, const ScenarioManager::Data_Structure::PackageVectorPtr &packages)
parseScenarioByFile parses an scenario file and returns the curresponding ScenarioPtr.
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.
static bool isScenarioexistent(const std::string &name, ScenarioManager::Data_Structure::PackagePtr package, const std::string &subPath="")
isScenarioexistent
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.
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition Package.h:123
std::weak_ptr< Scenario > ScenarioWPtr
Definition Scenario.h:36
std::shared_ptr< Package > PackagePtr
Definition Package.h:122
This file offers overloads of toIce() and fromIce() functions for STL container types.