cmd.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifndef BOOST_PROCESS_DETAIL_CMD_LINE_HPP
  11. #define BOOST_PROCESS_DETAIL_CMD_LINE_HPP
  12. #include <boost/winapi/config.hpp>
  13. #include <boost/process/v1/detail/config.hpp>
  14. #include <boost/process/v1/detail/handler_base.hpp>
  15. #include <boost/process/v1/detail/traits/cmd_or_exe.hpp>
  16. #include <boost/process/v1/detail/traits/wchar_t.hpp>
  17. #if defined(BOOST_POSIX_API)
  18. #include <boost/process/v1/detail/posix/cmd.hpp>
  19. #elif defined(BOOST_WINDOWS_API)
  20. #include <boost/process/v1/detail/windows/cmd.hpp>
  21. #endif
  22. /** \file boost/process/cmd.hpp
  23. *
  24. * This header provides the \xmlonly <globalname alt="boost::process::v1::cmd">cmd</globalname>\endxmlonly property.
  25. *
  26. \xmlonly
  27. <programlisting>
  28. namespace boost {
  29. namespace process { BOOST_PROCESS_V1_INLINE namespace v1 {
  30. <emphasis>unspecified</emphasis> <globalname alt="boost::process::v1::cmd">cmd</globalname>;
  31. }
  32. }
  33. </programlisting>
  34. \endxmlonly
  35. */
  36. namespace boost { namespace process { BOOST_PROCESS_V1_INLINE namespace v1 { namespace detail {
  37. struct cmd_
  38. {
  39. constexpr cmd_() = default;
  40. template<typename Char>
  41. inline api::cmd_setter_<Char> operator()(const Char *s) const
  42. { return api::cmd_setter_<Char>(s);
  43. }
  44. template<typename Char>
  45. inline api::cmd_setter_<Char> operator= (const Char *s) const
  46. {
  47. return api::cmd_setter_<Char>(s);
  48. }
  49. template<typename Char>
  50. inline api::cmd_setter_<Char> operator()(const std::basic_string<Char> &s) const
  51. {
  52. return api::cmd_setter_<Char>(s);
  53. }
  54. template<typename Char>
  55. inline api::cmd_setter_<Char> operator= (const std::basic_string<Char> &s) const
  56. {
  57. return api::cmd_setter_<Char>(s);
  58. }
  59. };
  60. template<> struct is_wchar_t<api::cmd_setter_<wchar_t>> : std::true_type {};
  61. template<>
  62. struct char_converter<char, api::cmd_setter_<wchar_t>>
  63. {
  64. static api::cmd_setter_<char> conv(const api::cmd_setter_<wchar_t> & in)
  65. {
  66. return { ::boost::process::v1::detail::convert(in.str()) };
  67. }
  68. };
  69. template<>
  70. struct char_converter<wchar_t, api::cmd_setter_<char>>
  71. {
  72. static api::cmd_setter_<wchar_t> conv(const api::cmd_setter_<char> & in)
  73. {
  74. return { ::boost::process::v1::detail::convert(in.str()) };
  75. }
  76. };
  77. }
  78. /** The cmd property allows to explicitly set commands for the execution.
  79. The overload form applies when only one string is passed to a launching function.
  80. The string will be internally parsed and split at spaces.
  81. The following expressions are valid, with `value` being either a C-String or
  82. a `std::basic_string` with `char` or `wchar_t`.
  83. \code{.cpp}
  84. cmd="value";
  85. cmd(value);
  86. \endcode
  87. The property can only be used for assignments.
  88. */
  89. constexpr static ::boost::process::v1::detail::cmd_ cmd;
  90. }}}
  91. #endif