summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-12-01 18:12:00 +0000
committerBernard Normier <bernard@zeroc.com>2003-12-01 18:12:00 +0000
commitd3c97d3684313de23723d31a8bdb374acb5f977e (patch)
tree96480bd53b0dda1b198564e47d2087b27f74ec77 /cpp
parentChanged default for Freeze.Map.KeepIterators to 1 (diff)
downloadice-d3c97d3684313de23723d31a8bdb374acb5f977e.tar.bz2
ice-d3c97d3684313de23723d31a8bdb374acb5f977e.tar.xz
ice-d3c97d3684313de23723d31a8bdb374acb5f977e.zip
Added /Zc:wchar_t support to VC7.x builds
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES3
-rw-r--r--cpp/include/IceUtil/Unicode.h41
-rw-r--r--cpp/src/IceUtil/Unicode.cpp21
3 files changed, 65 insertions, 0 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 1d5bf174393..b667cc7f7f6 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,9 @@
Changes since version 1.2.0
---------------------------
+- Visual C++ 7.x builds can now be used by applications built with
+ /Zc:wchar_t.
+
- Fixed a bug in IceSSL that caused the error message "WRN unable
to load certificate authorities" to be logged when no value
was specified for the "path" attribute of <certauthority>.
diff --git a/cpp/include/IceUtil/Unicode.h b/cpp/include/IceUtil/Unicode.h
index 1d15156dedd..75ae345a90c 100644
--- a/cpp/include/IceUtil/Unicode.h
+++ b/cpp/include/IceUtil/Unicode.h
@@ -20,9 +20,50 @@
namespace IceUtil
{
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+
+//
+// With Visual C++ 7.x, wchar_t is either a typedef unsigned short or a
+// native type (when /Zc:wchar_t is used).
+// Since wstring is a typedef basic_string<wchar_t>, its type is also
+// different depending on whether /Zc:wchar_t is used or not.
+//
+// Ice is always built without /Zc:wchar_t, but provides wstringToString()
+// and stringToWstring() implementations for both flavors of wstring.
+//
+
+# if defined(_NATIVE_WCHAR_T_DEFINED)
+//
+// We're using Ice with /Zc:wchar_t
+//
+ICE_UTIL_API std::string wstringToString(const std::wstring&);
+ICE_UTIL_API std::wstring stringToNativeWstring(const std::string&);
+
+inline std::wstring
+stringToWstring(const std::string& str)
+{
+ return stringToNativeWstring(str);
+}
+
+# else
+//
+// We're building Ice or using it without /Zc:wchar_t
+//
+ICE_UTIL_API std::string wstringToString(const std::wstring&);
+ICE_UTIL_API std::wstring stringToWstring(const std::string&);
+
+ICE_UTIL_API std::string wstringToString(const std::basic_string<__wchar_t>&);
+ICE_UTIL_API std::basic_string<__wchar_t> stringToNativeWstring(const std::string&);
+
+# endif
+
+#else
+
ICE_UTIL_API std::string wstringToString(const std::wstring&);
ICE_UTIL_API std::wstring stringToWstring(const std::string&);
+#endif
+
}
#endif
diff --git a/cpp/src/IceUtil/Unicode.cpp b/cpp/src/IceUtil/Unicode.cpp
index c4ea2d36b16..2f553cd099a 100644
--- a/cpp/src/IceUtil/Unicode.cpp
+++ b/cpp/src/IceUtil/Unicode.cpp
@@ -158,3 +158,24 @@ IceUtil::stringToWstring(const string& str)
return result;
}
+
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+//
+// See comments in IceUtil/Unicode.h
+//
+string
+IceUtil::wstringToString(const basic_string<__wchar_t>& str)
+{
+ assert(sizeof(__wchar_t) == SIZEOF_WCHAR_T);
+ return wstringToString(*reinterpret_cast<const wstring*>(&str));
+}
+
+basic_string<__wchar_t>
+IceUtil::stringToNativeWstring(const string& str)
+{
+ assert(sizeof(__wchar_t) == SIZEOF_WCHAR_T);
+ return *reinterpret_cast<basic_string<__wchar_t>* >(&stringToWstring(str));
+}
+
+#endif