Package.cpp
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 Dennis Weigelt
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#include "Package.h"
27
28#include <filesystem>
29#ifndef _WIN32
30#include <fcntl.h> /* Definition of AT_* constants */
31#include <unistd.h>
32#endif
34using namespace ScenarioManager;
35
36Data_Structure::Package::Package(std::string name, std::string path, std::string scenarioPath) :
37 name(name),
38 path(path),
39 scenarioPath(scenarioPath),
40 scenarios(new std::vector<Data_Structure::ScenarioPtr>()),
41 applications(new std::vector<Data_Structure::ApplicationPtr>())
42{
43}
44
46 name(other.name), path(other.path)
47{
48}
49
50std::string
52{
53 return this->name;
54}
55
56std::string
58{
59 return this->path;
60}
61
62std::string
64{
65 return this->scenarioPath;
66}
67
68bool
70{
72
73 ARMARX_VERBOSE << scenarioPath;
74
75 return true;
76
77 // bool writable = faccessat(0, scenarioPath.c_str(), W_OK, AT_EACCESS) == 0;
78 // if (!writable)
79 // {
80 // std::filesystem::path scenarioDir(scenarioPath.c_str());
81 // if (!std::filesystem::is_directory(scenarioDir))
82 // {
83 // if (std::filesystem::create_directory(scenarioDir))
84 // {
85 // ARMARX_DEBUG << "Created Scenario dir for Package " << name;
86 // writable = true;
87 // }
88 // else
89 // {
90 // ARMARX_DEBUG << "Failed to create Scenario dir for Package " << name << " please check if you have the certain permissions";
91 // }
92 // }
93 // }
94 // ARMARX_DEBUG << scenarioPath << " is writeable: " << writable;
95 // return writable;
96}
97
100{
101 return this->scenarios;
102}
103
106{
107 return this->applications;
108}
109
110void
112{
113 scenarios->push_back(scenario);
114}
115
116void
118{
119 for (auto it = scenarios->begin(); it != scenarios->end(); ++it)
120 {
121 if ((*it)->getName().compare(scenario->getName()) == 0 &&
122 (*it)->getPackage()->getName().compare(scenario->getPackage()->getName()) == 0)
123 {
124 scenarios->erase(it);
125 return;
126 }
127 }
128}
129
130void
132{
133 applications->push_back(application);
134}
135
137Data_Structure::Package::getScenarioByName(std::string name) //drĂ¼ber schauen kp ...
138{
139 for (std::vector<ScenarioPtr>::iterator iter = scenarios->begin(); iter != scenarios->end();
140 ++iter)
141 {
142 if (iter->get()->getName().compare(name) == 0)
143 {
144 return *iter;
145 }
146 }
147 return ScenarioPtr();
148}
149
151Data_Structure::Package::getApplicationByName(std::string name) //same as getScenarioByName(...)
152{
153 for (std::vector<ApplicationPtr>::iterator iter = applications->begin();
154 iter != applications->end();
155 ++iter)
156 {
157 if (iter->get()->getName().compare(name) == 0)
158 {
159 return *iter;
160 }
161 }
162 return ApplicationPtr();
163}
Class containing data about a package, its scenarios and its applications.
Definition Package.h:47
ScenarioPtr getScenarioByName(std::string name)
Returns a Scenario contained in this package that has the given name.
Definition Package.cpp:137
void addScenario(ScenarioPtr scenario)
Adds a Scenario to this package.
Definition Package.cpp:111
Package(std::string name, std::string path, std::string scenarioPath)
Constructor that sets the name and the path of the package.
Definition Package.cpp:36
void addApplication(ApplicationPtr application)
Adds an Application to this package.
Definition Package.cpp:131
ApplicationVectorPtr getApplications()
Definition Package.cpp:105
void removeScenario(ScenarioPtr scenario)
Definition Package.cpp:117
ApplicationPtr getApplicationByName(std::string name)
Returns an Application contained in this package that has the given name.
Definition Package.cpp:151
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< Application > ApplicationPtr
std::shared_ptr< std::vector< ScenarioPtr > > ScenarioVectorPtr
Definition Scenario.h:37
std::shared_ptr< std::vector< ApplicationPtr > > ApplicationVectorPtr
#define ARMARX_TRACE
Definition trace.h:77