fileFormats.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "fileFormats.H"
29 #include "dictionary.H"
30 
31 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // Extract and merge 'default' + formatName from list of dictionaries
37 //
38 // \returns dictionary of merged options
40 (
41  const word& formatName,
42  std::initializer_list<const dictionary*> dicts
43 )
44 {
45  dictionary options;
46 
47  // Default specification. Merge from all levels
48  // - literal search only
49  for (const dictionary* dict : dicts)
50  {
51  if
52  (
53  dict
54  && (dict = dict->findDict("default", keyType::LITERAL)) != nullptr
55  )
56  {
57  options.merge(*dict);
58  }
59  }
60 
61  // Format specification. Merge from all levels
62  // - allow REGEX search
63  if (!formatName.empty())
64  {
65  for (const dictionary* dict : dicts)
66  {
67  if
68  (
69  dict
70  && (dict = dict->findDict(formatName)) != nullptr
71  )
72  {
73  options.merge(*dict);
74  }
75  }
76  }
77 
78  return options;
79 }
80 
81 } // End namespace Foam
82 
83 
84 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
85 
87 (
88  const dictionary& dict,
89  const word& formatName,
90  const word& entryName
91 )
92 {
94  (
95  formatName,
96  {
97  dict.findDict(entryName, keyType::LITERAL)
98  }
99  );
100 }
101 
102 
104 (
105  const dictionary& dict,
106  const dictionary& altDict,
107  const word& formatName,
108  const word& entryName
109 )
110 {
111  return combineFormatOptions
112  (
113  formatName,
114  {
115  dict.findDict(entryName, keyType::LITERAL),
116  altDict.findDict(entryName, keyType::LITERAL)
117  }
118  );
119 }
120 
121 
122 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
dictionary getFormatOptions(const dictionary &dict, const word &formatName, const word &entryName="formatOptions")
Find "formatOptions" in a top-level dictionary. Extract and merge &#39;default&#39; + formatName values...
Definition: fileFormats.C:80
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:799
A class for handling words, derived from Foam::string.
Definition: word.H:63
String literal.
Definition: keyType.H:82
static dictionary combineFormatOptions(const word &formatName, std::initializer_list< const dictionary *> dicts)
Definition: fileFormats.C:33
Namespace for OpenFOAM.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124