PackagePath.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::PackagePath
19  * @author Christian R. G. Dreher <c.dreher@kit.edu>
20  * @date 2020
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
27 
28 
29 // ArmarX
31 
32 
33 armarx::PackagePath::PackagePath(const std::string& package_name, const std::filesystem::path& rel_path) :
34  m_pp{package_name, rel_path.string()}
35 {
36 
37 }
38 
39 
40 armarx::PackagePath::PackagePath(const data::PackagePath& pp) :
41  m_pp{pp}
42 {
43 
44 }
45 
46 
48 {
49 
50 }
51 
52 
53 std::filesystem::path
54 armarx::PackagePath::toSystemPath(const data::PackagePath& pp)
55 {
56  CMakePackageFinder pkg_finder(pp.package);
57  const std::filesystem::path pkg_data_dir{pkg_finder.getDataDir()};
58 
59  if (pkg_data_dir.empty())
60  {
61  throw PackageNotFoundException{pp.package};
62  }
63 
64  return pkg_data_dir / std::filesystem::path{pp.package} / pp.path;
65 }
66 
67 
68 std::filesystem::path
70 {
71  return PackagePath::toSystemPath(m_pp);
72 }
73 
74 
75 armarx::data::PackagePath
77 {
78  return m_pp;
79 }
80 
81 
82 namespace armarx
83 {
84 
85  std::ostream& operator<<(std::ostream& os, const armarx::PackagePath& packagePath)
86  {
87  os << "PackagePath { " << packagePath.serialize().package << " : " << packagePath.serialize().path << " }";
88  return os;
89  }
90 
91 }
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::PackageNotFoundException
Definition: PackagePath.h:42
armarx::PackagePath::PackagePath
PackagePath()=default
armarx::PackagePath::serialize
data::PackagePath serialize() const
Definition: PackagePath.cpp:76
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
CMakePackageFinder.h
armarx::PackagePath::~PackagePath
virtual ~PackagePath()
Definition: PackagePath.cpp:47
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:221
armarx::PackagePath
Definition: PackagePath.h:55
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PackagePath::toSystemPath
std::filesystem::path toSystemPath() const
Definition: PackagePath.cpp:69
PackagePath.h