namedUnitConversionIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "namedUnitConversion.H"
27 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 void Foam::namedUnitConversion::readName(const entry& e)
32 {
33  // Read the entry characters directly
34  OStringStream oss;
35  dynamicCast<const primitiveEntry>(e).write(oss, true);
36  name_ = oss.str();
37 
38  // Beautify slightly by removing unnecessary spaces
39  static const string a(List<char>({token::BEGIN_SQR, token::SPACE}));
40  static const string b(List<char>({token::BEGIN_SQR}));
41  name_.replace(a, b);
42 }
43 
44 
45 void Foam::namedUnitConversion::readName
46 (
47  const word& keyword,
48  const dictionary& dict
49 )
50 {
51  readName(dict.lookupEntry(keyword, false, true));
52 }
53 
54 
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 
58 (
59  const word& keyword,
60  const dictionary& dict
61 )
62 {
63  unitConversion::read(keyword, dict);
64 
65  readName(keyword, dict);
66 }
67 
68 
70 (
71  const word& keyword,
72  const dictionary& dict
73 )
74 {
75  if (unitConversion::readIfPresent(keyword, dict))
76  {
77  readName(keyword, dict);
78  return true;
79  }
80  else
81  {
82  return false;
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
88 
90 {
91  const primitiveEntry e(word::null, is);
92  u.reset(unitConversion(e.stream()));
93  u.readName(e);
94 
95  // Check state of Istream
96  is.check("Istream& operator>>(Istream&, namedUnitConversion&)");
97 
98  return is;
99 }
100 
101 
103 {
104  os << u.name_.c_str();
105 
106  // Check state of Ostream
107  os.check("Ostream& operator<<(Ostream&, const namedUnitConversion&)");
108 
109  return os;
110 }
111 
112 
113 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:667
bool readIfPresent(const word &keyword, const dictionary &)
Update if found in the dictionary.
void read(const word &keyword, const dictionary &)
Update.
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
string & replace(const string &oldStr, const string &newStr, size_type start=0)
In this string replace first occurrence of sub-string oldStr.
Definition: string.C:64
@ BEGIN_SQR
Definition: token.H:111
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
bool readIfPresent(const word &keyword, const dictionary &)
Update if found in the dictionary.
void read(const word &keyword, const dictionary &)
Update.
void reset(const unitConversion &)
Reset the unit conversion.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
volScalarField & b
Definition: createFields.H:25
const dimensionedScalar e
Elementary charge.
const doubleScalar e
Definition: doubleScalar.H:106
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dictionary dict