$darkmode
boost_path.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
23 #pragma once
24 
25 #include <fable/schema/path.hpp>
28 
29 #include <boost/filesystem/path.hpp>
30 #include <boost/process/search_path.hpp>
31 
32 namespace fable::schema {
33 
34 template <>
35 struct is_path<boost::filesystem::path> : std::true_type {};
36 
37 namespace detail {
38 
39 template <>
40 inline bool exists(const boost::filesystem::path& path) {
41  return boost::filesystem::exists(path);
42 }
43 
44 template <>
45 inline bool is_regular_file(const boost::filesystem::path& path) {
46  return boost::filesystem::is_regular_file(path);
47 }
48 
49 template <>
50 inline bool is_directory(const boost::filesystem::path& path) {
51  return boost::filesystem::is_directory(path);
52 }
53 
54 template <>
55 inline bool is_other(const boost::filesystem::path& path) {
56  return boost::filesystem::is_other(path);
57 }
58 
59 template <>
60 inline boost::filesystem::path canonical(const boost::filesystem::path& path) {
61  return boost::filesystem::canonical(path);
62 }
63 
64 template <>
65 inline std::optional<boost::filesystem::path> search_path(const boost::filesystem::path& executable) {
66  boost::filesystem::path path = boost::process::search_path(executable);
67  if (path.empty()) {
68  return std::nullopt;
69  }
70  return path;
71 }
72 
73 } // namespace detail
74 
75 } // namespace fable::schema
Definition: path.hpp:47