initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / test / dictionary / dictionaryTest.C
blob2c2395e9fb956b769db5a48bec0798fd945ca2d5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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     dictionaryTest
28 Description
30 \*---------------------------------------------------------------------------*/
32 #include "argList.H"
33 #include "IOstreams.H"
34 #include "IOobject.H"
35 #include "IFstream.H"
36 #include "dictionary.H"
38 using namespace Foam;
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 //  Main program:
43 int main(int argc, char *argv[])
45     argList::noParallel();
46     argList args(argc, argv);
48     Info<< nl
49         << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
50         << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
51         << endl;
54     {
55         dictionary dict1(IFstream("testDict")());
56         Info<< "dict1: " << dict1 << nl
57             << "toc: " << dict1.toc() << nl
58             << "keys: " << dict1.keys() << nl
59             << "patterns: " << dict1.keys(true) << endl;
61         dictionary dict2(dict1.xfer());
63         Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << nl
64             << "dict2.toc(): " << dict2.name() << " " << dict2.toc() << endl;
66         // copy back
67         dict1 = dict2;
68         Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << endl;
70         dictionary dict3(dict2.subDictPtr("boundaryField"));
71         dictionary dict4(dict2.subDictPtr("NONEXISTENT"));
73         Info<< "dictionary construct from pointer" << nl
74             << "ok = " << dict3.name() << " " << dict3.toc() << nl
75             << "no = " << dict4.name() << " " << dict4.toc() << endl;
76     }
79     IOobject::writeDivider(Info);
81     {
82         dictionary dict(IFstream("testDictRegex")());
83         dict.add(keyType("fooba[rz]", true), "anything");
85         Info<< "dict:" << dict << nl
86             << "toc: " << dict.toc() << nl
87             << "keys: " << dict.keys() << nl
88             << "patterns: " << dict.keys(true) << endl;
90         Info<< "Pattern find \"abc\" in top directory : "
91             << dict.lookup("abc") << endl;
92         Info<< "Pattern find \"abc\" in sub directory : "
93             << dict.subDict("someDict").lookup("abc")
94             << endl;
95         Info<< "Recursive pattern find \"def\" in sub directory : "
96             << dict.subDict("someDict").lookup("def", true)
97             << endl;
98         Info<< "Recursive pattern find \"foo\" in sub directory : "
99             << dict.subDict("someDict").lookup("foo", true)
100             << endl;
101         Info<< "Recursive pattern find \"fooz\" in sub directory : "
102             << dict.subDict("someDict").lookup("fooz", true)
103             << endl;
104         Info<< "Recursive pattern find \"bar\" in sub directory : "
105             << dict.subDict("someDict").lookup("bar", true)
106             << endl;
107         Info<< "Recursive pattern find \"xxx\" in sub directory : "
108             << dict.subDict("someDict").lookup("xxx", true)
109             << endl;
110     }
112     return 0;
116 // ************************************************************************* //