set_cmd_line.hpp
Go to the documentation of this file.
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
10#pragma once
11
12#include <memory>
13
15#include <boost/range/algorithm/copy.hpp>
16#include <boost/shared_array.hpp>
17
19{
20
21 template <class String>
23 {
24 private:
25 using Char = typename String::value_type;
26
27 public:
28 explicit set_cmd_line_(const String& s) : cmd_line_(new Char[s.size() + 1])
29 {
30 boost::copy(s, cmd_line_.get());
31 cmd_line_[s.size()] = 0;
32 }
33
34 template <class WindowsExecutor>
35 void
36 on_CreateProcess_setup(WindowsExecutor& e) const
37 {
38 e.cmd_line = cmd_line_.get();
39 }
40
41 private:
42 boost::shared_array<Char> cmd_line_;
43 };
44
45#if defined(_UNICODE) || defined(UNICODE)
46 inline set_cmd_line_<std::wstring>
47 set_cmd_line(const wchar_t* ws)
48 {
49 return set_cmd_line_<std::wstring>(ws);
50 }
51
52 inline set_cmd_line_<std::wstring>
53 set_cmd_line(const std::wstring& ws)
54 {
55 return set_cmd_line_<std::wstring>(ws);
56 }
57#else
58 inline set_cmd_line_<std::string>
59 set_cmd_line(const char* s)
60 {
62 }
63
64 inline set_cmd_line_<std::string>
65 set_cmd_line(const std::string& s)
66 {
68 }
69#endif
70
71} // namespace boost::process::windows::initializers
void on_CreateProcess_setup(WindowsExecutor &e) const
set_cmd_line_< std::string > set_cmd_line(const char *s)