fileRegEx.H
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) 2024 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 Class
27  Foam::substitutionModels::fileRegEx
28 
29 Description
30  The \c fileRegEx substitution model.
31 
32  The example below shows how the keyword \c executionTime is set by
33  applying a regular expression (string) to a log file.
34 
35  \verbatim
36  fileRegEx1
37  {
38  // Mandatory entries
39  type fileRegEx;
40  path "log.simpleFoam";
41 
42  entries
43  {
44  executionTime "ExecutionTime = (.*) s Clock.*";
45  }
46 
47  // Optional entries
48  sectionSeparator <string>;
49  matchSeparator <string>;
50  lastMatch <bool>;
51 
52  // Inherited entries
53  ...
54  }
55  \endverbatim
56 
57  The entries mean:
58  \table
59  Property | Description | Type | Reqd | Deflt
60  type | Type name: functionObjectValue | word | yes | -
61  path | Path to file | string | yes | -
62  entries | Keyword regular-expression pairs | dictionary | yes | -
63  sectionSeparator | Marker used to separate files into sections <!--
64  --!> | string | no | "Time ="
65  matchSeparator | Separator used to join multiple values <!--
66  --!> | string | no | " "
67  lastMatch | Flag to use last file section | bool | no | yes
68  \endtable
69 
70  The inherited entries are elaborated in:
71  - \link substitutionModel.H \endlink
72 
73 SourceFiles
74  fileRegEx.C
75 
76 ---------------------------------------------------------------------------*/
77 
78 #ifndef Foam_substitutionModels_fileRegEx_H
79 #define Foam_substitutionModels_fileRegEx_H
80 
81 #include "substitutionModel.H"
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 namespace Foam
86 {
87 
88 namespace substitutionModels
89 {
90 
91 /*---------------------------------------------------------------------------*\
92  Class fileRegEx Declaration
93 \*---------------------------------------------------------------------------*/
94 
95 class fileRegEx
96 :
97  public substitutionModel
98 {
99  // Private Data
100 
101  //- Path to dictionary
102  const fileName path_;
103 
104  //- Hash table for key and regular expression pairs
105  HashTable<string> entries_;
106 
107  //- Section separator to dive log files, e.g. into time step info
108  const string sectionSeparator_;
109 
110  //- Separator to apply between (multiple) matches
111  const string matchSeparator_;
112 
113  //- Last match wins flag
114  bool lastMatch_;
115 
116 
117  // Private Functions
118 
119  //- No copy construct
120  fileRegEx(const fileRegEx&) = delete;
121 
122  //- No copy assignment
123  void operator=(const fileRegEx&) = delete;
124 
125 
126 public:
127 
128  //- Runtime type information
129  TypeName("fileRegEx");
130 
131 
132  //- Constructor
133  fileRegEx(const dictionary& dict, const Time& time);
134 
135 
136  //- Destructor
137  virtual ~fileRegEx() = default;
138 
139 
140  // Member Functions
141 
142  //- Return true of model applies to this keyName
143  virtual bool valid(const word& keyName) const;
144 
145  //- Apply substitutions to this string buffer
146  virtual bool apply(const word& key, string& buffer) const;
147 
148  //- Return a word list of the keys
149  virtual wordList keys() const;
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace substitutionModels
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
dictionary dict
virtual bool apply(const word &key, string &buffer) const
Apply substitutions to this string buffer.
Definition: fileRegEx.C:76
virtual bool valid(const word &keyName) const
Return true of model applies to this keyName.
Definition: fileRegEx.C:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
auto key(const Type &t) -> std::enable_if_t< std::is_enum_v< Type >, std::underlying_type_t< Type > >
Definition: foamGltfBase.H:103
virtual wordList keys() const
Return a word list of the keys.
Definition: fileRegEx.C:150
virtual ~fileRegEx()=default
Destructor.
TypeName("fileRegEx")
Runtime type information.
Namespace for OpenFOAM.