00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 #include <ximol/str_cast.hpp>
00046 #include <ximol/macros.hpp>
00047 #include <algorithm>
00048 #include <functional>
00049 #include <locale>
00050 
00051 XIMOL_BEGIN_PRIVATE_NAMESPACE
00052 
00053 wchar_t to_wide_char(char c)
00054 {
00055     using namespace std;
00056     typedef ctype<wchar_t> ctype_facet;
00057     static const ctype_facet & the_facet = XIMOL_USE_FACET(::std::locale::classic(), ctype_facet);
00058     return the_facet.widen(c);
00059 };
00060 
00061 char to_narrow_char(wchar_t xc)
00062 {
00063     using namespace std;
00064     typedef ctype<wchar_t> ctype_facet;
00065     static const ctype_facet & the_facet = XIMOL_USE_FACET(::std::locale::classic(), ctype_facet);
00066     return the_facet.narrow(xc,' ');
00067 };
00068 
00069 XIMOL_END_PRIVATE_NAMESPACE
00070 
00071 XIMOL_BEGIN_NAMESPACE
00072 
00073 
00074 
00075 
00076 char converter<char, wchar_t>::get(wchar_t xc)
00077 {
00078     return to_narrow_char(xc);
00079 };
00080 
00081 
00082 
00083 
00084 ::std::string converter<char, wchar_t>::get(const ::std::wstring & wstr)
00085 {
00086     using namespace std;
00087     string str;
00088     str.resize(wstr.length());
00089     transform(wstr.begin(),wstr.end(),str.begin(),ptr_fun(to_narrow_char));
00090     return str;
00091 };
00092 
00093 
00094 
00095 
00096 char converter<char, char>::get(char c)
00097 {
00098     return c;
00099 };
00100 
00101 
00102 
00103 
00104 ::std::string converter<char, char>::get(const ::std::string& str_)
00105 {
00106     return str_;
00107 };
00108 
00109 
00110 
00111 
00112 wchar_t converter<wchar_t, char>::get(char c)
00113 {    
00114     return to_wide_char(c);
00115 
00116 };
00117 
00118 
00119 
00120 
00121 ::std::wstring converter<wchar_t, char>::get(const ::std::string& str_)
00122 {
00123     using namespace std;
00124     wstring wstr;
00125     wstr.resize(str_.length());
00126     transform(str_.begin(), str_.end(), wstr.begin(), ptr_fun(to_wide_char));
00127     return wstr;
00128 }
00129 
00130 
00131 
00132 
00133 wchar_t converter<wchar_t, wchar_t>::get(wchar_t xc)
00134 {
00135     return xc;
00136 };
00137 
00138 
00139 
00140 
00141 ::std::wstring converter<wchar_t, wchar_t>::get(const ::std::wstring & wstr)
00142 {
00143     return wstr;
00144 };
00145 
00146 XIMOL_END_NAMESPACE