Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
e3f681fa
Commit
e3f681fa
authored
Feb 17, 2020
by
Mark OLESEN
Browse files
ENH: support use of IOstreamOption for IFstream/OFstream
- can be convenient to bundle IO options as a single parameter
parent
f3106ec1
Changes
19
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C
View file @
e3f681fa
...
...
@@ -80,20 +80,14 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
Foam
::
IFstream
::
IFstream
(
const
fileName
&
pathname
,
streamFormat
format
,
versionNumber
version
IOstreamOption
streamOpt
)
:
Detail
::
IFstreamAllocator
(
pathname
),
ISstream
(
*
allocatedPtr_
,
pathname
,
format
,
version
,
IFstreamAllocator
::
detectedCompression_
)
ISstream
(
*
allocatedPtr_
,
pathname
,
streamOpt
)
{
IOstream
::
compression
(
IFstreamAllocator
::
detectedCompression_
);
setClosed
();
setState
(
allocatedPtr_
->
rdstate
());
...
...
src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H
View file @
e3f681fa
...
...
@@ -100,10 +100,20 @@ public:
explicit
IFstream
(
const
fileName
&
pathname
,
streamFormat
format
=
ASCII
,
versionNumber
version
=
currentVersion
IOstreamOption
streamOpt
=
IOstreamOption
()
);
//- Construct from pathname, format (version)
IFstream
(
const
fileName
&
pathname
,
streamFormat
fmt
,
versionNumber
ver
=
currentVersion
)
:
IFstream
(
pathname
,
IOstreamOption
(
fmt
,
ver
))
{}
//- Destructor
~
IFstream
()
=
default
;
...
...
src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C
View file @
e3f681fa
...
...
@@ -111,21 +111,12 @@ Foam::Detail::OFstreamAllocator::OFstreamAllocator
Foam
::
OFstream
::
OFstream
(
const
fileName
&
pathname
,
streamFormat
format
,
versionNumber
version
,
compressionType
compression
,
IOstreamOption
streamOpt
,
const
bool
append
)
:
Detail
::
OFstreamAllocator
(
pathname
,
compression
,
append
),
OSstream
(
*
allocatedPtr_
,
pathname
,
format
,
version
,
compression
)
Detail
::
OFstreamAllocator
(
pathname
,
streamOpt
.
compression
(),
append
),
OSstream
(
*
allocatedPtr_
,
pathname
,
streamOpt
)
{
setClosed
();
setState
(
allocatedPtr_
->
rdstate
());
...
...
src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H
View file @
e3f681fa
...
...
@@ -102,12 +102,23 @@ public:
explicit
OFstream
(
const
fileName
&
pathname
,
streamFormat
format
=
ASCII
,
versionNumber
version
=
currentVersion
,
compressionType
compression
=
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
append
=
false
);
//- Construct from pathname, format (version, compression)
OFstream
(
const
fileName
&
pathname
,
streamFormat
fmt
,
versionNumber
ver
=
currentVersion
,
compressionType
comp
=
compressionType
::
UNCOMPRESSED
,
const
bool
append
=
false
)
:
OFstream
(
pathname
,
IOstreamOption
(
fmt
,
comp
,
ver
),
append
)
{}
//- Destructor
~
OFstream
()
=
default
;
...
...
src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C
View file @
e3f681fa
...
...
@@ -184,16 +184,14 @@ void Foam::masterOFstream::commit()
Foam
::
masterOFstream
::
masterOFstream
(
const
fileName
&
pathName
,
streamFormat
format
,
versionNumber
version
,
compressionType
compression
,
IOstreamOption
streamOpt
,
const
bool
append
,
const
bool
valid
)
:
OStringStream
(
format
,
version
),
OStringStream
(
streamOpt
.
format
(),
streamOpt
.
version
()
),
pathName_
(
pathName
),
compression_
(
compression
),
compression_
(
streamOpt
.
compression
()
),
append_
(
append
),
valid_
(
valid
)
{}
...
...
src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H
View file @
e3f681fa
...
...
@@ -86,17 +86,35 @@ public:
// Constructors
//- Construct and set stream status
//- Construct
from pathname
and set stream status
explicit
masterOFstream
(
const
fileName
&
pathname
,
streamFormat
format
=
ASCII
,
versionNumber
version
=
currentVersion
,
compressionType
compression
=
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
append
=
false
,
const
bool
valid
=
true
);
//- Construct from pathname, version and set stream status
masterOFstream
(
const
fileName
&
pathname
,
streamFormat
fmt
,
versionNumber
ver
=
currentVersion
,
compressionType
comp
=
compressionType
::
UNCOMPRESSED
,
const
bool
append
=
false
,
const
bool
valid
=
true
)
:
masterOFstream
(
pathname
,
IOstreamOption
(
fmt
,
comp
,
ver
),
append
,
valid
)
{}
//- Destructor - commits buffered information to file
~
masterOFstream
();
...
...
src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H
View file @
e3f681fa
...
...
@@ -28,6 +28,7 @@ Class
Description
A simple output token stream that can be used to build token lists.
Always UNCOMPRESSED.
Note
Appending single characters to token list is fragile.
...
...
@@ -63,13 +64,23 @@ public:
// Constructors
//- Default construct, set stream status
explicit
OTstream
(
IOstreamOption
streamOpt
=
IOstreamOption
())
:
Ostream
(
streamOpt
.
format
(),
streamOpt
.
version
()),
DynamicList
<
token
>
()
{
setOpened
();
setGood
();
}
//- Construct with format, version
explicit
OTstream
(
streamFormat
f
ormat
=
ASCII
,
versionNumber
ver
sion
=
currentVersion
streamFormat
f
mt
,
versionNumber
ver
=
currentVersion
)
:
Ostream
(
f
orma
t
,
ver
sion
),
Ostream
(
f
m
t
,
ver
),
DynamicList
<
token
>
()
{
setOpened
();
...
...
src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C
View file @
e3f681fa
...
...
@@ -199,10 +199,8 @@ bool Foam::fileOperations::collatedFileOperation::appendObject
OFstream
os
(
pathName
,
IOstream
::
BINARY
,
ver
,
IOstream
::
UNCOMPRESSED
,
// no compression
!
isMaster
IOstreamOption
(
IOstream
::
BINARY
,
ver
),
// UNCOMPRESSED
!
isMaster
// append slaves
);
if
(
!
os
.
good
())
...
...
@@ -488,10 +486,8 @@ bool Foam::fileOperations::collatedFileOperation::writeObject
masterOFstream
os
(
pathName
,
fmt
,
ver
,
cmp
,
false
,
IOstreamOption
(
fmt
,
ver
,
cmp
),
false
,
// append=false
valid
);
...
...
@@ -534,10 +530,8 @@ bool Foam::fileOperations::collatedFileOperation::writeObject
masterOFstream
os
(
pathName
,
fmt
,
ver
,
cmp
,
false
,
IOstreamOption
(
fmt
,
ver
,
cmp
),
false
,
// append=false
valid
);
...
...
@@ -596,9 +590,7 @@ bool Foam::fileOperations::collatedFileOperation::writeObject
(
writer_
,
pathName
,
fmt
,
ver
,
cmp
,
IOstreamOption
(
fmt
,
ver
,
cmp
),
useThread
);
...
...
src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C
View file @
e3f681fa
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -35,16 +36,14 @@ Foam::threadedCollatedOFstream::threadedCollatedOFstream
(
OFstreamCollator
&
writer
,
const
fileName
&
pathName
,
streamFormat
format
,
versionNumber
version
,
compressionType
compression
,
IOstreamOption
streamOpt
,
const
bool
useThread
)
:
OStringStream
(
format
,
version
),
OStringStream
(
streamOpt
.
format
(),
streamOpt
.
version
()
),
writer_
(
writer
),
pathName_
(
pathName
),
compression_
(
compression
),
compression_
(
streamOpt
.
compression
()
),
useThread_
(
useThread
)
{}
...
...
@@ -61,7 +60,7 @@ Foam::threadedCollatedOFstream::~threadedCollatedOFstream()
IOstream
::
BINARY
,
version
(),
compression_
,
false
,
// append
false
,
// append
=false
useThread_
);
}
...
...
src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H
View file @
e3f681fa
...
...
@@ -72,14 +72,32 @@ public:
//- Construct and set stream status
threadedCollatedOFstream
(
OFstreamCollator
&
,
OFstreamCollator
&
writer
,
const
fileName
&
pathname
,
streamFormat
format
=
ASCII
,
versionNumber
version
=
currentVersion
,
compressionType
compression
=
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
useThread
=
true
);
//- Construct and set stream status
threadedCollatedOFstream
(
OFstreamCollator
&
writer
,
const
fileName
&
pathname
,
streamFormat
fmt
,
versionNumber
ver
=
currentVersion
,
compressionType
comp
=
compressionType
::
UNCOMPRESSED
,
const
bool
useThread
=
true
)
:
threadedCollatedOFstream
(
writer
,
pathname
,
IOstreamOption
(
fmt
,
ver
,
comp
),
useThread
)
{}
//- Destructor
~
threadedCollatedOFstream
();
...
...
src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
View file @
e3f681fa
...
...
@@ -466,7 +466,7 @@ bool Foam::fileOperation::writeObject
const
regIOobject
&
io
,
IOstream
::
streamFormat
fmt
,
IOstream
::
versionNumber
ver
,
IOstream
::
compressionType
cmp
,
IOstream
::
compressionType
c
o
mp
,
const
bool
valid
)
const
{
...
...
@@ -478,21 +478,15 @@ bool Foam::fileOperation::writeObject
autoPtr
<
OSstream
>
osPtr
(
NewOFstream
(
pathName
,
fmt
,
ver
,
cmp
)
NewOFstream
(
pathName
,
IOstreamOption
(
fmt
,
ver
,
comp
))
);
if
(
!
osPtr
.
valid
()
)
if
(
!
osPtr
)
{
return
false
;
}
Ostream
&
os
=
osPtr
();
O
S
stream
&
os
=
osPtr
();
// If any of these fail, return (leave error handling to Ostream class)
if
(
!
os
.
good
())
...
...
src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
View file @
e3f681fa
...
...
@@ -409,10 +409,10 @@ public:
// suppress empty local lagrangian data)
virtual
bool
writeObject
(
const
regIOobject
&
,
IOstream
::
streamFormat
f
ormat
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
ver
sion
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
comp
ression
=
IOstream
::
UNCOMPRESSED
,
const
regIOobject
&
io
,
IOstream
::
streamFormat
f
mt
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
ver
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
comp
=
IOstream
::
UNCOMPRESSED
,
const
bool
valid
=
true
)
const
;
...
...
@@ -430,9 +430,7 @@ public:
virtual
autoPtr
<
OSstream
>
NewOFstream
(
const
fileName
&
pathname
,
IOstream
::
streamFormat
format
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
version
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
compression
=
IOstream
::
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
valid
=
true
)
const
=
0
;
...
...
src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
View file @
e3f681fa
...
...
@@ -2246,7 +2246,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::writeObject
const
regIOobject
&
io
,
IOstream
::
streamFormat
fmt
,
IOstream
::
versionNumber
ver
,
IOstream
::
compressionType
cmp
,
IOstream
::
compressionType
c
o
mp
,
const
bool
valid
)
const
{
...
...
@@ -2266,13 +2266,11 @@ bool Foam::fileOperations::masterUncollatedFileOperation::writeObject
NewOFstream
(
pathName
,
fmt
,
ver
,
cmp
,
IOstreamOption
(
fmt
,
ver
,
comp
),
valid
)
);
Ostream
&
os
=
osPtr
();
O
S
stream
&
os
=
osPtr
();
// If any of these fail, return (leave error handling to Ostream class)
if
(
!
os
.
good
())
...
...
@@ -2549,9 +2547,7 @@ Foam::autoPtr<Foam::OSstream>
Foam
::
fileOperations
::
masterUncollatedFileOperation
::
NewOFstream
(
const
fileName
&
pathName
,
IOstream
::
streamFormat
fmt
,
IOstream
::
versionNumber
ver
,
IOstream
::
compressionType
cmp
,
IOstreamOption
streamOpt
,
const
bool
valid
)
const
{
...
...
@@ -2560,10 +2556,8 @@ Foam::fileOperations::masterUncollatedFileOperation::NewOFstream
new
masterOFstream
(
pathName
,
fmt
,
ver
,
cmp
,
false
,
// append
streamOpt
,
false
,
// append=false
valid
)
);
...
...
src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
View file @
e3f681fa
...
...
@@ -487,7 +487,7 @@ public:
TypeName
(
"masterUncollated"
);
// Static
d
ata
// Static
D
ata
//- Max size of parallel communications. Switches from non-blocking
// to scheduled when reading/writing files. Read as float to enable
...
...
@@ -696,7 +696,7 @@ public:
// Returns success state.
virtual
bool
writeObject
(
const
regIOobject
&
,
const
regIOobject
&
io
,
IOstream
::
streamFormat
format
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
version
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
compression
=
IOstream
::
UNCOMPRESSED
,
...
...
@@ -710,9 +710,7 @@ public:
virtual
autoPtr
<
OSstream
>
NewOFstream
(
const
fileName
&
pathname
,
IOstream
::
streamFormat
format
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
version
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
compression
=
IOstream
::
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
valid
=
true
)
const
;
...
...
src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
View file @
e3f681fa
...
...
@@ -724,13 +724,11 @@ Foam::autoPtr<Foam::OSstream>
Foam
::
fileOperations
::
uncollatedFileOperation
::
NewOFstream
(
const
fileName
&
pathName
,
IOstream
::
streamFormat
fmt
,
IOstream
::
versionNumber
ver
,
IOstream
::
compressionType
cmp
,
IOstreamOption
streamOpt
,
const
bool
valid
)
const
{
return
autoPtr
<
OSstream
>
(
new
OFstream
(
pathName
,
fmt
,
ver
,
cmp
));
return
autoPtr
<
OSstream
>
(
new
OFstream
(
pathName
,
streamOpt
));
}
...
...
src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
View file @
e3f681fa
...
...
@@ -282,9 +282,7 @@ public:
virtual
autoPtr
<
OSstream
>
NewOFstream
(
const
fileName
&
pathname
,
IOstream
::
streamFormat
format
=
IOstream
::
ASCII
,
IOstream
::
versionNumber
version
=
IOstream
::
currentVersion
,
IOstream
::
compressionType
compression
=
IOstream
::
UNCOMPRESSED
,
IOstreamOption
streamOpt
=
IOstreamOption
(),
const
bool
valid
=
true
)
const
;
};
...
...
src/fileFormats/obj/OBJstream.C
View file @
e3f681fa
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -63,12 +64,10 @@ void Foam::OBJstream::writeAndCheck(const char c)
Foam
::
OBJstream
::
OBJstream
(
const
fileName
&
pathname
,
streamFormat
format
,
versionNumber
version
,
compressionType
compression
IOstreamOption
streamOpt
)
:
OFstream
(
pathname
,
format
,
version
,
compression
),
OFstream
(
pathname
,
streamOpt
),
startOfLine_
(
true
),
nVertices_
(
0
)
{}
...
...
src/fileFormats/obj/OBJstream.H
View file @
e3f681fa
...
...
@@ -83,11 +83,21 @@ public:
explicit
OBJstream
(
const
fileName
&
pathname
,
streamFormat
format
=
ASCII
,
versionNumber
version
=
currentVersion
,
compressionType
compression
=
UNCOMPRESSED
IOstreamOption
streamOpt
=
IOstreamOption
()
);
//- Construct from pathname
OBJstream
(
const
fileName
&
pathname
,
streamFormat
fmt
,
versionNumber
ver
=
currentVersion
,
compressionType
comp
=
compressionType
::
UNCOMPRESSED
)
:
OBJstream
(
pathname
,
IOstreamOption
(
fmt
,
ver
,
comp
))
{}
//- Destructor
~
OBJstream
()
=
default
;
...
...
src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C
View file @
e3f681fa
...
...
@@ -142,13 +142,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
)
);
OFstream
os
(
objectDir
/
io
.
name
(),
t
.
writeFormat
(),
IOstream
::
currentVersion
,
t
.
writeCompression
()
);
OFstream
os
(
objectDir
/
io
.
name
(),
t
.
writeStreamOption
());
io
.
writeHeader
(
os
);
...
...
@@ -174,13 +168,8 @@ void Foam::MeshedSurfaceProxy<Face>::write
)
);
OFstream
os
(
objectDir
/
io
.
name
(),
t
.
writeFormat
(),
IOstream
::
currentVersion
,
t
.
writeCompression
()
);
OFstream
os
(
objectDir
/
io
.
name
(),
t
.
writeStreamOption
());
io
.
writeHeader
(
os
);
if
(
this
->
useFaceMap
())
...
...
@@ -212,8 +201,9 @@ void Foam::MeshedSurfaceProxy<Face>::write
)
);
//
w
rite as
ascii
//
W
rite as
ASCII-only
OFstream
os
(
objectDir
/
io
.
name
());
io
.
writeHeader
(
os
);
os
<<
this
->
surfZones
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment