]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2105] Make setData() optionally return the old data
authorMukund Sivaraman <muks@isc.org>
Thu, 2 Aug 2012 05:46:16 +0000 (11:16 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 2 Aug 2012 05:46:16 +0000 (11:16 +0530)
src/lib/datasrc/memory/domaintree.h

index 9767b975434a7b92b299530fcaf17e918fdc2320..cf92c1a6c37c53f55e96cf688c2b04838586f7ec 100644 (file)
@@ -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;
     }
     //@}