1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-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());
86 UDictionary<ent>::const_iterator iter = dict.begin();
91 Info<< "element : " << *iter;
94 Info<< dict.toc() << endl;
98 dictPtr = new UDictionary<ent>;
99 UDictionary<ent>& dict2 = *dictPtr;
101 for (int i = 0; i<10; i++)
103 ent* ePtr = new ent(word("ent") + name(i), i);
104 dict2.append(ePtr->keyword(), ePtr);
108 Info<< dict2 << endl;
110 dict2.remove("ent9");
111 dict2.UILList<DLListBase, ent>::remove(dict2.first());
113 Info<< dict2 << endl;
116 Info<< nl << "Testing transfer: " << nl << endl;
117 Info<< "original: " << dict2 << endl;
119 UDictionary<ent> newDict;
120 newDict.transfer(dict2);
122 Info<< nl << "source: " << dict2 << nl
123 << "keys: " << dict2.toc() << nl
124 << "target: " << newDict << nl
125 << "keys: " << newDict.toc() << endl;
127 Info<< nl << "Done." << endl;
133 // ************************************************************************* //