File indexing completed on 2024-11-15 09:28:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP
0012 #define BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP
0013
0014 #include <boost/process/v2/detail/config.hpp>
0015 #include <boost/process/v2/cstring_ref.hpp>
0016
0017 #include <cwctype>
0018
0019 BOOST_PROCESS_V2_BEGIN_NAMESPACE
0020
0021 namespace environment
0022 {
0023
0024 using char_type = wchar_t;
0025
0026 template<typename Char>
0027 struct key_char_traits
0028 {
0029 typedef Char char_type;
0030 typedef typename std::char_traits<char_type>::int_type int_type;
0031 typedef typename std::char_traits<char_type>::off_type off_type;
0032 typedef typename std::char_traits<char_type>::pos_type pos_type;
0033 typedef typename std::char_traits<char_type>::state_type state_type;
0034
0035 BOOST_CONSTEXPR static char to_lower(char c) {return std::tolower(to_int_type(c));}
0036 BOOST_CONSTEXPR static wchar_t to_lower(wchar_t c) {return std::towlower(to_int_type(c));}
0037
0038 BOOST_CONSTEXPR static int_type to_lower(int_type i, char ) {return std::tolower(i);}
0039 BOOST_CONSTEXPR static int_type to_lower(int_type i, wchar_t) {return std::towlower(i);}
0040
0041
0042 BOOST_CONSTEXPR static
0043 void assign(char_type& c1, const char_type& c2) BOOST_NOEXCEPT
0044 {
0045 c1 = c2;
0046 }
0047
0048 BOOST_CONSTEXPR static
0049 bool eq(char_type c1, char_type c2) BOOST_NOEXCEPT
0050 {
0051 return to_lower(c1) == to_lower(c2);
0052 }
0053
0054 BOOST_CONSTEXPR static
0055 bool lt(char_type c1, char_type c2) BOOST_NOEXCEPT
0056 {
0057 return to_lower(c1) < to_lower(c2);
0058 }
0059
0060 BOOST_CONSTEXPR static
0061 int compare(const char_type* s1, const char_type* s2, size_t n) BOOST_NOEXCEPT
0062 {
0063 auto itrs = std::mismatch(s1, s1 + n, s2, &eq);
0064 if (itrs.first == (s1 + n))
0065 return 0;
0066 auto c1 = to_lower(*itrs.first);
0067 auto c2 = to_lower(*itrs.second);
0068
0069 return (c1 < c2 ) ? -1 : 1;
0070 }
0071
0072 BOOST_CONSTEXPR static size_t length(const char* s) BOOST_NOEXCEPT { return std::strlen(s); }
0073 BOOST_CONSTEXPR static size_t length(const wchar_t* s) BOOST_NOEXCEPT { return std::wcslen(s); }
0074
0075 BOOST_CONSTEXPR static
0076 const char_type* find(const char_type* s, size_t n, const char_type& a) BOOST_NOEXCEPT
0077 {
0078 const char_type u = to_lower(a);
0079 return std::find_if(s, s + n, [u](char_type c){return to_lower(c) == u;});
0080 }
0081
0082 BOOST_CONSTEXPR static
0083 char_type* move(char_type* s1, const char_type* s2, size_t n) BOOST_NOEXCEPT
0084 {
0085 if (s1 < s2)
0086 return std::move(s2, s2 + n, s1);
0087 else
0088 return std::move_backward(s2, s2 + n, s1);
0089 }
0090
0091 BOOST_CONSTEXPR static
0092 char_type* copy(char_type* s1, const char_type* s2, size_t n) BOOST_NOEXCEPT
0093 {
0094 return std::copy(s2, s2 + n, s1);
0095 }
0096
0097 BOOST_CONSTEXPR static
0098 char_type* assign(char_type* s, size_t n, char_type a) BOOST_NOEXCEPT
0099 {
0100 std::fill(s, s + n, a);
0101 return s +n;
0102 }
0103
0104 BOOST_CONSTEXPR static
0105 int_type not_eof(int_type c) BOOST_NOEXCEPT
0106 {
0107 return eq_int_type(c, eof()) ? ~eof() : c;
0108 }
0109
0110 BOOST_CONSTEXPR static
0111 char_type to_char_type(int_type c) BOOST_NOEXCEPT
0112 {
0113 return char_type(c);
0114 }
0115
0116 BOOST_CONSTEXPR static
0117 int_type to_int_type(char c) BOOST_NOEXCEPT
0118 {
0119 return int_type((unsigned char)c);
0120 }
0121
0122 BOOST_CONSTEXPR static
0123 int_type to_int_type(wchar_t c) BOOST_NOEXCEPT
0124 {
0125 return int_type((wchar_t)c);
0126 }
0127
0128 BOOST_CONSTEXPR static
0129 bool eq_int_type(int_type c1, int_type c2) BOOST_NOEXCEPT
0130 {
0131 return to_lower(c1, char_type()) == to_lower(c2, char_type());
0132 }
0133
0134 BOOST_CONSTEXPR static inline int_type eof() BOOST_NOEXCEPT
0135 {
0136 return int_type(EOF);
0137 }
0138 };
0139
0140 namespace detail
0141 {
0142
0143
0144 template<typename Char>
0145 std::size_t hash_step(std::size_t prev, Char c, key_char_traits<Char>)
0146 {
0147 return prev ^ (key_char_traits<Char>::to_lower(c) << 1);
0148 }
0149
0150
0151 }
0152
0153 template<typename Char>
0154 using value_char_traits = std::char_traits<Char>;
0155
0156 BOOST_CONSTEXPR static char_type equality_sign = L'=';
0157 BOOST_CONSTEXPR static char_type delimiter = L';';
0158
0159 using native_handle_type = wchar_t*;
0160 using native_iterator = const wchar_t*;
0161
0162 namespace detail
0163 {
0164
0165 BOOST_PROCESS_V2_DECL
0166 std::basic_string<wchar_t, value_char_traits<wchar_t>> get(
0167 basic_cstring_ref<wchar_t, key_char_traits<wchar_t>> key,
0168 error_code & ec);
0169
0170 BOOST_PROCESS_V2_DECL
0171 void set(basic_cstring_ref<wchar_t, key_char_traits<wchar_t>> key,
0172 basic_cstring_ref<wchar_t, value_char_traits<wchar_t>> value,
0173 error_code & ec);
0174
0175 BOOST_PROCESS_V2_DECL
0176 void unset(basic_cstring_ref<wchar_t, key_char_traits<wchar_t>> key,
0177 error_code & ec);
0178
0179
0180 BOOST_PROCESS_V2_DECL
0181 std::basic_string<char, value_char_traits<char>> get(
0182 basic_cstring_ref<char, key_char_traits<char>> key,
0183 error_code & ec);
0184
0185 BOOST_PROCESS_V2_DECL
0186 void set(basic_cstring_ref<char, key_char_traits<char>> key,
0187 basic_cstring_ref<char, value_char_traits<char>> value,
0188 error_code & ec);
0189
0190 BOOST_PROCESS_V2_DECL
0191 void unset(basic_cstring_ref<char, key_char_traits<char>> key,
0192 error_code & ec);
0193
0194 BOOST_PROCESS_V2_DECL native_handle_type load_native_handle();
0195 struct native_handle_deleter
0196 {
0197 native_handle_deleter() = default;
0198 native_handle_deleter(const native_handle_deleter& ) = default;
0199 BOOST_PROCESS_V2_DECL void operator()(native_handle_type nh) const;
0200
0201 };
0202
0203 inline const char_type * dereference(native_iterator iterator) {return iterator;}
0204 BOOST_PROCESS_V2_DECL native_iterator next(native_iterator nh);
0205 BOOST_PROCESS_V2_DECL native_iterator find_end(native_handle_type nh);
0206 BOOST_PROCESS_V2_DECL bool is_executable(const filesystem::path & pth, error_code & ec);
0207 }
0208
0209 }
0210 BOOST_PROCESS_V2_END_NAMESPACE
0211
0212 #endif