Update of /cvsroot/boost/boost/libs/serialization/example
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15751

Modified Files:
        portable_binary_iarchive.hpp portable_binary_oarchive.hpp 
Log Message:
added shared ptr helper, short type, sign extension fix

Index: portable_binary_iarchive.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/libs/serialization/example/portable_binary_iarchive.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- portable_binary_iarchive.hpp        12 Feb 2006 05:55:30 -0000      1.7
+++ portable_binary_iarchive.hpp        16 Jul 2007 16:44:29 -0000      1.8
@@ -55,7 +55,8 @@
         portable_binary_iarchive, 
         std::istream::char_type, 
         std::istream::traits_type
-    >
+    >,
+    public boost::archive::detail::shared_ptr_helper
 {
     typedef boost::archive::binary_iarchive_impl<
         portable_binary_iarchive, 
@@ -92,12 +93,27 @@
                 *first = x;
             }
         #endif
+
+        // extend sign if necessary
+        if((l >> (size - 1) * 8) & 0x80){
+            l |= (-1 << (size * 8));
+        }
     }
     // default fall through for any types not specified here
     template<class T>
     void load(T & t){
         this->primitive_base_t::load(t);
     }
+    void load(unsigned short & t){
+        long l;
+        load_impl(l, sizeof(unsigned short));
+        t = l;
+    }
+    void load(short & t){
+        long l;
+        load_impl(l, sizeof(short));
+        t = l;
+    }
     void load(unsigned int & t){
         long l;
         load_impl(l, sizeof(unsigned int));

Index: portable_binary_oarchive.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/libs/serialization/example/portable_binary_oarchive.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- portable_binary_oarchive.hpp        12 Feb 2006 05:55:30 -0000      1.7
+++ portable_binary_oarchive.hpp        16 Jul 2007 16:44:29 -0000      1.8
@@ -52,13 +52,25 @@
     friend class 
boost::archive::basic_binary_oarchive<portable_binary_oarchive>;
     friend class boost::archive::save_access;
 #endif
-    void save_impl(long l){
+    void save_impl(const long l){
         long ll = l;
-        char size = 0;;
-        do{
-            ll >>= 8;
-            ++size;
-        }while(ll != -1 && ll != 0);
+        char size = 0;
+        if(l < 0){
+            // make sure that enough of data is output
+            // to include a high order bit indicating the sign
+            char x;
+            do{
+                x = ll;
+                ll >>= 8;
+                ++size;
+            }while(ll != -1 && x < 0);
+        }
+        else{
+            do{
+                ll >>= 8;
+                ++size;
+            }while(ll != 0);
+        }
 
         this->archive_base_t::save(size);
 
@@ -84,6 +96,12 @@
     void save(const T & t){
         this->primitive_base_t::save(t);
     }
+    void save(const short  t){
+        save_impl(t);
+    }
+    void save(const unsigned short t){
+        save_impl(t);
+    }
     void save(const unsigned int t){
         save_impl(t);
     }


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to