Test-UDictionary.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 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 
26 Description
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "OSspecific.H"
31 
32 #include "IOstreams.H"
33 #include "UDictionary.H"
34 
35 using namespace Foam;
36 
37 class ent
38 :
39  public UDictionary<ent>::link
40 {
41  word keyword_;
42  int i_;
43 
44 public:
45 
46  ent(const word& keyword, int i)
47  :
48  keyword_(keyword),
49  i_(i)
50  {}
51 
52  const word& keyword() const
53  {
54  return keyword_;
55  }
56 
57  friend Ostream& operator<<(Ostream& os, const ent& e)
58  {
59  os << e.keyword_ << ' ' << e.i_ << endl;
60  return os;
61  }
62 };
63 
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 // Main program:
67 
68 int main(int argc, char *argv[])
69 {
70  UDictionary<ent>* dictPtr = new UDictionary<ent>;
71  UDictionary<ent>& dict = *dictPtr;
72 
73  for (int i = 0; i<10; i++)
74  {
75  ent* ePtr = new ent(word("ent") + name(i), i);
76  dict.append(ePtr->keyword(), ePtr);
77  dict.swapUp(ePtr);
78  }
79 
80  Info<< dict << endl;
81 
82  dict.swapDown(dict.first());
83 
85  {
86  Info<< "element : " << *iter;
87  }
88 
89  Info<< dict.toc() << endl;
90 
91  delete dictPtr;
92 
93  dictPtr = new UDictionary<ent>;
94  UDictionary<ent>& dict2 = *dictPtr;
95 
96  for (int i = 0; i<10; i++)
97  {
98  ent* ePtr = new ent(word("ent") + name(i), i);
99  dict2.append(ePtr->keyword(), ePtr);
100  dict2.swapUp(ePtr);
101  }
102 
103  Info<< dict2 << endl;
104 
105  dict2.remove("ent9");
106  dict2.UILList<DLListBase, ent>::remove(dict2.first());
107 
108  Info<< dict2 << endl;
109 
110 
111  Info<< nl << "Testing transfer: " << nl << endl;
112  Info<< "original: " << dict2 << endl;
113 
114  UDictionary<ent> newDict;
115  newDict.transfer(dict2);
116 
117  Info<< nl << "source: " << dict2 << nl
118  << "keys: " << dict2.toc() << nl
119  << "target: " << newDict << nl
120  << "keys: " << newDict.toc() << endl;
121 
122  Info<< nl << "Done." << endl;
123 
124  return 0;
125 }
126 
127 
128 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::DictionaryBase< UIDLList< T >, T >::toc
wordList toc() const
Return the table of contents.
Definition: DictionaryBase.C:172
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::DictionaryBase< UIDLList< T >, T >::append
void append(const word &, T *)
Add at tail of dictionary.
Definition: DictionaryBase.C:203
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
ent::ent
ent(const word &keyword, int i)
Definition: Test-UDictionary.C:43
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::DictionaryBase< UIDLList< T >, T >::remove
T * remove(const word &)
Remove and return entry specified by keyword.
Definition: DictionaryBase.C:212
dict
dictionary dict
Definition: searchingEngine.H:14
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
ent::keyword
const word & keyword() const
Definition: Test-UDictionary.C:49
main
int main(int argc, char *argv[])
Definition: Test-UDictionary.C:65
ent::operator<<
friend Ostream & operator<<(Ostream &os, const ent &e)
Definition: Test-UDictionary.C:54
Foam::UDictionary
Template dictionary class which does not manages the storage associated with it.
Definition: UDictionary.H:54
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::DictionaryBase< UIDLList< T >, T >::transfer
void transfer(DictionaryBase< IDLListType, T > &)
Transfer the contents of the argument into this DictionaryBase.
Definition: DictionaryBase.C:239
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
UDictionary.H
ent
Definition: Test-Dictionary.C:37