cmd.hpp 3.0 KB

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