1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 \*---------------------------------------------------------------------------*/
31 #include "OSspecific.H"
35 #include "IOstreams.H"
36 #include "Dictionary.H"
37 #include "PtrDictionary.H"
43 public Dictionary<ent>::link
50 ent(const word& keyword, int i)
56 const word& keyword() const
61 friend Ostream& operator<<(Ostream& os, const ent& e)
63 os << e.keyword_ << ' ' << e.i_ << endl;
87 Info <<"delete Scalar: " << data_ << endl;
90 friend Ostream& operator<<(Ostream& os, const Scalar& val)
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 int main(int argc, char *argv[])
104 Dictionary<ent>* dictPtr = new Dictionary<ent>;
105 Dictionary<ent>& dict = *dictPtr;
107 for (int i = 0; i<10; i++)
109 ent* ePtr = new ent(word("ent") + name(i), i);
110 dict.append(ePtr->keyword(), ePtr);
116 dict.swapDown(dict.first());
120 Dictionary<ent>::const_iterator iter = dict.begin();
125 Info<< "element : " << *iter;
128 Info<< "keys: " << dict.toc() << endl;
132 Dictionary<ent> dict2;
134 for (int i = 0; i<10; i++)
136 ent* ePtr = new ent(word("ent") + name(i), i);
137 dict2.append(ePtr->keyword(), ePtr);
141 Info<< "dict:\n" << dict2 << endl;
143 Info<< nl << "Testing transfer: " << nl << endl;
144 Info<< "original: " << dict2 << endl;
146 Dictionary<ent> newDict;
147 newDict.transfer(dict2);
149 Info<< nl << "source: " << dict2 << nl
150 << "keys: " << dict2.toc() << nl
151 << "target: " << newDict << nl
152 << "keys: " << newDict.toc() << endl;
155 PtrDictionary<Scalar> scalarDict;
156 for (int i = 0; i<10; i++)
158 word key("ent" + name(i));
159 scalarDict.insert(key, new Scalar(1.3*i));
162 Info<< nl << "scalarDict1: " << endl;
165 PtrDictionary<Scalar>::const_iterator iter = scalarDict.begin();
166 iter != scalarDict.end();
170 Info<< " = " << iter() << endl;
173 PtrDictionary<Scalar> scalarDict2;
174 for (int i = 8; i<15; i++)
176 word key("ent" + name(i));
177 scalarDict2.insert(key, new Scalar(1.3*i));
179 Info<< nl << "scalarDict2: " << endl;
182 PtrDictionary<Scalar>::const_iterator iter = scalarDict2.begin();
183 iter != scalarDict2.end();
187 Info<< "elem = " << *iter << endl;
190 scalarDict.transfer(scalarDict2);
193 Scalar* p = scalarDict.lookupPtr("ent8");
195 // This does not (yet) work
196 // Scalar* q = scalarDict.remove("ent10");
200 Info << "found: " << *p << endl;
204 Info << "no p: " << endl;
209 // Info<< " = " << *iter << endl;
213 Info<< nl << "Done." << endl;
218 // ************************************************************************* //