From 239c31f30fef4a6dff5700a30492048280eafdf3 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Wed, 17 Dec 2008 12:36:55 +0100
Subject: [PATCH] DictionaryBase gets transfer() method

---
 applications/test/DLList/DLListTest.C         | 16 +++++++++---
 applications/test/Dictionary/DictionaryTest.C | 22 +++++++++++-----
 applications/test/ISLList/ISLListTest.C       | 20 +++++++++++---
 applications/test/SLList/SLListTest.C         | 26 ++++++++++++++++---
 .../test/UDictionary/UDictionaryTest.C        | 17 ++++++++++--
 .../DictionaryBase/DictionaryBase.C           | 11 ++++++++
 .../DictionaryBase/DictionaryBase.H           |  3 +++
 7 files changed, 97 insertions(+), 18 deletions(-)

diff --git a/applications/test/DLList/DLListTest.C b/applications/test/DLList/DLListTest.C
index 12913ce8666..2929efc1ce8 100644
--- a/applications/test/DLList/DLListTest.C
+++ b/applications/test/DLList/DLListTest.C
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Application
-    
+
 Description
 
 \*---------------------------------------------------------------------------*/
@@ -48,7 +48,6 @@ int main(int argc, char *argv[])
     }
 
     myList.append(100.3);
-
     myList.append(500.3);
 
     Info<< nl << "And again using STL iterator: " << nl << endl;
@@ -120,7 +119,18 @@ int main(int argc, char *argv[])
         Info<< "element:" << *iter << endl;
     }
 
-    Info<< nl << "Bye." << endl;
+
+    Info<< nl << "Testing transfer: " << nl << endl;
+    Info<< "original: " << myList << endl;
+
+    DLList<scalar> newList;
+    newList.transfer(myList);
+
+    Info<< nl << "source: " << myList << nl
+        << nl << "target: " << newList << endl;
+
+
+    Info<< nl << "Done." << endl;
     return 0;
 }
 
diff --git a/applications/test/Dictionary/DictionaryTest.C b/applications/test/Dictionary/DictionaryTest.C
index ade39072642..9c0b2d71f26 100644
--- a/applications/test/Dictionary/DictionaryTest.C
+++ b/applications/test/Dictionary/DictionaryTest.C
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Application
-    
+
 Description
 
 \*---------------------------------------------------------------------------*/
@@ -92,12 +92,11 @@ int main(int argc, char *argv[])
         Info<< "element : " << *iter;
     }
 
-    Info<< dict.toc() << endl;
+    Info<< "keys: " << dict.toc() << endl;
 
     delete dictPtr;
 
-    dictPtr = new Dictionary<ent>;
-    Dictionary<ent>& dict2 = *dictPtr;
+    Dictionary<ent> dict2;
 
     for (int i = 0; i<10; i++)
     {
@@ -106,9 +105,20 @@ int main(int argc, char *argv[])
         dict2.swapUp(ePtr);
     }
 
-    Info<< dict2 << endl;
+    Info<< "dict:\n" << dict2 << endl;
+
+    Info<< nl << "Testing transfer: " << nl << endl;
+    Info<< "original: " << dict2 << endl;
+
+    Dictionary<ent> newDict;
+    newDict.transfer(dict2);
+
+    Info<< nl << "source: " << dict2 << nl
+        << "keys: " << dict2.toc() << nl
+        << "target: " << newDict << nl
+        << "keys: " << newDict.toc() << endl;
 
-    Info<< nl << "Bye." << endl;
+    Info<< nl << "Done." << endl;
     return 0;
 }
 
diff --git a/applications/test/ISLList/ISLListTest.C b/applications/test/ISLList/ISLListTest.C
index 60590d1eafc..f33f811c1a4 100644
--- a/applications/test/ISLList/ISLListTest.C
+++ b/applications/test/ISLList/ISLListTest.C
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Application
-    
+
 Description
 
 \*---------------------------------------------------------------------------*/
@@ -52,6 +52,13 @@ public:
     :
         data_(s)
     {}
+
+    friend Ostream& operator<<(Ostream& os, const Scalar& s)
+    {
+        os << s.data_;
+        return os;
+    }
+
 };
 
 
