1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 \*---------------------------------------------------------------------------*/
30 #include "OSspecific.H"
32 #include "IOstreams.H"
33 #include "UDictionary.H"
39 public UDictionary<ent>::link
46 ent(const word& keyword, int i)
52 const word& keyword() const
57 friend Ostream& operator<<(Ostream& os, const ent& e)
59 os << e.keyword_ << ' ' << e.i_ << endl;
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 int main(int argc, char *argv[])
70 UDictionary<ent>* dictPtr = new UDictionary<ent>;
71 UDictionary<ent>& dict = *dictPtr;
73 for (int i = 0; i<10; i++)
75 ent* ePtr = new ent(word("ent") + name(i), i);
76 dict.append(ePtr->keyword(), ePtr);
82 dict.swapDown(dict.first());
84 forAllConstIter(UDictionary<ent>, dict, iter)
86 Info<< "element : " << *iter;
89 Info<< dict.toc() << endl;
93 dictPtr = new UDictionary<ent>;
94 UDictionary<ent>& dict2 = *dictPtr;
96 for (int i = 0; i<10; i++)
98 ent* ePtr = new ent(word("ent") + name(i), i);
99 dict2.append(ePtr->keyword(), ePtr);
103 Info<< dict2 << endl;
105 dict2.remove("ent9");
106 dict2.UILList<DLListBase, ent>::remove(dict2.first());
108 Info<< dict2 << endl;
111 Info<< nl << "Testing transfer: " << nl << endl;
112 Info<< "original: " << dict2 << endl;
114 UDictionary<ent> newDict;
115 newDict.transfer(dict2);
117 Info<< nl << "source: " << dict2 << nl
118 << "keys: " << dict2.toc() << nl
119 << "target: " << newDict << nl
120 << "keys: " << newDict.toc() << endl;
122 Info<< nl << "Done." << endl;
128 // ************************************************************************* //