set_env.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 <cstddef>
13
#include <iterator>
14
15
#include <
boost/process/windows/initializers/initializer_base.hpp
>
16
#include <boost/range/algorithm/copy.hpp>
17
#include <boost/range/algorithm/for_each.hpp>
18
#include <boost/range/numeric.hpp>
19
#include <boost/shared_array.hpp>
20
21
#include <Windows.h>
22
23
namespace
boost::process::windows::initializers
24
{
25
26
template
<
class
Range,
bool
Unicode>
27
class
set_env_
:
public
initializer_base
28
{
29
private
:
30
using
String =
typename
Range::value_type;
31
using
Char =
typename
String::value_type;
32
33
static
std::size_t
34
add_size(std::size_t size,
const
String& s)
35
{
36
return
size + s.size() + 1u;
37
}
38
39
struct
copy
40
{
41
Char* it_;
42
43
copy(Char* it) : it_(it)
44
{
45
}
46
47
void
48
operator()(
const
String& s)
49
{
50
it_ = boost::copy(s, it_);
51
*it_ = 0;
52
++it_;
53
}
54
};
55
56
public
:
57
set_env_
(
const
Range& envs) :
58
size_(
boost
::accumulate(envs, 0, add_size) + 1), env_(new Char[size_])
59
{
60
boost::for_each(envs, copy(env_.get()));
61
env_[size_ - 1] = 0;
62
}
63
64
template
<
class
WindowsExecutor>
65
void
66
on_CreateProcess_setup
(WindowsExecutor& e)
const
67
{
68
e.env = env_.get();
69
if
(Unicode)
70
{
71
e.creation_flags |= CREATE_UNICODE_ENVIRONMENT;
72
}
73
}
74
75
private
:
76
std::size_t size_;
77
boost::shared_array<Char> env_;
78
};
79
80
#if defined(_UNICODE) || defined(UNICODE)
81
template
<
class
Range>
82
set_env_<Range, true>
83
set_env
(
const
Range& envs)
84
{
85
return
set_env_<Range, true>(envs);
86
}
87
#else
88
template
<
class
Range>
89
set_env_<Range, false>
90
set_env
(
const
Range& envs)
91
{
92
return
set_env_<Range, false>
(envs);
93
}
94
#endif
95
96
}
// namespace boost::process::windows::initializers
boost::process::windows::initializers::set_env_
Definition
set_env.hpp:28
boost::process::windows::initializers::set_env_::on_CreateProcess_setup
void on_CreateProcess_setup(WindowsExecutor &e) const
Definition
set_env.hpp:66
boost::process::windows::initializers::set_env_::set_env_
set_env_(const Range &envs)
Definition
set_env.hpp:57
boost::process::windows::initializers
Definition
bind_stderr.hpp:18
boost::process::windows::initializers::set_env
set_env_< Range, false > set_env(const Range &envs)
Definition
set_env.hpp:90
boost
Definition
ApplicationOptions.h:38
boost::process::windows::initializers::initializer_base
Definition
initializer_base.hpp:16
initializer_base.hpp
boost
process
windows
initializers
set_env.hpp
Generated by
1.13.2