00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : Transcoder 00006 * Package : Zeus.ZeusBase.System.Platforms 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef TranscoderHPP 00033 #define TranscoderHPP 00034 00035 #include <zeusbase/System/String.h> 00036 00037 #ifdef _MSC_VER 00038 #pragma warning(push, 1) // Avoid Visual Studio 6.0 level 4 and 3 compiler warnings. 00039 #endif 00040 00041 #include <stdlib.h> 00042 00043 #ifdef _MSC_VER 00044 #pragma warning(pop) 00045 #endif 00046 00047 //############################################################################# 00048 //STL Transforms 00049 #ifdef USE_STL_BINDINGS 00050 00051 #ifdef _MSC_VER 00052 #pragma warning(push, 1) // Avoid Visual Studio 6.0 level 4 and 3 compiler warnings. 00053 #endif 00054 00055 #include <string> 00056 00057 #ifdef _MSC_VER 00058 #pragma warning(pop) 00059 #endif 00060 00061 00062 #define _STD_STR(arg) NAMESPACE_Zeus::TSTLTranscoder::transcodeStr(arg) 00063 #define _STD_WSTR(arg) NAMESPACE_Zeus::TSTLTranscoder::transcodeWStr(arg) 00064 00065 BEGIN_NAMESPACE_Zeus 00066 00067 /******************************************************************************/ 00070 /******************************************************************************/ 00071 class TSTLTranscoder 00072 { 00073 public: 00074 /**************************************************************************/ 00079 /**************************************************************************/ 00080 inline static TString transcodeStr(const std::string& rValue) 00081 { 00082 return TString(rValue.c_str()); 00083 } 00084 00085 /**************************************************************************/ 00090 /**************************************************************************/ 00091 inline static std::string transcodeStr(const TString& rValue) 00092 { 00093 return std::string(rValue.c_str(NULL)); 00094 } 00095 00096 /**************************************************************************/ 00101 /**************************************************************************/ 00102 inline static TString transcodeWStr(const std::wstring& rValue) 00103 { 00104 return TString(rValue.c_str()); 00105 } 00106 00107 /**************************************************************************/ 00112 /**************************************************************************/ 00113 inline static std::wstring transcodeWStr(const TString& rValue) 00114 { 00115 return std::wstring(rValue.c_bstr()); 00116 } 00117 }; 00118 END_NAMESPACE_Zeus 00119 #endif 00120 00121 //############################################################################# 00122 // QT Transforms 00123 #ifdef USE_QT_BINDINGS 00124 00125 #define _QTWSTR(arg) NAMESPACE_Zeus::TQTTranscoder::transcodeStr(arg) 00126 00127 00128 #include <qstring.h> 00129 BEGIN_NAMESPACE_Zeus 00130 /******************************************************************************/ 00133 /******************************************************************************/ 00134 class TQTTranscoder 00135 { 00136 public: 00137 00138 /**************************************************************************/ 00143 /**************************************************************************/ 00144 inline static TString transcodeStr(const QString& rValue) 00145 { 00146 return TString(rValue.ascii()); 00147 } 00148 00149 /**************************************************************************/ 00154 /**************************************************************************/ 00155 inline static QString transcodeStr(const TString& rValue) 00156 { 00157 return QString::fromAscii(rValue.c_str(NULL)); 00158 } 00159 }; 00160 END_NAMESPACE_Zeus 00161 00162 #endif 00163 00164 //############################################################################# 00165 // Borland Transforms 00166 #ifdef USE_BCB_BINDINGS 00167 #include <Classes.hpp> 00168 00169 #define _BCBSTR(arg) NAMESPACE_Zeus::TBCBTranscoder::transcodeStr(arg) 00170 #if __BCPLUSPLUS__ > 0x0610 00171 #define _BCBWSTR(arg) NAMESPACE_Zeus::TBCBTranscoder::transcodeUnicodeStr(arg) 00172 #else 00173 #define _BCBWSTR(arg) NAMESPACE_Zeus::TBCBTranscoder::transcodeWStr(arg) 00174 #endif 00175 00176 BEGIN_NAMESPACE_Zeus 00177 00178 /******************************************************************************/ 00181 /******************************************************************************/ 00182 class TBCBTranscoder 00183 { 00184 public: 00185 /**************************************************************************/ 00188 /**************************************************************************/ 00189 inline static TString transcodeStr(const AnsiString& rValue) // AnsiString for Transcoder. 00190 { 00191 return TString(rValue.c_str()); 00192 } 00193 00194 /**************************************************************************/ 00197 /**************************************************************************/ 00198 inline static TString transcodeWStr(const WideString& rValue) // WideString for Transcoder. 00199 { 00200 return TString(rValue.c_bstr()); 00201 } 00202 00203 /**************************************************************************/ 00206 /**************************************************************************/ 00207 inline static AnsiString transcodeStr(const TString& rValue, BOOL_ERRORRETVAL(pError)) // AnsiString for Transcoder. 00208 { 00209 return AnsiString(rValue.c_str(pError)); // AnsiString for Transcoder. 00210 } 00211 00212 /**************************************************************************/ 00215 /**************************************************************************/ 00216 inline static WideString transcodeWStr(const TString& rValue) // WideString for Transcoder. 00217 { 00218 return WideString(rValue.c_bstr()); // WideString for Transcoder. 00219 } 00220 00221 #if defined(ENABLE_BCB_UNICODESTRING) 00222 inline static TString transcodeUnicodeStr(const UnicodeString& rValue) 00223 { 00224 return TString(rValue.w_str()); // WideString for Transcoder. 00225 } 00226 00227 inline static UnicodeString transcodeUnicodeStr(const TString& rValue) 00228 { 00229 return UnicodeString(rValue.c_bstr()); // WideString for Transcoder. 00230 } 00231 #endif //ENABLE_BCB_UNICODESTRING 00232 00233 }; 00234 END_NAMESPACE_Zeus 00235 00236 #endif 00237 00238 00239 #endif