Date: Friday, January 19, 2007 @ 13:04:32
  Author: marc
    Path: /cvsroot/carob/carob

Modified: include/Common.hpp (1.56 -> 1.57) include/JavaSocket.hpp (1.41
          -> 1.42) include/StringCodecs.hpp (1.23 -> 1.24) src/Common.cpp
          (1.65 -> 1.66) src/JavaSocket.cpp (1.76 -> 1.77)

Implemented abstract class StringCodec, new superclass for MBSCodec
and IconvCodec. Now carob with iconv is compatible with carob without
iconv; clients do not need the CAROB_USE_ICONV flags anymore (unless
they want to use iconvcodecs). Removed related link-time check.
Removed unused StaticCodecs::utf8_codec. CAROB-79


--------------------------+
 include/Common.hpp       |   12 ------------
 include/JavaSocket.hpp   |    8 ++------
 include/StringCodecs.hpp |   41 +++++++++++++++++++++++++++--------------
 src/Common.cpp           |    8 --------
 src/JavaSocket.cpp       |    9 ++++++---
 5 files changed, 35 insertions(+), 43 deletions(-)


Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.56 carob/include/Common.hpp:1.57
--- carob/include/Common.hpp:1.56       Thu Jan 18 16:48:54 2007
+++ carob/include/Common.hpp    Fri Jan 19 13:04:31 2007
@@ -60,18 +60,6 @@
 
 namespace CarobNS {
 
-// This is to check that carob and its client are in sync concerning
-// -DCAROB_USE_ICONV. Before this linking-time check a run-time
-// segfault happened instead.
-// Ideally both versions of carob should be ABI-compatible in the future
-#ifdef CAROB_USE_ICONV
-extern bool use_iconv;
-static bool check_use_iconv = use_iconv;
-#else
-extern bool no_iconv;
-static bool check_no_iconv = no_iconv;
-#endif
-
 /** Java byte (signed) */
 typedef   int8_t    java_byte;
 
Index: carob/include/JavaSocket.hpp
diff -u carob/include/JavaSocket.hpp:1.41 carob/include/JavaSocket.hpp:1.42
--- carob/include/JavaSocket.hpp:1.41   Fri Jan 19 12:35:36 2007
+++ carob/include/JavaSocket.hpp        Fri Jan 19 13:04:31 2007
@@ -227,12 +227,8 @@
                     const throw (SocketIOException, UnexpectedException);
 
 private:
-#ifdef CAROB_USE_ICONV
-  const CarobNS::IconvCodec utf8_codec;
-#else
-  const CarobNS::MBSCodec utf8_codec;
-#endif
-  
+  const CarobNS::StringCodec& utf8_codec;
+
   /** Socket file descriptor */
   int           socket_fd;
   /** true if the socket is connected to a host */
Index: carob/include/StringCodecs.hpp
diff -u carob/include/StringCodecs.hpp:1.23 carob/include/StringCodecs.hpp:1.24
--- carob/include/StringCodecs.hpp:1.23 Fri Jan 19 12:35:36 2007
+++ carob/include/StringCodecs.hpp      Fri Jan 19 13:04:31 2007
@@ -27,11 +27,6 @@
 #include <locale>
 
 
-#ifdef CAROB_USE_ICONV
-#include <iconv.h>
-#include <CriticalSection.hpp>
-#endif
-
 namespace CarobNS {
 
 /**
@@ -65,10 +60,20 @@
 
 std::locale trylocale(const char * const name) throw (CodecException);
 
+
+class StringCodec
+{
+public:
+    virtual std::string encode(const std::wstring&) const throw 
(CodecException) = 0;
+    virtual std::wstring decode(const std::string&) const throw 
(CodecException) = 0;
+    virtual ~StringCodec() { }; // not much to delete...
+};
+
+
 /**
  * Multi-Byte String encoder and decoders according to a given or default 
locale
  */
-class MBSCodec
+class MBSCodec : public StringCodec
 {
   // TODO: replace loc by an accessor, so we could dynamically use
   // the (possibly changing) current locale() instead of a constant
@@ -117,12 +122,26 @@
   
 };
 
+
 #ifdef CAROB_USE_ICONV
+
+/*
+ *  WARNING: carob with and carob without iconv are currently binary
+ *  compatible. That is: clients with this macro OFF can link fine to
+ *  carob with this macro ON. Be VERY CAREFUL with what you put inside
+ *  here to avoid breaking that. See CAROB-79
+ */
+
+} // CarobNS namespace
+#include <iconv.h>
+#include <CriticalSection.hpp>
+namespace CarobNS {
+
+
 /**
  * Multi-Byte String encoder and decoders based on iconv
  */
-
-class IconvCodec
+class IconvCodec : public StringCodec
 {
 public:
   /**
@@ -191,12 +210,6 @@
   { return user_codec.encode(in); }
 private:
   static const CarobNS::MBSCodec ascii_codec;
-  /** Codec for UTF-8 strings */
-#ifdef CAROB_USE_ICONV
-  static const CarobNS::IconvCodec utf8_codec;
-#else
-  static const CarobNS::MBSCodec utf8_codec;
-#endif
   /** User-defined locale (typically set using LANG, LC_etc) codec */
   static const CarobNS::MBSCodec user_codec;
 };
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.65 carob/src/Common.cpp:1.66
--- carob/src/Common.cpp:1.65   Thu Jan 18 17:25:12 2007
+++ carob/src/Common.cpp        Fri Jan 19 13:04:31 2007
@@ -54,14 +54,6 @@
 using std::endl;
 
 
-// see explanation in Common.hpp
-#ifdef CAROB_USE_ICONV
-bool CarobNS::use_iconv = true;
-#else
-bool CarobNS::no_iconv = true;
-#endif
-
-
 #ifdef CAROB_LOG4CXX_NAME
 
 using namespace log4cxx;
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.76 carob/src/JavaSocket.cpp:1.77
--- carob/src/JavaSocket.cpp:1.76       Thu Jan 18 17:44:35 2007
+++ carob/src/JavaSocket.cpp    Fri Jan 19 13:04:31 2007
@@ -187,10 +187,10 @@
 
 
 JavaSocket::JavaSocket() throw (CodecException) :
-#ifdef CAROB_USE_ICONV
-  utf8_codec("UTF-8"),
+#ifdef CAROB_USE_ICONV // cpp-based factory :-]
+  utf8_codec(*new IconvCodec("UTF-8")),
 #else
-  utf8_codec(CarobNS::tryUTF8locale()),
+  utf8_codec(*new MBSCodec(tryUTF8locale())),
 #endif
 socket_fd(-1),
 connected(false),
@@ -201,6 +201,9 @@
 JavaSocket::~JavaSocket()
 {
   const wstring fctName(L"JavaSocket::~JavaSocket");
+
+  delete &utf8_codec;
+
   if (isDebugEnabled())
     logDebug(fctName, L"About to close socket...");
   try

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to