IOstreamOption.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) 2018 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 "IOstreamOption.H"
29 #include "error.H"
30 #include "Enum.H"
31 #include "Switch.H"
32 
33 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
34 
37 
40 
41 
42 const Foam::Enum
43 <
45 >
47 ({
48  { streamFormat::ASCII, "ascii" },
49  { streamFormat::BINARY, "binary" },
50 });
51 
52 
53 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
54 
57 {
58  // Handle bad input graciously
59  if (formatNames.found(formatName))
60  {
61  return formatNames[formatName];
62  }
63 
65  << "Unknown format specifier '" << formatName
66  << "', using 'ascii'" << endl;
67 
68  return streamFormat::ASCII;
69 }
70 
71 
74 {
75  // Handle bad input graciously
76 
77  const Switch sw(compName, true);
78  if (sw.valid())
79  {
80  return
81  (
82  sw
83  ? compressionType::COMPRESSED
84  : compressionType::UNCOMPRESSED
85  );
86  }
87 
89  << "Unknown compression specifier '" << compName
90  << "', assuming no compression" << endl;
91 
92  return compressionType::UNCOMPRESSED;
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
97 
98 Foam::Ostream& Foam::operator<<
99 (
100  Ostream& os,
102 )
103 {
104  os << IOstreamOption::formatNames[sf];
105  return os;
106 }
107 
108 
109 Foam::Ostream& Foam::operator<<
110 (
111  Ostream& os,
113 )
114 {
115  // Emit as char sequence instead of as individual characters
116  // in case this is needed for sending in parallel.
117  os << vn.str().c_str();
118  return os;
119 }
120 
121 
122 // ************************************************************************* //
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:70
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Enum::found
bool found(const word &enumName) const
Test if there is an enumeration corresponding to the given name.
Definition: EnumI.H:88
Foam::Switch::valid
bool valid() const noexcept
True if the Switch represents a valid enumeration.
Definition: Switch.C:203
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
error.H
IOstreamOption.H
Switch.H
Foam::IOstreamOption::compressionEnum
static compressionType compressionEnum(const word &compName)
The compression enum corresponding to the string.
Definition: IOstreamOption.C:73
Foam::IOstreamOption::originalVersion
static const versionNumber originalVersion
The original version number.
Definition: IOstreamOption.H:190
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::IOstreamOption::formatEnum
static streamFormat formatEnum(const word &formatName)
The stream format enum corresponding to the string.
Definition: IOstreamOption.C:56
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::IOstreamOption::formatNames
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary)
Definition: IOstreamOption.H:187
Enum.H