Browse Source

[2105] Make setData() optionally return the old data

Mukund Sivaraman 12 years ago
parent
commit
0ea32d7945
1 changed files with 14 additions and 5 deletions
  1. 14 5
      src/lib/datasrc/memory/domaintree.h

+ 14 - 5
src/lib/datasrc/memory/domaintree.h

@@ -244,12 +244,21 @@ public:
 
     /// \name Setter functions.
     //@{
-    /// \brief Set the data stored in the node. If there is old data, it
-    /// is destroyed.
-    void setData(T* data) {
-        const DT deleter;
-        deleter(data_);
 
+    /// \brief Set the data stored in the node. If there is old data, it
+    /// is either returned or destroyed based on what is passed in \c
+    /// old_data.
+    /// \param data The new data to set.
+    /// \param old_data If \c NULL is passed here, any old data is
+    ///                 destroyed. Otherwise, the old data is returned
+    ///                 in this location.
+    void setData(T* data, T** old_data = NULL) {
+        if (old_data != NULL) {
+            *old_data = data;
+        } else {
+            const DT deleter;
+            deleter(data_);
+        }
         data_ = data;
     }
     //@}