From 61187dfedb3dc34a06cdbfedb08e5a1dbbfb0853 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Thu, 18 Dec 2008 16:54:35 +0100 Subject: [PATCH] updated DictionaryTest to test transfer() and remove() - PtrDictionary and remove(const word&) does not seem to work --- applications/test/Dictionary/DictionaryTest.C | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/applications/test/Dictionary/DictionaryTest.C b/applications/test/Dictionary/DictionaryTest.C index 9c0b2d71f26..9bbd32d4fdd 100644 --- a/applications/test/Dictionary/DictionaryTest.C +++ b/applications/test/Dictionary/DictionaryTest.C @@ -30,8 +30,11 @@ Description #include "OSspecific.H" +#include "scalar.H" + #include "IOstreams.H" #include "Dictionary.H" +#include "PtrDictionary.H" using namespace Foam; @@ -63,6 +66,36 @@ public: }; +class Scalar +{ + scalar data_; + +public: + + Scalar() + : + data_(0) + {} + + Scalar(scalar val) + : + data_(val) + {} + + ~Scalar() + { + Info <<"delete Scalar: " << data_ << endl; + } + + friend Ostream& operator<<(Ostream& os, const Scalar& val) + { + os << val.data_; + return os; + } +}; + + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -118,6 +151,65 @@ int main(int argc, char *argv[]) << "target: " << newDict << nl << "keys: " << newDict.toc() << endl; + + PtrDictionary<Scalar> scalarDict; + for (int i = 0; i<10; i++) + { + word key("ent" + name(i)); + scalarDict.insert(key, new Scalar(1.3*i)); + } + + Info<< nl << "scalarDict1: " << endl; + for + ( + PtrDictionary<Scalar>::const_iterator iter = scalarDict.begin(); + iter != scalarDict.end(); + ++iter + ) + { + Info<< " = " << iter() << endl; + } + + PtrDictionary<Scalar> scalarDict2; + for (int i = 8; i<15; i++) + { + word key("ent" + name(i)); + scalarDict2.insert(key, new Scalar(1.3*i)); + } + Info<< nl << "scalarDict2: " << endl; + for + ( + PtrDictionary<Scalar>::const_iterator iter = scalarDict2.begin(); + iter != scalarDict2.end(); + ++iter + ) + { + Info<< "elem = " << *iter << endl; + } + + scalarDict.transfer(scalarDict2); + + + Scalar* p = scalarDict.lookupPtr("ent8"); + + // This does not (yet) work + // Scalar* q = scalarDict.remove("ent10"); + + if (p) + { + Info << "found: " << *p << endl; + } + else + { + Info << "no p: " << endl; + } + + scalarDict.clear(); + + // Info<< " = " << *iter << endl; + + + Info<< nl << "Done." << endl; return 0; } -- GitLab