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 <Windows.h>
14 #include <boost/range/numeric.hpp>
15 #include <boost/range/algorithm/copy.hpp>
16 #include <boost/range/algorithm/for_each.hpp>
17 #include <boost/shared_array.hpp>
18 #include <iterator>
19 #include <cstddef>
20 
22 {
23 
24  template <class Range, bool Unicode>
25  class set_env_ : public initializer_base
26  {
27  private:
28  using String = typename Range::value_type;
29  using Char = typename String::value_type;
30 
31  static std::size_t add_size(std::size_t size, const String& s)
32  {
33  return size + s.size() + 1u;
34  }
35 
36  struct copy
37  {
38  Char* it_;
39 
40  copy(Char* it) : it_(it) {}
41 
42  void operator()(const String& s)
43  {
44  it_ = boost::copy(s, it_);
45  *it_ = 0;
46  ++it_;
47  }
48  };
49 
50  public:
51  set_env_(const Range& envs)
52  : size_(boost::accumulate(envs, 0, add_size) + 1),
53  env_(new Char[size_])
54  {
55  boost::for_each(envs, copy(env_.get()));
56  env_[size_ - 1] = 0;
57  }
58 
59  template <class WindowsExecutor>
60  void on_CreateProcess_setup(WindowsExecutor& e) const
61  {
62  e.env = env_.get();
63  if (Unicode)
64  {
65  e.creation_flags |= CREATE_UNICODE_ENVIRONMENT;
66  }
67  }
68 
69  private:
70  std::size_t size_;
71  boost::shared_array<Char> env_;
72  };
73 
74 #if defined(_UNICODE) || defined(UNICODE)
75  template <class Range>
76  set_env_<Range, true> set_env(const Range& envs)
77  {
78  return set_env_<Range, true>(envs);
79  }
80 #else
81  template <class Range>
82  set_env_<Range, false> set_env(const Range& envs)
83  {
84  return set_env_<Range, false>(envs);
85  }
86 #endif
87 
88 }
boost
Definition: ApplicationOptions.h:37
boost::process::windows::initializers::set_env_::on_CreateProcess_setup
void on_CreateProcess_setup(WindowsExecutor &e) const
Definition: set_env.hpp:60
boost::process::windows::initializers
Definition: bind_stderr.hpp:16
boost::process::windows::initializers::set_env_::set_env_
set_env_(const Range &envs)
Definition: set_env.hpp:51
boost::process::windows::initializers::set_env
set_env_< Range, false > set_env(const Range &envs)
Definition: set_env.hpp:82
copy
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: license.txt:39
boost::process::windows::initializers::set_env_
Definition: set_env.hpp:25
initializer_base.hpp
boost::process::windows::initializers::initializer_base
Definition: initializer_base.hpp:15
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33