$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57095 - sandbox/stm/branches/vbe/boost/stm/tx
From: vicente.botet_at_[hidden]
Date: 2009-10-23 10:56:22
Author: viboes
Date: 2009-10-23 10:56:20 EDT (Fri, 23 Oct 2009)
New Revision: 57095
URL: http://svn.boost.org/trac/boost/changeset/57095
Log:
TBoost.STM vbe: Factoring common behavior between tx::numeric.hpp and tx/pointer.hpp on a new file tx::object.hpp
Added:
   sandbox/stm/branches/vbe/boost/stm/tx/object.hpp   (contents, props changed)
Text files modified: 
   sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp |    58 ++-------------------                   
   sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp |   106 +++++++-------------------------------- 
   2 files changed, 28 insertions(+), 136 deletions(-)
Modified: sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp	(original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/numeric.hpp	2009-10-23 10:56:20 EDT (Fri, 23 Oct 2009)
@@ -16,72 +16,28 @@
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-#include <boost/stm/transaction.hpp>
-//#include <boost/stm/non_tx/detail/cache_map.hpp>
+#include <boost/stm/tx/object.hpp>
 
 //-----------------------------------------------------------------------------
 namespace boost { namespace stm { namespace tx {
 
 //-----------------------------------------------------------------------------
-// mixing transactional object numeric class that wraps a numeric builtin type providing
+// transactional object numeric class that wraps a numeric builtin type providing
 // a transparent transactional view on a transactional context
 // a non-transactional view on a non-transactional context
 // Note: the sizeof(numeric<T>)>>>>=sizeof(T)
 //-----------------------------------------------------------------------------
 template <typename T>
-class numeric : public transaction_object< numeric<T> >
+class numeric : public object< numeric<T>, T >
 {
-protected:
-    T val_;
+    typedef object< numeric<T> ,T > base_type;
 public:
     //-----------------------------------------------------------------------------
-    numeric() : val_(0) {}
-
-    //
+    numeric() : base_type(0) {}
     template<class U>
-    numeric(numeric<U> const& r) : val_(r.value()) {}
-
-    // contructor from a implicitly convertible to T
+    numeric(numeric<U> const& r) : base_type(r) {}
     template <typename U>
-    numeric(U v) : val_(v) {}
-    //numeric(T v) : val_(v) {}
-    ~numeric() {}
-
-    #if 0
-    template<class U>
-    numeric& operator=(numeric<U> const& r) {
-        val_=r.value();
-    }
-    #endif
-
-    operator T() const { return value(); }
-    operator T&() { return ref(); }
-
-    T& ref() {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-
-            return tx->write(*this).val_;
-        }
-        return val_;
-    }
-
-    T value() const {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->read(*this).val_;
-        }
-        return val_;
-    }
-
+    numeric(U v) : base_type(v) {}
 };
 
 
Added: sandbox/stm/branches/vbe/boost/stm/tx/object.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/tx/object.hpp	2009-10-23 10:56:20 EDT (Fri, 23 Oct 2009)
@@ -0,0 +1,91 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_TX_OBJECT__HPP
+#define BOOST_STM_TX_OBJECT__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stm/transaction.hpp>
+#include <boost/stm/transaction_object.hpp>
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm { namespace tx {
+
+//-----------------------------------------------------------------------------
+// mixing transactional object class that wraps a object type providing
+// a transparent transactional view on a transactional context
+// a non-transactional view on a non-transactional context
+// Note: the sizeof(object<T>)>>>>=sizeof(T)
+//-----------------------------------------------------------------------------
+template <typename Final, typename T>
+class object : public transaction_object< Final >
+{
+protected:
+    T val_;
+public:
+    typedef Final final_type;
+    typedef T value_type;
+    //-----------------------------------------------------------------------------
+    object() : val_() {}
+
+    //
+    template<typename F, typename U>
+    object(object<F,U> const& r) : val_(r.value()) {}
+
+    // contructor from a convertible to T
+    template <typename U>
+    object(U v) : val_(v) {}
+    //object(T v) : val_(v) {}
+
+    #if 0
+    template<typename F, typename U>
+    object& operator=(object<F, U> const& r) {
+        val_=r.value();
+    }
+    #endif
+
+    operator T() const { return value(); }
+    operator T&() { return ref(); }
+
+    T& ref() {
+        transaction* tx=current_transaction();
+        if (tx!=0) {
+            if (tx->forced_to_abort()) {
+                tx->lock_and_abort();
+                throw aborted_transaction_exception("aborting transaction");
+            }
+
+            return tx->write(*this).val_;
+        }
+        return val_;
+    }
+
+    T value() const {
+        transaction* tx=current_transaction();
+        if (tx!=0) {
+            if (tx->forced_to_abort()) {
+                tx->lock_and_abort();
+                throw aborted_transaction_exception("aborting transaction");
+            }
+            return tx->read(*this).val_;
+        }
+        return val_;
+    }
+
+};
+
+}}}
+#endif
+
+
Modified: sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp	(original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp	2009-10-23 10:56:20 EDT (Fri, 23 Oct 2009)
@@ -16,7 +16,7 @@
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-#include <boost/stm/transaction.hpp>
+#include <boost/stm/tx/object.hpp>
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -30,64 +30,31 @@
 // Note: the sizeof(pointer<T>)>>>>=sizeof(T*)
 //-----------------------------------------------------------------------------
 template <typename T>
-class pointer : public transaction_object< pointer<T> >
+class pointer : public object< pointer<T> ,T* >
 {
-protected:
-    T* val_;
+    typedef object< pointer<T> , T* > base_type;
+    
 public:
     //-----------------------------------------------------------------------------
-    pointer() : val_(0) {}
-
-    //
+    pointer() : base_type(static_cast<T*>(0)) {}
     template<class U>
-    pointer(pointer<U> const& r) : val_(r.value()) {}
-
-    // contructor from a implicitly convertible to T
+    pointer(pointer<U> const& r) : base_type(r) {}
     template <typename U>
-    pointer(U* v) : val_(v) {}
-    pointer(T* v) : val_(v) {}
-    //
-    ~pointer() {}
-
-    operator T*() const { return get(); }
-    operator T*&() { return get(); }
-
-    T*& get() {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->write(*this).val_;
-        }
-        return val_;
-    }
-
-    T* get() const {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->read(*this).val_;
-        }
-        return val_;
-    }
+    pointer(U* v) : base_type(v) {}
+    //pointer(T* v) : base_type(v) {}
 
     T* operator->() const {
-        return this->get();
+        return this->value();
     }
     T& operator*() const {
-        return *this->get();
+        return *this->value();
     }
 
-    T * operator->() {
-        return this->get();
+    T* operator->() {
+        return this->ref();
     }
-    T & operator*() {
-        return *this->get();
+    T& operator*() {
+        return *this->ref();
     }
 
 };
@@ -95,47 +62,16 @@
 template <typename C, typename R>
 class pointer_to_member : public transaction_object< pointer_to_member<C,R> >
 {
-protected:
-    R C::* val_;
+    typedef object< pointer_to_member<C,R> ,R C::*> base_type;
 public:
     //-----------------------------------------------------------------------------
-    pointer_to_member() : val_(0) {}
-
-    //
-    pointer_to_member(pointer_to_member const& r) : val_(r.value()) {}
-
-    // contructor from a implicitly convertible to T
-    pointer_to_member(R C::* v) : val_(v) {}
-    //
-
-    operator R C::*() const { return get(); }
-    operator R C::*&() { return get(); }
-
-    R C::*& get() {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-
-            return tx->write(*this).val_;
-        }
-        return val_;
-    }
-
-    R C::* const * get() const {
-        transaction* tx=current_transaction();
-        if (tx!=0) {
-            if (tx->forced_to_abort()) {
-                tx->lock_and_abort();
-                throw aborted_transaction_exception("aborting transaction");
-            }
-            return tx->read(*this).val_;
-        }
-        return val_;
-    }
+    pointer_to_member() : base_type(static_cast<R C::*>(0)) {}
 
+    template <typename D, typename S>
+    pointer_to_member(pointer_to_member<D,S> const& r) : base_type(r) {}
+    template <typename D, typename S>
+    pointer_to_member(S D::* v) : base_type(v) {}
+    //pointer_to_member(R C::* v) : base_type(v) {}
 };
 
 #if 0