ensightReadFile.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) 2016-2023 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::ensightReadFile
28 
29 Description
30  A variant of IFstream with specialised read() for
31  strings, integers and floats.
32  Correctly handles binary read as well.
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef Foam_ensightReadFile_H
37 #define Foam_ensightReadFile_H
38 
39 #include "IFstream.H"
40 #include "IOstream.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class ensightReadFile Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class ensightReadFile
52 :
53  public IFstream
54 {
55 public:
56 
57  // Generated Methods
58 
59  //- No copy construct
60  ensightReadFile(const ensightReadFile&) = delete;
61 
62  //- No copy assignment
63  void operator=(const ensightReadFile&) = delete;
64 
65 
66  // Constructors
67 
68  //- Construct from pathname, auto-detect the format
69  explicit ensightReadFile(const fileName& pathname);
70 
71  //- Construct from pathname, use the specified (ascii/binary) format
73  (
74  const fileName& pathname,
76  );
77 
78 
79  //- Destructor
80  ~ensightReadFile() = default;
81 
82 
83  // Static Functions
84 
85  //- Detect if the file is \em binary by testing for initial
86  //- "(C|Fortran) Binary"
88  (
89  const fileName& pathname
90  );
91 
92 
93  // Read Functions
94 
95  //- Inherit read from Istream
96  using Istream::read;
97 
98  //- Binary read
99  virtual Istream& read(char* buf, std::streamsize count) override;
100 
101  //- Read string as "%80s" or as binary
102  virtual Istream& read(string& value) override;
103 
104  //- Read integer as "%10d" or as binary
105  virtual Istream& read(label& value) override;
106 
107  //- Read floating-point as "%12.5e" or as binary
108  virtual Istream& read(float& value) override;
109 
110  //- Read floating-point as "%12.5e" or as a binary (narrowed) float
111  virtual Istream& read(double& value) override;
112 
113  //- Read element keyword. Currently the same as read(string)
114  Istream& readKeyword(string& key);
115 
116  //- Read "C Binary" for binary files (eg, geometry/measured)
118 };
119 
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 } // End namespace Foam
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 #endif
128 
129 // ************************************************************************* //
virtual Istream & read(char *buf, std::streamsize count) override
Binary read.
A class for handling file names.
Definition: fileName.H:72
ensightReadFile(const ensightReadFile &)=delete
No copy construct.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator=(const ensightReadFile &)=delete
No copy assignment.
static IOstreamOption::streamFormat detectBinaryHeader(const fileName &pathname)
Detect if the file is binary by testing for initial "(C|Fortran) Binary".
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
virtual Istream & read(token &)=0
Return next token from stream.
A variant of IFstream with specialised read() for strings, integers and floats. Correctly handles bin...
Istream & readBinaryHeader()
Read "C Binary" for binary files (eg, geometry/measured)
Input from file stream, using an ISstream.
Definition: IFstream.H:49
~ensightReadFile()=default
Destructor.
Istream & readKeyword(string &key)
Read element keyword. Currently the same as read(string)
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
streamFormat
Data format (ascii | binary)
Namespace for OpenFOAM.