Test-dictionary.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation |
7  -------------------------------------------------------------------------------
8  License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24  Application
25  dictionaryTest
26 
27  Description
28 
29  \*---------------------------------------------------------------------------*/
30 
31 #include "argList.H"
32 #include "IOstreams.H"
33 #include "IOobject.H"
34 #include "IFstream.H"
35 #include "dictionary.H"
36 #include "stringOps.H"
37 
38 using namespace Foam;
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // Main program:
42 
43 int main(int argc, char *argv[])
44 {
46  argList::validArgs.insert("dict .. dictN");
47  argList args(argc, argv, false, true);
48 
49  {
50  dictionary dict,dict2;
51  dict.add("value", 1);
52  dict2.add("value2", 2);
53  dictionary paredict(dict,dict2);
54  paredict.add("asdf",4);
55  paredict.add("subdcit",dict2);
56  paredict.merge(dict);
57  Info<< "dict" << dict <<endl;
58  Info<< "paredict" << paredict <<endl;
59 
60  }
61 
62 
63  Info<< nl
64  << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
65  << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
66  << endl;
67 
68  if (args.size() <= 1)
69  {
70  {
71  dictionary dict1(IFstream("testDict")());
72  Info<< "dict1: " << dict1 << nl
73  << "toc: " << dict1.toc() << nl
74  << "keys: " << dict1.keys() << nl
75  << "patterns: " << dict1.keys(true) << endl;
76 
77  dictionary dict2(dict1.xfer());
78 
79  Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << nl
80  << "dict2.toc(): " << dict2.name() << " " << dict2.toc()
81  << endl;
82 
83  // copy back
84  dict1 = dict2;
85  Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc()
86  << endl;
87 
88  dictionary dict3(dict2.subDictPtr("boundaryField"));
89  dictionary dict4(dict2.subDictPtr("NONEXISTENT"));
90 
91  Info<< "dictionary construct from pointer" << nl
92  << "ok dict 3 name = " << dict3.name() << " " << dict3.toc() << nl
93  << "no dict 3 name = " << dict4.name() << " " << dict4.toc() << endl;
94  }
95 
96 
97  // Info<< "dict:" << dict << nl
98  // << "toc: " << dict.toc() << nl
99  // << "keys: " << dict.keys() << nl
100  // << "patterns: " << dict.keys(true) << endl;
101  //
102  // Info<< "Pattern find \"abc\" in top directory : "
103  // << dict.lookup("abc") << endl;
104  // Info<< "Pattern find \"abc\" in sub directory : "
105  // << dict.subDict("someDict").lookup("abc")
106  // << endl;
107  // Info<< "Recursive pattern find \"def\" in sub directory : "
108  // << dict.subDict("someDict").lookup("def", true)
109  // << endl;
110  // Info<< "Recursive pattern find \"foo\" in sub directory : "
111  // << dict.subDict("someDict").lookup("foo", true)
112  // << endl;
113  // Info<< "Recursive pattern find \"fooz\" in sub directory : "
114  // << dict.subDict("someDict").lookup("fooz", true)
115  // << endl;
116  // Info<< "Recursive pattern find \"bar\" in sub directory : "
117  // << dict.subDict("someDict").lookup("bar", true)
118  // << endl;
119  // Info<< "Recursive pattern find \"xxx\" in sub directory : "
120  // << dict.subDict("someDict").lookup("xxx", true)
121  // << endl;
122  }
123  else
124  {
125  }
126 
127  return 0;
128 }
129 
130 
131 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::dictionaryName::name
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
Foam::argList::size
label size() const
Return the number of arguments.
Definition: argListI.H:84
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dictionary::keys
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:711
Foam::getEnv
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:101
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::dictionary::merge
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1005
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
IOobject.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
main
int main(int argc, char *argv[])
Definition: Test-dictionary.C:43
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
dictionary.H
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
stringOps.H
Foam::dictionary::xfer
Xfer< dictionary > xfer()
Transfer contents to the Xfer container.
Definition: dictionary.C:1072
Foam::dictionary::subDictPtr
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:616
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729