1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 // Copyright (c) 2016 Klemens D. Morgenstern
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef BOOST_PROCESS_ARGS_HPP
12 #define BOOST_PROCESS_ARGS_HPP
13 
14 /** \file boost/process/args.hpp
15  *
16  *    This header provides the \xmlonly <globalname alt="boost::process::args">args</globalname>\endxmlonly property. It also provides the
17  *    alternative name \xmlonly <globalname alt="boost::process::argv">argv</globalname>\endxmlonly .
18  *
19  *
20 \xmlonly
21 <programlisting>
22 namespace boost {
23   namespace process {
24     <emphasis>unspecified</emphasis> <globalname alt="boost::process::args">args</globalname>;
25     <emphasis>unspecified</emphasis> <globalname alt="boost::process::argv">argv</globalname>;
26   }
27 }
28 </programlisting>
29 \endxmlonly
30  */
31 
32 
33 #include <boost/process/detail/basic_cmd.hpp>
34 #include <iterator>
35 
36 namespace boost { namespace process { namespace detail {
37 
38 struct args_
39 {
40     template<typename T>
41     using remove_reference_t = typename std::remove_reference<T>::type;
42     template<typename T>
43     using value_type = typename remove_reference_t<T>::value_type;
44 
45     template<typename T>
46     using vvalue_type = value_type<value_type<T>>;
47 
48     template <class Range>
operator ()boost::process::detail::args_49     arg_setter_<vvalue_type<Range>, true>     operator()(Range &&range) const
50     {
51         return arg_setter_<vvalue_type<Range>, true>(std::forward<Range>(range));
52     }
53     template <class Range>
operator +=boost::process::detail::args_54     arg_setter_<vvalue_type<Range>, true>     operator+=(Range &&range) const
55     {
56         return arg_setter_<vvalue_type<Range>, true>(std::forward<Range>(range));
57     }
58     template <class Range>
operator =boost::process::detail::args_59     arg_setter_<vvalue_type<Range>, false>    operator= (Range &&range) const
60     {
61         return arg_setter_<vvalue_type<Range>, false>(std::forward<Range>(range));
62     }
63     template<typename Char>
operator ()boost::process::detail::args_64     arg_setter_<Char, true>     operator()(std::basic_string<Char> && str) const
65     {
66         return arg_setter_<Char, true> (str);
67     }
68     template<typename Char>
operator +=boost::process::detail::args_69     arg_setter_<Char, true>     operator+=(std::basic_string<Char> && str) const
70     {
71         return arg_setter_<Char, true> (str);
72     }
73     template<typename Char>
operator =boost::process::detail::args_74     arg_setter_<Char, false>    operator= (std::basic_string<Char> && str) const
75     {
76         return arg_setter_<Char, false>(str);
77     }
78     template<typename Char>
operator ()boost::process::detail::args_79     arg_setter_<Char, true>     operator()(const std::basic_string<Char> & str) const
80     {
81         return arg_setter_<Char, true> (str);
82     }
83     template<typename Char>
operator +=boost::process::detail::args_84     arg_setter_<Char, true>     operator+=(const std::basic_string<Char> & str) const
85     {
86         return arg_setter_<Char, true> (str);
87     }
88     template<typename Char>
operator =boost::process::detail::args_89     arg_setter_<Char, false>    operator= (const std::basic_string<Char> & str) const
90     {
91         return arg_setter_<Char, false>(str);
92     }
93     template<typename Char>
operator ()boost::process::detail::args_94     arg_setter_<Char, true>     operator()(std::basic_string<Char> & str) const
95     {
96         return arg_setter_<Char, true> (str);
97     }
98     template<typename Char>
operator +=boost::process::detail::args_99     arg_setter_<Char, true>     operator+=(std::basic_string<Char> & str) const
100     {
101         return arg_setter_<Char, true> (str);
102     }
103     template<typename Char>
operator =boost::process::detail::args_104     arg_setter_<Char, false>    operator= (std::basic_string<Char> & str) const
105     {
106         return arg_setter_<Char, false>(str);
107     }
108     template<typename Char>
operator ()boost::process::detail::args_109     arg_setter_<Char, true>     operator()(const Char* str) const
110     {
111         return arg_setter_<Char, true> (str);
112     }
113     template<typename Char>
operator +=boost::process::detail::args_114     arg_setter_<Char, true>     operator+=(const Char* str) const
115     {
116         return arg_setter_<Char, true> (str);
117     }
118     template<typename Char>
operator =boost::process::detail::args_119     arg_setter_<Char, false>    operator= (const Char* str) const
120     {
121         return arg_setter_<Char, false>(str);
122     }
123 //    template<typename Char, std::size_t Size>
124 //    arg_setter_<Char, true>     operator()(const Char (&str) [Size]) const
125 //    {
126 //        return arg_setter_<Char, true> (str);
127 //    }
128 //    template<typename Char, std::size_t Size>
129 //    arg_setter_<Char, true>     operator+=(const Char (&str) [Size]) const
130 //    {
131 //        return arg_setter_<Char, true> (str);
132 //    }
133 //    template<typename Char, std::size_t Size>
134 //    arg_setter_<Char, false>    operator= (const Char (&str) [Size]) const
135 //    {
136 //        return arg_setter_<Char, false>(str);
137 //    }
138 
operator ()boost::process::detail::args_139     arg_setter_<char, true> operator()(std::initializer_list<const char*> &&range) const
140     {
141         return arg_setter_<char, true>(range.begin(), range.end());
142     }
operator +=boost::process::detail::args_143     arg_setter_<char, true> operator+=(std::initializer_list<const char*> &&range) const
144     {
145         return arg_setter_<char, true>(range.begin(), range.end());
146     }
operator =boost::process::detail::args_147     arg_setter_<char, false> operator= (std::initializer_list<const char*> &&range) const
148     {
149         return arg_setter_<char, false>(range.begin(), range.end());
150     }
operator ()boost::process::detail::args_151     arg_setter_<char, true> operator()(std::initializer_list<std::string> &&range) const
152     {
153         return arg_setter_<char, true>(range.begin(), range.end());
154     }
operator +=boost::process::detail::args_155     arg_setter_<char, true> operator+=(std::initializer_list<std::string> &&range) const
156     {
157         return arg_setter_<char, true>(range.begin(), range.end());
158     }
operator =boost::process::detail::args_159     arg_setter_<char, false> operator= (std::initializer_list<std::string> &&range) const
160     {
161         return arg_setter_<char, false>(range.begin(), range.end());
162     }
163 
operator ()boost::process::detail::args_164     arg_setter_<wchar_t, true> operator()(std::initializer_list<const wchar_t*> &&range) const
165     {
166         return arg_setter_<wchar_t, true>(range.begin(), range.end());
167     }
operator +=boost::process::detail::args_168     arg_setter_<wchar_t, true> operator+=(std::initializer_list<const wchar_t*> &&range) const
169     {
170         return arg_setter_<wchar_t, true>(range.begin(), range.end());
171     }
operator =boost::process::detail::args_172     arg_setter_<wchar_t, false> operator= (std::initializer_list<const wchar_t*> &&range) const
173     {
174         return arg_setter_<wchar_t, false>(range.begin(), range.end());
175     }
operator ()boost::process::detail::args_176     arg_setter_<wchar_t, true> operator()(std::initializer_list<std::wstring> &&range) const
177     {
178         return arg_setter_<wchar_t, true>(range.begin(), range.end());
179     }
operator +=boost::process::detail::args_180     arg_setter_<wchar_t, true> operator+=(std::initializer_list<std::wstring> &&range) const
181     {
182         return arg_setter_<wchar_t, true>(range.begin(), range.end());
183     }
operator =boost::process::detail::args_184     arg_setter_<wchar_t, false> operator= (std::initializer_list<std::wstring> &&range) const
185     {
186         return arg_setter_<wchar_t, false>(range.begin(), range.end());
187     }
188 };
189 
190 
191 }
192 /**
193 
194 The `args` property allows to explicitly set arguments for the execution. The
195 name of the executable will always be the first element in the arg-vector.
196 
197 \section args_details Details
198 
199 \subsection args_operations Operations
200 
201 \subsubsection args_set_var Setting values
202 
203 To set a the argument vector the following syntax can be used.
204 
205 \code{.cpp}
206 args = value;
207 args(value);
208 \endcode
209 
210 `std::initializer_list` is among the allowed types, so the following syntax is also possible.
211 
212 \code{.cpp}
213 args = {value1, value2};
214 args({value1, value2});
215 \endcode
216 
217 Below the possible types for `value` are listed, with `char_type` being either `char` or `wchar_t`.
218 
219 \paragraph args_set_var_value value
220 
221  - `std::basic_string<char_type>`
222  - `const char_type * `
223  - `std::initializer_list<const char_type *>`
224  - `std::vector<std::basic_string<char_type>>`
225 
226 Additionally any range of `std::basic_string<char_type>` can be passed.
227 
228 \subsubsection args_append_var Appending values
229 
230 To append a the argument vector the following syntax can be used.
231 
232 \code{.cpp}
233 args += value;
234 \endcode
235 
236 `std::initializer_list` is among the allowed types, so the following syntax is also possible.
237 
238 \code{.cpp}
239 args += {value1, value2};
240 \endcode
241 
242 Below the possible types for `value` are listed, with `char_type` being either `char` or `wchar_t`.
243 
244 \paragraph args_append_var_value value
245 
246  - `std::basic_string<char_type>`
247  - `const char_type * `
248  - `std::initializer_list<const char_type *>`
249  - `std::vector<std::basic_string<char_type>>`
250 
251 Additionally any range of `std::basic_string<char_type>` can be passed.
252 
253 
254 \subsection args_example Example
255 
256 The overload form is used when more than one string is passed, from the second one forward.
257 I.e. the following expressions have the same results:
258 
259 \code{.cpp}
260 spawn("gcc", "--version");
261 spawn("gcc", args ="--version");
262 spawn("gcc", args+="--version");
263 spawn("gcc", args ={"--version"});
264 spawn("gcc", args+={"--version"});
265 \endcode
266 
267 \note A string will be parsed and set in quotes if it has none and contains spaces.
268 
269 
270  */
271 constexpr boost::process::detail::args_ args{};
272 
273 ///Alias for \xmlonly <globalname alt="boost::process::args">args</globalname> \endxmlonly .
274 constexpr boost::process::detail::args_ argv{};
275 
276 
277 }}
278 
279 #endif
280