start_dir.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_PROCESS_START_IN_DIR_HPP
  10. #define BOOST_PROCESS_START_IN_DIR_HPP
  11. #include <boost/process/detail/config.hpp>
  12. #include <boost/process/detail/handler.hpp>
  13. #include <boost/process/locale.hpp>
  14. #include <boost/process/detail/traits/wchar_t.hpp>
  15. #if defined (BOOST_POSIX_API)
  16. #include <boost/process/detail/posix/start_dir.hpp>
  17. #elif defined (BOOST_WINDOWS_API)
  18. #include <boost/process/detail/windows/start_dir.hpp>
  19. #endif
  20. #include <boost/process/detail/config.hpp>
  21. #include <string>
  22. #include <boost/filesystem/path.hpp>
  23. /** \file boost/process/start_dir.hpp
  24. *
  25. Header which provides the start_dir property, which allows to set the directory
  26. the process shall be started in.
  27. \xmlonly
  28. <programlisting>
  29. namespace boost {
  30. namespace process {
  31. <emphasis>unspecified</emphasis> <globalname alt="boost::process::start_dir">start_dir</globalname>;
  32. }
  33. }
  34. </programlisting>
  35. \endxmlonly
  36. */
  37. namespace boost { namespace process { namespace detail {
  38. struct start_dir_
  39. {
  40. constexpr start_dir_() {};
  41. template<typename Char>
  42. api::start_dir_init<Char> operator()(const std::basic_string<Char> & st) const {return {st}; }
  43. template<typename Char>
  44. api::start_dir_init<Char> operator()(std::basic_string<Char> && s) const {return {std::move(s)}; }
  45. template<typename Char>
  46. api::start_dir_init<Char> operator()(const Char* s) const {return {s}; }
  47. api::start_dir_init<typename boost::filesystem::path::value_type>
  48. operator()(const boost::filesystem::path & st) const {return {st.native()}; }
  49. template<typename Char>
  50. api::start_dir_init<Char> operator= (const std::basic_string<Char> & st) const {return {st}; }
  51. template<typename Char>
  52. api::start_dir_init<Char> operator= (std::basic_string<Char> && s) const {return {std::move(s)}; }
  53. template<typename Char>
  54. api::start_dir_init<Char> operator= (const Char* s) const {return {s}; }
  55. api::start_dir_init<typename boost::filesystem::path::value_type>
  56. operator= (const boost::filesystem::path & st) const {return {st.native()}; }
  57. };
  58. template<> struct is_wchar_t<api::start_dir_init<wchar_t>> : std::true_type {};
  59. template<>
  60. struct char_converter<char, api::start_dir_init<wchar_t>>
  61. {
  62. static api::start_dir_init<char> conv(const api::start_dir_init<wchar_t> & in)
  63. {
  64. return api::start_dir_init<char>{::boost::process::detail::convert(in.str())};
  65. }
  66. };
  67. template<>
  68. struct char_converter<wchar_t, api::start_dir_init<char>>
  69. {
  70. static api::start_dir_init<wchar_t> conv(const api::start_dir_init<char> & in)
  71. {
  72. return api::start_dir_init<wchar_t>{::boost::process::detail::convert(in.str())};
  73. }
  74. };
  75. }
  76. /**
  77. To set the start dir, the `start_dir` property is provided.
  78. The valid operations are the following:
  79. \code{.cpp}
  80. start_dir=path
  81. start_dir(path)
  82. \endcode
  83. It can be used with `std::string`, `std::wstring` and `boost::filesystem::path`.
  84. */
  85. constexpr ::boost::process::detail::start_dir_ start_dir;
  86. }}
  87. #endif