Commits

Anonymous committed 30450b6

Implement operator= for ArenaSharedHeapSTLAllocator.

  • Participants
  • Parent commits 5d3a7e9

Comments (0)

Files changed (3)

+2012-04-20  scott snyder  <snyder@bnl.gov>
+
+	* Tagging DataModel-00-23-34.
+	* DataModel/tools/ArenaSharedHeapSTLAllocator.h,
+	DataModel/tools/ArenaSharedHeapSTLAllocator.icc: Implement
+	operator=.
+
 2012-04-04  Sebastien Binet  <binet@cern.ch>
 
 	* tagging DataModel-00-23-33

File DataModel/tools/ArenaSharedHeapSTLAllocator.h

    * @param name   Value to use as the base for the allocator names.
    */
   ArenaSharedHeapSTLAllocator (size_t nblock = 1000,
-                                   const std::string& name = "");
+                               const std::string& name = "");
 
 
   /**
   ~ArenaSharedHeapSTLAllocator();
 
 
+  /**
+   * @brief Assignment.
+   *
+   * We allow assignment only if the two objects involved represent
+   * the same arena, in which case it's a no-op.
+   * In other cases, we raise an exception.
+   *
+   * FIXME: By default, swap() is implemented in terms of this.
+   * It might be useful, though, to have a swap() that could
+   * handle different arenas.  We would need to be able handle
+   * updating the ownership back pointers from the headers, though;
+   * but that's much easier for swap than for the case of general
+   * assignments.
+   */
+  ArenaSharedHeapSTLAllocator&
+  operator= (const ArenaSharedHeapSTLAllocator& a);
+
+
   /// Convert a reference to an address.
   pointer address (reference x) const;
   const_pointer address (const_reference x) const;

File DataModel/tools/ArenaSharedHeapSTLAllocator.icc

  */
 
 
+#include <cassert>
+#include <stdexcept>
+
+
 namespace SG {
 
 
 
 
 /**
+ * @brief Assignment.
+ *
+ * We allow assignment only if the two objects involved represent
+ * the same arena, in which case it's a no-op.
+ * In other cases, we raise an exception.
+ */
+template <class T>
+ArenaSharedHeapSTLAllocator<T>&
+ArenaSharedHeapSTLAllocator<T>::operator=
+  (const ArenaSharedHeapSTLAllocator& a)
+{
+  if (&a != this) {
+    if (m_header != a.m_header)
+      throw std::runtime_error
+        ("Attempt to assign between ArenaSharedHeapSTLAllocators "
+         "for different arenas");
+    assert (m_pool == a.m_pool);
+  }
+  return *this;
+}
+
+
+/**
  * @brief Convert a reference to an address.
  */
 template <class T>