Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:07

0001 // Copyright (c) 2016 Klemens D. Morgenstern
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 
0007 #ifndef BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_
0008 #define BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_
0009 
0010 #include <algorithm>
0011 
0012 #include <boost/process/detail/traits/decl.hpp>
0013 #include <boost/process/detail/traits/cmd_or_exe.hpp>
0014 #include <boost/process/detail/traits/env.hpp>
0015 #include <boost/process/locale.hpp>
0016 
0017 namespace boost { namespace process { namespace detail {
0018 
0019 //template
0020 
0021 template<typename T> struct is_wchar_t : std::false_type {};
0022 
0023 template<> struct is_wchar_t<boost::process::filesystem::path> : std::is_same<typename boost::process::filesystem::path::value_type, wchar_t>
0024 {
0025 };
0026 
0027 template<> struct is_wchar_t<const wchar_t* > : std::true_type {};
0028 
0029 template<> struct is_wchar_t<wchar_t* > : std::true_type {};
0030 
0031 template<std::size_t Size> struct is_wchar_t<const wchar_t [Size]>    : std::true_type {};
0032 template<std::size_t Size> struct is_wchar_t<const wchar_t (&)[Size]> : std::true_type {};
0033 
0034 template<> struct is_wchar_t<std::wstring>               : std::true_type {};
0035 template<> struct is_wchar_t<std::vector<std::wstring>>  : std::true_type {};
0036 template<> struct is_wchar_t<std::initializer_list<std::wstring>> : std::true_type {};
0037 template<> struct is_wchar_t<std::vector<wchar_t *>>           : std::true_type {};
0038 template<> struct is_wchar_t<std::initializer_list<wchar_t *>> : std::true_type {};
0039 
0040 
0041 
0042 template<typename Char, typename T>
0043 struct char_converter
0044 {
0045     static T&  conv(T & in)
0046     {
0047         return in;
0048     }
0049     static T&& conv(T&& in)
0050     {
0051         return std::move(in);
0052     }
0053     static const T&  conv(const T & in)
0054     {
0055         return in;
0056     }
0057 };
0058 
0059 template<typename Char, typename T>
0060 using char_converter_t = char_converter<Char,
0061         typename std::remove_cv<typename std::remove_reference<T>::type>::type>;
0062 
0063 
0064 template<>
0065 struct char_converter<char, const wchar_t*>
0066 {
0067     static std::string conv(const wchar_t* in)
0068     {
0069         std::size_t size = 0;
0070         while (in[size] != L'\0') size++;
0071         return ::boost::process::detail::convert(in, in + size);
0072     }
0073 };
0074 
0075 template<>
0076 struct char_converter<char, wchar_t*>
0077 {
0078     static std::string conv(wchar_t* in)
0079     {
0080         std::size_t size = 0;
0081         while (in[size] != L'\0') size++;
0082         return ::boost::process::detail::convert(in, in + size);
0083     }
0084 };
0085 
0086 template<std::size_t Size>
0087 struct char_converter<char, wchar_t[Size]>
0088 {
0089     static std::string conv(const wchar_t(&in)[Size])
0090     {
0091         return ::boost::process::detail::convert(in, in + Size -1);
0092     }
0093 };
0094 
0095 template<>
0096 struct char_converter<wchar_t, const char*>
0097 {
0098     static std::wstring conv(const char* in)
0099     {
0100         std::size_t size = 0;
0101         while (in[size] != '\0') size++;
0102         return ::boost::process::detail::convert(in, in + size);
0103     }
0104 };
0105 
0106 template<>
0107 struct char_converter<wchar_t, char*>
0108 {
0109     static std::wstring conv(char* in)
0110     {
0111         std::size_t size = 0;
0112         while (in[size] != '\0') size++;
0113         return ::boost::process::detail::convert(in, in + size);
0114     }
0115 };
0116 
0117 
0118 template<std::size_t Size>
0119 struct char_converter<wchar_t, char[Size]>
0120 {
0121     static std::wstring conv(const char(&in)[Size])
0122     {
0123         return ::boost::process::detail::convert(in, in + Size -1);
0124     }
0125 };
0126 
0127 //all the containers.
0128 template<>
0129 struct char_converter<wchar_t, std::string>
0130 {
0131     static std::wstring conv(const std::string & in)
0132     {
0133         return ::boost::process::detail::convert(in);
0134     }
0135 };
0136 
0137 template<>
0138 struct char_converter<char, std::wstring>
0139 {
0140     static std::string conv(const std::wstring & in)
0141     {
0142         return ::boost::process::detail::convert(in);
0143     }
0144 };
0145 
0146 template<>
0147 struct char_converter<wchar_t, std::vector<std::string>>
0148 {
0149     static std::vector<std::wstring> conv(const std::vector<std::string> & in)
0150     {
0151         std::vector<std::wstring> ret(in.size());
0152         std::transform(in.begin(), in.end(), ret.begin(),
0153                 [](const std::string & st)
0154                 {
0155                     return convert(st);
0156                 });
0157         return ret;
0158     }
0159 };
0160 
0161 template<>
0162 struct char_converter<wchar_t, std::initializer_list<std::string>>
0163 {
0164     static std::vector<std::wstring> conv(const std::initializer_list<std::string> & in)
0165     {
0166         std::vector<std::wstring> ret(in.size());
0167         std::transform(in.begin(), in.end(), ret.begin(),
0168                 [](const std::string & st)
0169                 {
0170                     return convert(st);
0171                 });
0172         return ret;
0173     }
0174 };
0175 
0176 template<>
0177 struct char_converter<wchar_t, std::vector<char* >>
0178 {
0179     static std::vector<std::wstring> conv(const std::vector<char* > & in)
0180     {
0181         std::vector<std::wstring> ret(in.size());
0182         std::transform(in.begin(), in.end(), ret.begin(),
0183                 [](const char* st)
0184                 {
0185                     std::size_t sz = 0;
0186                     while (st[sz] != '\0') sz++;
0187                     return convert(st, st + sz);
0188                 });
0189         return ret;
0190     }
0191 };
0192 
0193 template<>
0194 struct char_converter<wchar_t, std::initializer_list<char *>>
0195 {
0196     static std::vector<std::wstring>  conv(const std::initializer_list<char * > & in)
0197     {
0198         std::vector<std::wstring> ret(in.size());
0199         std::transform(in.begin(), in.end(), ret.begin(),
0200                 [](const char* st)
0201                 {
0202                     std::size_t sz = 0;
0203                     while (st[sz] != '\0') sz++;
0204                     return convert(st, st + sz);
0205                 });
0206         return ret;
0207     }
0208 };
0209 
0210 template<>
0211 struct char_converter<char, std::vector<std::wstring>>
0212 {
0213     static std::vector<std::string> conv(const std::vector<std::wstring> & in)
0214     {
0215         std::vector<std::string> ret(in.size());
0216         std::transform(in.begin(), in.end(), ret.begin(),
0217                 [](const std::wstring & st)
0218                 {
0219                     return convert(st);
0220                 });
0221         return ret;
0222     }
0223 };
0224 
0225 template<>
0226 struct char_converter<char, std::initializer_list<std::wstring>>
0227 {
0228     static std::vector<std::string> conv(const std::initializer_list<std::wstring> & in)
0229     {
0230         std::vector<std::string> ret(in.size());
0231         std::transform(in.begin(), in.end(), ret.begin(),
0232                 [](const std::wstring & st)
0233                 {
0234                     return convert(st);
0235                 });
0236         return ret;
0237     }
0238 };
0239 
0240 template<>
0241 struct char_converter<char, std::vector<wchar_t* >>
0242 {
0243     static std::vector<std::string> conv(const std::vector<wchar_t* > & in)
0244     {
0245         std::vector<std::string> ret(in.size());
0246         std::transform(in.begin(), in.end(), ret.begin(),
0247                 [](const wchar_t* st)
0248                 {
0249                     std::size_t sz = 0;
0250                     while (st[sz] != L'\0') sz++;
0251                     return convert(st, st + sz);
0252                 });
0253         return ret;
0254     }
0255 };
0256 
0257 template<>
0258 struct char_converter<char, std::initializer_list<wchar_t * >>
0259 {
0260     static std::vector<std::string> conv(const std::initializer_list<wchar_t *> & in)
0261     {
0262         std::vector<std::string> ret(in.size());
0263         std::transform(in.begin(), in.end(), ret.begin(),
0264                 [](const wchar_t* st)
0265                 {
0266                     std::size_t sz = 0;
0267                     while (st[sz] != L'\0') sz++;
0268                     return convert(st, st + sz);
0269                 });
0270         return ret;
0271     }
0272 };
0273 
0274 
0275 }}}
0276 #endif /* BOOST_PROCESS_DETAIL_TRAITS_WCHAR_T_HPP_ */