Skip to content
Snippets Groups Projects
Commit 61187dfe authored by Mark Olesen's avatar Mark Olesen
Browse files

updated DictionaryTest to test transfer() and remove()

- PtrDictionary and remove(const word&) does not seem to work
parent 5692245b
No related merge requests found
......@@ -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;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment