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"
34 #include "IOstreams.H"
35 #include "Dictionary.H"
36 #include "PtrDictionary.H"
42 public Dictionary<ent>::link
49 ent(const word& keyword, int i)
55 const word& keyword() const
60 friend Ostream& operator<<(Ostream& os, const ent& e)
62 os << e.keyword_ << ' ' << e.i_ << endl;
86 Info <<"delete Scalar: " << data_ << endl;
89 friend Ostream& operator<<(Ostream& os, const Scalar& val)
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101 int main(int argc, char *argv[])
103 Dictionary<ent>* dictPtr = new Dictionary<ent>;
104 Dictionary<ent>& dict = *dictPtr;
106 for (int i = 0; i<10; i++)
108 ent* ePtr = new ent(word("ent") + name(i), i);
109 dict.append(ePtr->keyword(), ePtr);
115 dict.swapDown(dict.first());
119 Dictionary<ent>::const_iterator iter = dict.begin();
124 Info<< "element : " << *iter;
127 Info<< "keys: " << dict.toc() << endl;
131 Dictionary<ent> dict2;
133 for (int i = 0; i<10; i++)
135 ent* ePtr = new ent(word("ent") + name(i), i);
136 dict2.append(ePtr->keyword(), ePtr);
140 Info<< "dict:\n" << dict2 << endl;
142 Info<< nl << "Testing transfer: " << nl << endl;
143 Info<< "original: " << dict2 << endl;
145 Dictionary<ent> newDict;
146 newDict.transfer(dict2);
148 Info<< nl << "source: " << dict2 << nl
149 << "keys: " << dict2.toc() << nl
150 << "target: " << newDict << nl
151 << "keys: " << newDict.toc() << endl;
154 PtrDictionary<Scalar> scalarDict;
155 for (int i = 0; i<10; i++)
157 word key("ent" + name(i));
158 scalarDict.insert(key, new Scalar(1.3*i));
161 Info<< nl << "scalarDict1: " << endl;
164 PtrDictionary<Scalar>::const_iterator iter = scalarDict.begin();
165 iter != scalarDict.end();
169 Info<< " = " << iter() << endl;
172 PtrDictionary<Scalar> scalarDict2;
173 for (int i = 8; i<15; i++)
175 word key("ent" + name(i));
176 scalarDict2.insert(key, new Scalar(1.3*i));
178 Info<< nl << "scalarDict2: " << endl;
181 PtrDictionary<Scalar>::const_iterator iter = scalarDict2.begin();
182 iter != scalarDict2.end();
186 Info<< "elem = " << *iter << endl;
189 scalarDict.transfer(scalarDict2);
192 Scalar* p = scalarDict.lookupPtr("ent8");
194 // This does not (yet) work
195 // Scalar* q = scalarDict.remove("ent10");
199 Info << "found: " << *p << endl;
203 Info << "no p: " << endl;
208 // Info<< " = " << *iter << endl;
212 Info<< nl << "Done." << endl;
217 // ************************************************************************* //