@@ -68,10 +75,8 @@ int main(int argc, char *argv[])
     }
 
     myList.append(new Scalar(100.3));
-
     myList.append(new Scalar(500.3));
 
-
     Info<< nl << "And again using STL iterator: " << nl << endl;
 
     for
@@ -99,6 +104,15 @@ int main(int argc, char *argv[])
     }
 
 
+    Info<< nl << "Testing transfer: " << nl << endl;
+    Info<< "original: " << myList << endl;
+
+    ISLList<Scalar> newList;
+    newList.transfer(myList);
+
+    Info<< nl << "source: " << myList << nl
+        << nl << "target: " << newList << endl;
+
     Info<< nl << "Bye." << endl;
     return 0;
 }
diff --git a/applications/test/SLList/SLListTest.C b/applications/test/SLList/SLListTest.C
index 3bd9af2b672..f55f7b4edf5 100644
--- a/applications/test/SLList/SLListTest.C
+++ b/applications/test/SLList/SLListTest.C
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Application
-    
+
 Description
 
 \*---------------------------------------------------------------------------*/
@@ -48,10 +48,8 @@ int main(int argc, char *argv[])
     }
 
     myList.append(100.3);
-
     myList.append(500.3);
 
-
     Info<< nl << "And again using STL iterator: " << nl << endl;
 
     for
@@ -99,7 +97,27 @@ int main(int argc, char *argv[])
         Info<< "element:" << *iter2 << endl;
     }
 
-    Info<< nl << "Bye." << endl;
+
+
+    for (int i = 0; i<10; i++)
+    {
+        myList.append(1.3*i);
+    }
+
+    myList.append(100.3);
+    myList.append(500.3);
+
+    Info<< nl << "Testing transfer: " << nl << endl;
+    Info<< "original: " << myList << endl;
+
+    SLList<scalar> newList;
+    newList.transfer(myList);
+
+    Info<< nl << "source: " << myList << nl
+        << nl << "target: " << newList << endl;
+
+
+    Info<< nl << "Done." << endl;
     return 0;
 }
 
diff --git a/applications/test/UDictionary/UDictionaryTest.C b/applications/test/UDictionary/UDictionaryTest.C
index 5caea16dad9..247fc98cbb6 100644
--- a/applications/test/UDictionary/UDictionaryTest.C
+++ b/applications/test/UDictionary/UDictionaryTest.C
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Application
-    
+
 Description
 
 \*---------------------------------------------------------------------------*/
@@ -113,7 +113,20 @@ int main(int argc, char *argv[])
 
     Info<< dict2 << endl;
 
-    Info<< nl << "Bye." << endl;
+
+    Info<< nl << "Testing transfer: " << nl << endl;
+    Info<< "original: " << dict2 << endl;
+
+    UDictionary<ent> newDict;
+    newDict.transfer(dict2);
+
+    Info<< nl << "source: " << dict2 << nl
+        << "keys: " << dict2.toc() << nl
+        << "target: " << newDict << nl
+        << "keys: " << newDict.toc() << endl;
+
+    Info<< nl << "Done." << endl;
+
     return 0;
 }
 
diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C
index b8ce241f094..95112712081 100644
--- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C
+++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C
@@ -237,6 +237,17 @@ void Foam::DictionaryBase<IDLListType, T>::clear()
 }
 
 
+template<class IDLListType, class T>
+void Foam::DictionaryBase<IDLListType, T>::transfer
+(
+    DictionaryBase<IDLListType, T>& dict
+)
+{
+    IDLListType::transfer(dict);
+    hashedTs_.transfer(dict.hashedTs_);
+}
+
+
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
 template<class IDLListType, class T>
diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H
index 63566cc4c1e..f14785bcd55 100644
--- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H
+++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H
@@ -143,6 +143,9 @@ public:
             //- Clear the dictionary
             void clear();
 
+            //- Transfer the contents of the argument into this DictionaryBase
+            //  and annull the argument.
+            void transfer(DictionaryBase<IDLListType, T>&);
 
     // Member operators
 
-- 
GitLab