[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch to add std::string support back into the Persistence Engine
From: |
Chad Yates |
Subject: |
Re: Patch to add std::string support back into the Persistence Engine |
Date: |
Fri, 16 Jul 2004 20:21:28 -0700 |
User-agent: |
Mozilla Thunderbird 0.7.1 (X11/20040708) |
Lets try this again... found out that current development is on the
stable1 branch at savannah and not on the default MAIN branch. away
from commoncpp for a while and I just can't get back into the groove.
Attached is single unified patch for persist.h and engine.cpp
thanks for your patience.
Chad Yates wrote:
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:
*/
-
-
-
-
------------------------------------------------------------------------
_______________________________________________
Bug-commoncpp mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-commoncpp
Index: include/cc++/persist.h
===================================================================
RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/persist.h,v
retrieving revision 1.11.4.7
diff -u -r1.11.4.7 persist.h
--- include/cc++/persist.h 14 Jun 2004 21:48:23 -0000 1.11.4.7
+++ include/cc++/persist.h 17 Jul 2004 03:17:06 -0000
@@ -312,7 +312,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
+
void write(const String& str) THROWS (Exception);
+ void write(const std::string& str) THROWS (Exception);
// Every write operation boils down to one or more of these
void writeBinary(const uint8* data, const uint32 size) THROWS
(Exception);
@@ -348,6 +350,7 @@
#undef CCXX_ENGINEREAD_REF
void read(String& str) THROWS (Exception);
+ void read(std::string& str) THROWS (Exception);
// Every read operation boild down to one or more of these
void readBinary(uint8* data, uint32 size) THROWS (Exception);
@@ -465,6 +468,11 @@
__EXPORT Engine& operator <<( Engine& ar, String ob) THROWS
(Engine::Exception);
/** @relates Engine */
+__EXPORT Engine& operator >>( Engine& ar, std::string& ob) THROWS
(Engine::Exception);
+/** @relates Engine */
+__EXPORT Engine& operator <<( Engine& ar, std::string ob) THROWS
(Engine::Exception);
+
+/** @relates Engine */
__EXPORT Engine& operator >>( Engine& ar, bool& ob) THROWS (Engine::Exception);
/** @relates Engine */
__EXPORT Engine& operator <<( Engine& ar, bool ob) THROWS (Engine::Exception);
@@ -585,7 +593,3 @@
* c-basic-offset: 8
* End:
*/
-
-
-
-
Index: src/engine.cpp
===================================================================
RCS file: /cvsroot/commoncpp/commoncpp2/src/engine.cpp,v
retrieving revision 1.6.4.4
diff -u -r1.6.4.4 engine.cpp
--- src/engine.cpp 6 Jul 2004 21:55:05 -0000 1.6.4.4
+++ src/engine.cpp 17 Jul 2004 03:17:06 -0000
@@ -268,7 +268,7 @@
uint32 classId = (uint32)myClassMap.size();
myClassMap[object->getPersistenceID()] = classId;
write(classId);
- write(object->getPersistenceID());
+ write(static_cast<String>(object->getPersistenceID()));
}
else
{
@@ -419,6 +419,30 @@
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