initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / test / UDictionary / UDictionaryTest.C
blob5caea16dad9e959c73d5c7911b938a300df9f8ec
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Application
26     
27 Description
29 \*---------------------------------------------------------------------------*/
31 #include "OSspecific.H"
33 #include "IOstreams.H"
34 #include "UDictionary.H"
36 using namespace Foam;
38 class ent
40     public UDictionary<ent>::link
42     word keyword_;
43     int i_;
45 public:
47     ent(const word& keyword, int i)
48     :
49         keyword_(keyword),
50         i_(i)
51     {}
53     const word& keyword() const
54     {
55         return keyword_;
56     }
58     friend Ostream& operator<<(Ostream& os, const ent& e)
59     {
60         os << e.keyword_ << ' ' << e.i_ << endl;
61         return os;
62     }
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 //  Main program:
69 int main(int argc, char *argv[])
71     UDictionary<ent>* dictPtr = new UDictionary<ent>;
72     UDictionary<ent>& dict = *dictPtr;
74     for (int i = 0; i<10; i++)
75     {
76         ent* ePtr = new ent(word("ent") + name(i), i);
77         dict.append(ePtr->keyword(), ePtr);
78         dict.swapUp(ePtr);
79     }
81     Info<< dict << endl;
83     dict.swapDown(dict.first());
85     for
86     (
87         UDictionary<ent>::const_iterator iter = dict.begin();
88         iter != dict.end();
89         ++iter
90     )
91     {
92         Info<< "element : " << *iter;
93     }
95     Info<< dict.toc() << endl;
97     delete dictPtr;
99     dictPtr = new UDictionary<ent>;
100     UDictionary<ent>& dict2 = *dictPtr;
102     for (int i = 0; i<10; i++)
103     {
104         ent* ePtr = new ent(word("ent") + name(i), i);
105         dict2.append(ePtr->keyword(), ePtr);
106         dict2.swapUp(ePtr);
107     }
109     Info<< dict2 << endl;
111     dict2.remove("ent9");
112     dict2.UILList<DLListBase, ent>::remove(dict2.first());
114     Info<< dict2 << endl;
116     Info<< nl << "Bye." << endl;
117     return 0;
121 // ************************************************************************* //