formattingEntry.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) 2023 Sergey Lesnik
9  Copyright (C) 2023-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::formattingEntry
29 
30 Description
31  A dictionary entry writing only contents by default, used to save
32  formatting symbols for the final output
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef Foam_formattingEntry_H
37 #define Foam_formattingEntry_H
38 
39 #include "primitiveEntry.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class formattingEntry Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class formattingEntry
51 :
52  public primitiveEntry
53 {
54  // Private Data
55 
56  //- The output visibility
57  bool active_ = true;
58 
59 public:
60 
61  // Static Member Functions
62 
63  //- Generate an entry keyword: "__format-entry__NNN".
64  //- The generated names are unlikely to collide with user dictionaries
65  static keyType defaultName(label n)
66  {
67  return keyType
68  (
69  "__format-entry__" + std::to_string(n),
71  );
72  }
73 
74 
75  // Constructors
76 
77  //- Inherit all constructors from primitiveEntry
79 
80  //- Construct with character data, using the provided keyword
81  formattingEntry(const keyType& key, const char* s, std::streamsize len);
82 
83  //- Construct with character data, using the provided keyword
84  formattingEntry(const keyType& key, const std::string& content);
85 
86  //- Construct with character data, using the provided keyword
87  formattingEntry(const keyType& key, std::string&& content);
88 
89  //- Construct with character data, using a generated keyword
90  formattingEntry(const label n, const char* s, std::streamsize len)
91  :
93  {}
94 
95  //- Construct with character data, using a generated keyword
96  formattingEntry(const label n, const std::string& content)
97  :
98  formattingEntry(defaultName(n), content)
99  {}
100 
101  //- Construct with character data, using a generated keyword
102  formattingEntry(const label n, std::string&& content)
103  :
104  formattingEntry(defaultName(n), std::move(content))
105  {}
106 
107  //- Construct with token data, using a generated keyword
108  formattingEntry(const label n, token&& tok, bool visible=true)
109  :
110  primitiveEntry(defaultName(n), std::move(tok)),
111  active_(visible)
112  {}
114  //- Clone the entry
115  virtual autoPtr<entry> clone(const dictionary&) const
116  {
117  return autoPtr<entry>(new formattingEntry(*this));
118  }
119 
120 
121  // Factory Methods
122 
123 
124  // Member Functions
125 
126  //- Set output visibility on/off.
127  // \return the previous value
128  bool active(bool on) noexcept
129  {
130  bool old(active_);
131  active_ = on;
132  return old;
133  }
134 
135  //- Get the output visibility
136  bool active() const noexcept
137  {
138  return active_;
139  }
140 
141  //- Write content without the keyword.
142  // Special properties:
143  // - ignores any bad tokens on output.
144  virtual void write(Ostream& os) const;
145 };
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 } // End namespace Foam
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #endif
155 
156 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:66
A dictionary entry writing only contents by default, used to save formatting symbols for the final ou...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A token holds an item read from Istream.
Definition: token.H:65
formattingEntry(const keyType &key, const char *s, std::streamsize len)
Construct with character data, using the provided keyword.
bool active() const noexcept
Get the output visibility.
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read...
String literal.
Definition: keyType.H:82
static keyType defaultName(label n)
Generate an entry keyword: "__format-entry__NNN". The generated names are unlikely to collide with us...
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:76
virtual void write(Ostream &os) const
Write content without the keyword.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
label n
primitiveEntry(const keyType &key)
Construct from keyword and no tokens.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.