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 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 public:
55 
56  // Static Member Functions
57 
58  //- Generate a default entry keyword: "__format-entry__NNN"
59  // The generated names are unlikely to collide with user dictionaries
60  static keyType defaultName(label n)
61  {
62  return keyType
63  (
64  "__format-entry__" + std::to_string(n),
66  );
67  }
68 
69 
70  // Constructors
71 
72  //- Inherit all constructors from primitiveEntry
74 
75  //- Construct with character data, using the provided keyword
76  formattingEntry(const keyType& key, const char* s, std::streamsize len);
77 
78  //- Construct with character data, using the provided keyword
79  formattingEntry(const keyType& key, const std::string& content);
80 
81  //- Construct with character data, using the provided keyword
82  formattingEntry(const keyType& key, std::string&& content);
83 
84  //- Construct with character data, using a generated keyword
85  formattingEntry(const label n, const char* s, std::streamsize len)
86  :
88  {}
89 
90  //- Construct with character data, using a generated keyword
91  formattingEntry(const label n, const std::string& content)
92  :
93  formattingEntry(defaultName(n), content)
94  {}
95 
96  //- Construct with character data, using a generated keyword
97  formattingEntry(const label n, std::string&& content)
98  :
99  formattingEntry(defaultName(n), std::move(content))
100  {}
101 
102 
103  //- Clone the entry
104  virtual autoPtr<entry> clone(const dictionary&) const
105  {
106  return autoPtr<entry>(new formattingEntry(*this));
107  }
108 
109 
110  // Factory Methods
111 
112 
113  // Member Functions
114 
115  //- Write content without the keyword.
116  // Special properties:
117  // - ignores any bad tokens on output.
118  virtual void write(Ostream& os) const;
119 };
120 
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 } // End namespace Foam
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 #endif
129 
130 // ************************************************************************* //
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
formattingEntry(const keyType &key, const char *s, std::streamsize len)
Construct with character data, using the provided keyword.
formattingEntry(const label n, const char *s, std::streamsize len)
Construct with character data, using a generated keyword.
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 a default entry keyword: "__format-entry__NNN".
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
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.