FreeFOAM The Cross-Platform CFD Toolkit
foamDebugSwitches.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) 1991-2010 OpenCFD Ltd.
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  foamDebugSwitches
26 
27 Description
28  Write out all library debug switches
29 
30 Usage
31  - foamDebugSwitches
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #include <OpenFOAM/argList.H>
36 #include <OpenFOAM/dictionary.H>
37 #include <OpenFOAM/IFstream.H>
38 #include <OpenFOAM/IOobject.H>
39 #include <OpenFOAM/HashSet.H>
40 
41 using namespace Foam;
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // Main program:
45 
46 int main(int argc, char *argv[])
47 {
49  argList::validOptions.insert("new", "");
50  argList::validOptions.insert("old", "");
51 
52  Foam::argList args(argc, argv);
53 
54  wordList currDebug(debug::debugSwitches().toc());
55  wordList currInfo(debug::infoSwitches().toc());
56  wordList currOpt(debug::optimisationSwitches().toc());
57 
58  if (args.optionFound("old") || args.optionFound("new"))
59  {
60  dictionary controlDict(IFstream(findEtcFile("controlDict", true))());
61 
62  // Work-around for compiler bug
63  wordList dbgTmp = controlDict.subDict("DebugSwitches").toc();
64  wordHashSet oldDebug
65  (
66  static_cast<UList<word>&>(dbgTmp)
67  );
68 
69  // Work-around for compiler bug
70  wordList infoTmp = controlDict.subDict("InfoSwitches").toc();
71  wordHashSet oldInfo
72  (
73  static_cast<UList<word>&>(infoTmp)
74  );
75 
76  // Work-around for compiler bug
77  wordList optTmp = controlDict.subDict("OptimisationSwitches").toc();
78  wordHashSet oldOpt
79  (
80  static_cast<UList<word>&>(optTmp)
81  );
82 
83 
84  wordHashSet hashset;
85  wordList listing;
86 
87 
88  // list old switches - but this can't work since the (old) inserted
89  // switches are in both sets
90  // Workaround:
91  // 1. run without any options (get complete list)
92  // 2. comment out DebugSwitches, run again with -new to find new ones
93  // and do a diff
94  if (args.optionFound("old"))
95  {
97 
98  hashset = oldDebug;
99  hashset -= currDebug;
100  listing = hashset.toc();
101  sort(listing);
102  Info<< "old DebugSwitches: " << listing << endl;
103 
104  hashset = oldInfo;
105  hashset -= currInfo;
106  listing = hashset.toc();
107  sort(listing);
108  Info<< "old InfoSwitches: " << listing << endl;
109 
110  hashset = oldOpt;
111  hashset -= currOpt;
112  listing = hashset.toc();
113  sort(listing);
114  Info<< "old OptimisationSwitches: " << listing << endl;
115  }
116 
117  // list new switches
118  if (args.optionFound("new"))
119  {
121 
122  hashset = currDebug;
123  hashset -= oldDebug;
124 
125  listing = hashset.toc();
126  sort(listing);
127  Info<< "new DebugSwitches: " << listing << endl;
128 
129  hashset = currInfo;
130  hashset -= oldInfo;
131  listing = hashset.toc();
132  sort(listing);
133  Info<< "new InfoSwitches: " << listing << endl;
134 
135  hashset = currOpt;
136  hashset -= oldOpt;
137  listing = hashset.toc();
138  sort(listing);
139  Info<< "new OptimisationSwitches: " << listing << endl;
140  }
141  }
142  else
143  {
145 
146  sort(currDebug);
147  Info<< "DebugSwitches: " << currDebug << endl;
148 
149  sort(currInfo);
150  Info<< "InfoSwitches: " << currInfo << endl;
151 
152  sort(currOpt);
153  Info<< "OptimisationSwitches: " << currOpt << endl;
154  }
155 
156 
157 
158  Info<< "done" << endl;
159 
160  return 0;
161 }
162 
163 
164 // ************************ vim: set sw=4 sts=4 et: ************************ //