mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
updated DictionaryTest to test transfer() and remove()
- PtrDictionary and remove(const word&) does not seem to work
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user