TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / process-cpp-minimal / include / core / posix / this_process.h
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18
19 #ifndef CORE_POSIX_THIS_PROCESS_H_
20 #define CORE_POSIX_THIS_PROCESS_H_
21
22 #include <core/posix/visibility.h>
23
24 #include <functional>
25 #include <iosfwd>
26 #include <string>
27 #include <system_error>
28
29 namespace core
30 {
31 namespace posix
32 {
33 class Process;
34 namespace this_process
35 {
36 namespace env
37 {
38 /**
39  * @brief for_each invokes a functor for every key-value pair in the environment.
40  * @param [in] functor Invoked for every key-value pair.
41  */
42 CORE_POSIX_DLL_PUBLIC void for_each(
43         const std::function<void(const std::string&, const std::string&)>& functor) noexcept(true);
44
45 /**
46  * @brief get queries the value of an environment variable.
47  * @throw std::runtime_error if there is no variable with the given key defined in the env.
48  * @param [in] key Name of the variable to query the value for.
49  * @return Contents of the variable.
50  */
51 CORE_POSIX_DLL_PUBLIC std::string get_or_throw(const std::string& key);
52
53 /**
54  * @brief get queries the value of an environment variable.
55  * @param [in] key Name of the variable to query the value for.
56  * @param [in] default_value Default value to return when key is not present in the environment.
57  * @return Contents of the variable or an empty string if the variable is not defined.
58  */
59 CORE_POSIX_DLL_PUBLIC std::string get(
60         const std::string& key,
61         const std::string& default_value = std::string()) noexcept(true);
62
63 /**
64  * @brief unset_or_throw removes the variable with name key from the environment.
65  * @throw std::system_error in case of errors.
66  * @param [in] key Name of the variable to unset.
67  */
68 CORE_POSIX_DLL_PUBLIC void unset_or_throw(const std::string& key);
69
70 /**
71  * @brief unset removes the variable with name key from the environment.
72  * @return false in case of errors, true otherwise.
73  * @param [in] key Name of the variable to unset.
74  * @param [out] se Receives error details if unset returns false.
75  */
76 CORE_POSIX_DLL_PUBLIC bool unset(const std::string& key,
77                             std::error_code& se) noexcept(true);
78
79 /**
80  * @brief set_or_throw will adjust the contents of the variable identified by key to the provided value.
81  * @throw std::system_error in case of errors.
82  * @param [in] key Name of the variable to set the value for.
83  * @param [in] value New contents of the variable.
84  */
85 CORE_POSIX_DLL_PUBLIC void set_or_throw(const std::string& key,
86                                    const std::string& value);
87 /**
88  * @brief set will adjust the contents of the variable identified by key to the provided value.
89  * @return false in case of errors, true otherwise.
90  * @param [in] key Name of the variable to set the value for.
91  * @param [in] value New contents of the variable.
92  * @param [out] se Receives the details in case of errors.
93  */
94 CORE_POSIX_DLL_PUBLIC bool set(const std::string &key,
95                           const std::string &value,
96                           std::error_code& se) noexcept(true);
97 }
98
99 /**
100   * @brief Returns a Process instance corresponding to this process.
101   */
102 CORE_POSIX_DLL_PUBLIC Process instance() noexcept(true);
103
104 /**
105  * @brief Query the parent of the process.
106  * @return The parent of the process.
107  */
108 CORE_POSIX_DLL_PUBLIC Process parent() noexcept(true);
109
110 /**
111  * @brief Access this process's stdin.
112  */
113 CORE_POSIX_DLL_PUBLIC std::istream& cin() noexcept(true);
114
115 /**
116  * @brief Access this process's stdout.
117  */
118 CORE_POSIX_DLL_PUBLIC std::ostream& cout() noexcept(true);
119
120 /**
121  * @brief Access this process's stderr.
122  */
123 CORE_POSIX_DLL_PUBLIC std::ostream& cerr() noexcept(true);
124 }
125 }
126 }
127
128 #endif // CORE_POSIX_THIS_PROCESS_H_