bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch to add std::string support back into the Persistence Engine


From: Chad Yates
Subject: Patch to add std::string support back into the Persistence Engine
Date: Thu, 15 Jul 2004 22:42:03 -0700
User-agent: Mozilla Thunderbird 0.7.1 (X11/20040708)

Attached is a patch to persist.h and engine.cpp to be applied directly to the CVS version. It adds back support for std::string to the Persistence Engine. This support was removed (I believe on accident) when a library wide change was made to ost::String.

I will be submitting a series of patches to things mentioned in my previous post in order to provide my changes piecemeal for your consideration.

,Chad
Index: src/engine.cpp
===================================================================
RCS file: /cvsroot/cplusplus/commoncpp2/src/engine.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 engine.cpp
--- src/engine.cpp      15 Dec 2003 19:26:49 -0000      1.1.1.1
+++ src/engine.cpp      16 Jul 2004 05:37:45 -0000
@@ -265,7 +265,7 @@
                  uint32 classId = myClassMap.size();
                  myClassMap[object->getPersistenceID()] = classId;
                  write(classId);
-                 write(object->getPersistenceID());
+                 write(static_cast<String>(object->getPersistenceID()));
                }
          else
                {
@@ -416,6 +416,32 @@
   delete[] buffer;
 }
 
+
+/*
+ * note, does not (yet?) throw an exception, but interface
+ * prepared ..
+ */
+void Engine::write(const std::string& str) THROWS (Engine::Exception)
+{
+  assert(myOperationalMode == modeWrite);
+  uint32 len = (uint32)str.length();
+  write(len);
+  writeBinary((uint8*)str.c_str(),len);
+}
+
+void Engine::read(std::string& str) THROWS (Engine::Exception)
+{
+  assert(myOperationalMode == modeRead);
+  uint32 len = 0;
+  read(len);
+  uint8 *buffer = new uint8[len+1];
+  readBinary(buffer,len);
+  buffer[len] = 0;
+  str = (char*)buffer;
+  delete[] buffer;
+}
+
+
 #define CCXX_RE(ar,ob)   ar.read(ob); return ar
 #define CCXX_WE(ar,ob)   ar.write(ob); return ar
 
@@ -459,6 +485,9 @@
 CCXX_EXPORT(Engine&) operator >>( Engine& ar, String& ob) THROWS 
(Engine::Exception) {CCXX_RE (ar,ob);}
 CCXX_EXPORT(Engine&) operator <<( Engine& ar, String ob)  THROWS 
(Engine::Exception) {CCXX_WE (ar,ob);}
 
+CCXX_EXPORT(Engine&) operator >>( Engine& ar, std::string& ob) THROWS 
(Engine::Exception) {CCXX_RE (ar,ob);}
+CCXX_EXPORT(Engine&) operator <<( Engine& ar, std::string ob)  THROWS 
(Engine::Exception) {CCXX_WE (ar,ob);}
+
 CCXX_EXPORT(Engine&) operator >>( Engine& ar, bool& ob) THROWS 
(Engine::Exception) {
        uint32 a; ar.read(a); ob=a==1;return ar;
 }
Index: include/cc++/persist.h
===================================================================
RCS file: /cvsroot/cplusplus/commoncpp2/include/cc++/persist.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 persist.h
--- include/cc++/persist.h      15 Dec 2003 19:27:12 -0000      1.1.1.1
+++ include/cc++/persist.h      16 Jul 2004 05:38:17 -0000
@@ -306,7 +306,9 @@
        void write(float i)  THROWS (Exception) { CCXX_ENGINEWRITE_REF(i); }
        void write(double i) THROWS (Exception) { CCXX_ENGINEWRITE_REF(i); }
 #undef CCXX_ENGINEWRITE_REF
+
        CCXX_MEMBER_EXPORT(void) write(const String& str) THROWS (Exception);
+       CCXX_MEMBER_EXPORT(void) write(const std::string& str) THROWS 
(Exception);
 
        // Every write operation boils down to one or more of these
        CCXX_MEMBER_EXPORT(void) writeBinary(const uint8* data, const uint32 
size) THROWS (Exception);
@@ -342,6 +344,7 @@
 #undef CCXX_ENGINEREAD_REF
 
        CCXX_MEMBER_EXPORT(void) read(String& str) THROWS (Exception);
+       CCXX_MEMBER_EXPORT(void) read(std::string& str) THROWS (Exception);
 
        // Every read operation boild down to one or more of these
        CCXX_MEMBER_EXPORT(void) readBinary(uint8* data, uint32 size) THROWS 
(Exception);
@@ -459,6 +462,11 @@
 CCXX_EXPORT(Engine&) operator <<( Engine& ar, String ob)  THROWS 
(Engine::Exception);
 
 /** @relates Engine */
+CCXX_EXPORT(Engine&) operator >>( Engine& ar, std::string& ob) THROWS 
(Engine::Exception);
+/** @relates Engine */
+CCXX_EXPORT(Engine&) operator <<( Engine& ar, std::string ob)  THROWS 
(Engine::Exception);
+
+/** @relates Engine */
 CCXX_EXPORT(Engine&) operator >>( Engine& ar, bool& ob) THROWS 
(Engine::Exception);
 /** @relates Engine */
 CCXX_EXPORT(Engine&) operator <<( Engine& ar, bool ob)  THROWS 
(Engine::Exception);
@@ -579,7 +587,3 @@
  * c-basic-offset: 8
  * End:
  */
-
-
-
-

reply via email to

[Prev in Thread] Current Thread [Next in Thread]