123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- // Copyright (c) 2006, 2007 Julio M. Merino Vidal
- // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
- // Copyright (c) 2009 Boris Schaeling
- // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
- // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
- // Copyright (c) 2016 Klemens D. Morgenstern
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #ifndef BOOST_PROCESS_ARGS_HPP
- #define BOOST_PROCESS_ARGS_HPP
- /** \file boost/process/args.hpp
- *
- * This header provides the \xmlonly <globalname alt="boost::process::args">args</globalname>\endxmlonly property. It also provides the
- * alternative name \xmlonly <globalname alt="boost::process::argv">argv</globalname>\endxmlonly .
- *
- *
- \xmlonly
- <programlisting>
- namespace boost {
- namespace process {
- <emphasis>unspecified</emphasis> <globalname alt="boost::process::args">args</globalname>;
- <emphasis>unspecified</emphasis> <globalname alt="boost::process::argv">argv</globalname>;
- }
- }
- </programlisting>
- \endxmlonly
- */
- #include <boost/process/detail/basic_cmd.hpp>
- #include <iterator>
- namespace boost { namespace process { namespace detail {
- struct args_
- {
- template<typename T>
- using remove_reference_t = typename std::remove_reference<T>::type;
- template<typename T>
- using value_type = typename remove_reference_t<T>::value_type;
- template<typename T>
- using vvalue_type = value_type<value_type<T>>;
- template <class Range>
- arg_setter_<vvalue_type<Range>, true> operator()(Range &&range) const
- {
- return arg_setter_<vvalue_type<Range>, true>(std::forward<Range>(range));
- }
- template <class Range>
- arg_setter_<vvalue_type<Range>, true> operator+=(Range &&range) const
- {
- return arg_setter_<vvalue_type<Range>, true>(std::forward<Range>(range));
- }
- template <class Range>
- arg_setter_<vvalue_type<Range>, false> operator= (Range &&range) const
- {
- return arg_setter_<vvalue_type<Range>, false>(std::forward<Range>(range));
- }
- template<typename Char>
- arg_setter_<Char, true> operator()(std::basic_string<Char> && str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator+=(std::basic_string<Char> && str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, false> operator= (std::basic_string<Char> && str) const
- {
- return arg_setter_<Char, false>(str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator()(const std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator+=(const std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, false> operator= (const std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, false>(str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator()(std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator+=(std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, false> operator= (std::basic_string<Char> & str) const
- {
- return arg_setter_<Char, false>(str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator()(const Char* str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, true> operator+=(const Char* str) const
- {
- return arg_setter_<Char, true> (str);
- }
- template<typename Char>
- arg_setter_<Char, false> operator= (const Char* str) const
- {
- return arg_setter_<Char, false>(str);
- }
- // template<typename Char, std::size_t Size>
- // arg_setter_<Char, true> operator()(const Char (&str) [Size]) const
- // {
- // return arg_setter_<Char, true> (str);
- // }
- // template<typename Char, std::size_t Size>
- // arg_setter_<Char, true> operator+=(const Char (&str) [Size]) const
- // {
- // return arg_setter_<Char, true> (str);
- // }
- // template<typename Char, std::size_t Size>
- // arg_setter_<Char, false> operator= (const Char (&str) [Size]) const
- // {
- // return arg_setter_<Char, false>(str);
- // }
- arg_setter_<char, true> operator()(std::initializer_list<const char*> &&range) const
- {
- return arg_setter_<char, true>(range.begin(), range.end());
- }
- arg_setter_<char, true> operator+=(std::initializer_list<const char*> &&range) const
- {
- return arg_setter_<char, true>(range.begin(), range.end());
- }
- arg_setter_<char, false> operator= (std::initializer_list<const char*> &&range) const
- {
- return arg_setter_<char, false>(range.begin(), range.end());
- }
- arg_setter_<char, true> operator()(std::initializer_list<std::string> &&range) const
- {
- return arg_setter_<char, true>(range.begin(), range.end());
- }
- arg_setter_<char, true> operator+=(std::initializer_list<std::string> &&range) const
- {
- return arg_setter_<char, true>(range.begin(), range.end());
- }
- arg_setter_<char, false> operator= (std::initializer_list<std::string> &&range) const
- {
- return arg_setter_<char, false>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, true> operator()(std::initializer_list<const wchar_t*> &&range) const
- {
- return arg_setter_<wchar_t, true>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, true> operator+=(std::initializer_list<const wchar_t*> &&range) const
- {
- return arg_setter_<wchar_t, true>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, false> operator= (std::initializer_list<const wchar_t*> &&range) const
- {
- return arg_setter_<wchar_t, false>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, true> operator()(std::initializer_list<std::wstring> &&range) const
- {
- return arg_setter_<wchar_t, true>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, true> operator+=(std::initializer_list<std::wstring> &&range) const
- {
- return arg_setter_<wchar_t, true>(range.begin(), range.end());
- }
- arg_setter_<wchar_t, false> operator= (std::initializer_list<std::wstring> &&range) const
- {
- return arg_setter_<wchar_t, false>(range.begin(), range.end());
- }
- };
- }
- /**
- The `args` property allows to explicitly set arguments for the execution. The
- name of the executable will always be the first element in the arg-vector.
- \section args_details Details
- \subsection args_operations Operations
- \subsubsection args_set_var Setting values
- To set a the argument vector the following syntax can be used.
- \code{.cpp}
- args = value;
- args(value);
- \endcode
- `std::initializer_list` is among the allowed types, so the following syntax is also possible.
- \code{.cpp}
- args = {value1, value2};
- args({value1, value2});
- \endcode
- Below the possible types for `value` are listed, with `char_type` being either `char` or `wchar_t`.
- \paragraph args_set_var_value value
- - `std::basic_string<char_type>`
- - `const char_type * `
- - `std::initializer_list<const char_type *>`
- - `std::vector<std::basic_string<char_type>>`
- Additionally any range of `std::basic_string<char_type>` can be passed.
- \subsubsection args_append_var Appending values
- To append a the argument vector the following syntax can be used.
- \code{.cpp}
- args += value;
- \endcode
- `std::initializer_list` is among the allowed types, so the following syntax is also possible.
- \code{.cpp}
- args += {value1, value2};
- \endcode
- Below the possible types for `value` are listed, with `char_type` being either `char` or `wchar_t`.
- \paragraph args_append_var_value value
- - `std::basic_string<char_type>`
- - `const char_type * `
- - `std::initializer_list<const char_type *>`
- - `std::vector<std::basic_string<char_type>>`
- Additionally any range of `std::basic_string<char_type>` can be passed.
- \subsection args_example Example
- The overload form is used when more than one string is passed, from the second one forward.
- I.e. the following expressions have the same results:
- \code{.cpp}
- spawn("gcc", "--version");
- spawn("gcc", args ="--version");
- spawn("gcc", args+="--version");
- spawn("gcc", args ={"--version"});
- spawn("gcc", args+={"--version"});
- \endcode
- \note A string will be parsed and set in quotes if it has none and contains spaces.
- */
- constexpr boost::process::detail::args_ args{};
- ///Alias for \xmlonly <globalname alt="boost::process::args">args</globalname> \endxmlonly .
- constexpr boost::process::detail::args_ argv{};
- }}
- #endif
|