Commit Graph

37 Commits

Author SHA1 Message Date
Mark Olesen
459aaad0f9 ENH: improve robustness of raw reading, file size checks
- use ignore instead of seekg/tellg to swallow input (robuster)

- check for bad gcount() values

- wrap Foam::fileSize() compressed/uncompressed handling into IFstream.

- improve handling of compressed files in masterUncollatedFileOperation.
  Previously read into a string via stream iterators.
  Now read chunk-wise into a List of char for fewer reallocations.
2023-09-01 14:44:49 +00:00
Mark Olesen
12916cd7a3 ENH: additional fstream pointer constructors with IOstreamOption
- allow future tweaking based on the target stream format.

- add ifstreamPointer::open().
  Allows default construct followed by open()
2023-08-29 11:24:13 +02:00
Mark Olesen
5338e56c73 ENH: add support for OFstream atomic file creation (#2631)
- with ATOMIC, an intermediary file is created - eg, (fileAbc~tmp~)
  where all of the output is written to. When the stream goes out of
  scope, this intermediary file is moved/renamed to the actually
  output name - eg, (fileAbc~tmp~) -> (fileAbc).

  This adds some safety if the simulation crashes while writing the
  file, since it will the partial (corrupt) file will be left
  behind as (fileAbc~tmp~) and not as (fileAbc), which means it will
  will be treated as a backup file and not loaded again on restart.

ENH: provided enumeration for APPEND/NON_APPEND

- clearer than using bool (with comments).
  Since append mode is primarily only used by masterOFstream etc
  this change is unlikely to affect user coding.

ENH: use file atomic for ensight file creation

- avoids corrupt (truncated) files being referenced by the ensight
  case file if the simulation crashes while writing the ensight file.
2022-11-15 14:10:01 +01:00
Mark Olesen
221c3c0200 ENH: add OFstream rewind() method.
- truncates output file, handles compressed streams
2021-03-23 18:00:14 +01:00
Mark Olesen
e8cf2a2c62 ENH: more consistent use of IOstreamOption
- improves interface and data consistency.
  Older signatures are still active (via the Foam_IOstream_extras
  define).

- refine internals for IOstreamOption streamFormat, versionNumber

ENH: improve data alignment for IOstream and IOobject

- fit sizeof label/scalar into unsigned char

STYLE: remove dead code
2021-03-16 08:47:59 +00:00
Mark Olesen
6e2b7be983 ENH: direct access to wrapped ifstream/ofstream with compression (#1805)
- previously hidden as Detail::[IO]FstreamAllocator, now exposed
  directly as [io]fstreamPointer, which allows reuse for
  std::ifstream, std::ofstream wrapping, without the additional
  ISstream, OSstream layers.

  These stream pointers have some characteristics similar to a
  unique_ptr.

- restrict direct gzstream usage to two files (fstreamPointers.C,
  gzstream.C) which improves localization and makes it simpler to
  enable/disable with the `HAVE_LIBZ` define.

  The HAVE_LIBZ define is currently simply hard-coded in the
  Make/options.

  If compiled WITHOUT libz support:
    - reading gz files : FatalError
    - writing gz files : emit warning and downgrade to uncompressed
    - warn if compression is specified in the case controlDict
      and downgrade to uncompressed

ENH: minor updates to gzstream interface for C++11

- support construct/open with std::string for the file names.

CONFIG: provisioning for have_libz detection as wmake/script
2020-08-10 12:40:08 +02:00
Mark Olesen
e3f681fa59 ENH: support use of IOstreamOption for IFstream/OFstream
- can be convenient to bundle IO options as a single parameter
2020-02-18 21:51:36 +01:00
Mark Olesen
f3106ec146 STYLE: use unique_ptr for Fstream resource management
STYLE: change return type of NewOFstream from Ostream to OSstream
2020-02-18 21:51:35 +01:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
36fae9fd98 ENH: open standard file streams with ios_base::binary
- this improves overall consistency and is independent of higher level
  tagging as ASCII or BINARY for IFstream, OFstream etc.
2019-04-02 22:05:13 +02:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00
Mark Olesen
a5cc0ffcad STYLE: use const reference for caught exceptions 2019-01-23 09:03:06 +01:00
Mark Olesen
2f567e53de COMP: silence some compiler warnings/errors
- catch (value)
- forward declarations for operator<<()
- non-const access to Reaction name()
- spurious return statement
2018-05-07 17:21:56 +02:00
Mark Olesen
53ae09ad04 STYLE: relocate stream allocators to Detail namespace 2018-04-13 10:24:22 +02:00
Mark Olesen
af5f857618 ENH: add reset() method to IStringStream
- for convenience and symmetry with OStringStream

STYLE: void return value for stream rewind() methods

- this makes it easier to design bidirectional streams
2017-10-23 07:50:12 +02:00
Mark Olesen
db376a412d ENH: improved behaviour of input stream rewind (issue #534)
- clear error flags. Special handling for igzstream.
2017-07-18 11:10:51 +02:00
Mark Olesen
86ef9e86dc ENH: make treatment of stream allocators more uniform (issue #532)
- use allocator class to wrap the stream pointers instead of passing
  them into ISstream, OSstream and using a dynamic cast to delete
  then. This is especially important if we will have a bidirectional
  stream (can't delete twice!).

STYLE:

- file stream constructors with std::string (C++11)

- for rewind, explicit about in|out direction. This is not currently
  important, but avoids surprises with any future bidirectional access.

- combined string streams in StringStream.H header.
  Similar to <sstream> include that has both input and output string
  streams.
2017-07-17 15:14:38 +02:00
Mark Olesen
a4c81f5962 ENH: make streams name() methods virtual throughout (issue #479) 2017-07-04 17:17:09 +02:00
Henry Weller
58f905ff70 C++11: Replaced the C NULL with the safer C++11 nullptr
Requires gcc version 4.7 or higher
2016-08-05 17:19:38 +01:00
Henry Weller
68e86f97fe Info -> InfoInFunction and updated comments 2016-01-20 10:18:13 +00:00
Henry Weller
a4ab3f61db src/OpenFOAM: Update ...ErrorIn -> ...ErrorInFunction
Avoids the clutter and maintenance effort associated with providing the
function signature string.
2015-11-08 12:23:52 +00:00
mattijs
8e968f5647 STYLE: debug: move debug declaration into Foam namespace 2012-12-11 09:33:20 +00:00
Henry
c2dd153a14 Copyright transfered to the OpenFOAM Foundation 2011-08-14 12:17:30 +01:00
andy
eaef8d482b STYLE: Updated 1991 start copyright year to 2004 2011-01-14 16:08:00 +00:00
andy
099cc39e2e Revert "STYLE: 2011 copyright date."
This reverts commit b18f6cc1ce.
2011-01-05 18:24:29 +00:00
graham
b18f6cc1ce STYLE: 2011 copyright date. 2011-01-05 11:14:26 +00:00
graham
d79237597e STYLE: Fixing code style requirements for all src. 2010-07-28 13:31:46 +01:00
Mark Olesen
d29c438657 STYLE: use url for FSF license instead of postal address, switch to GPL v3 2010-03-29 14:07:56 +02:00
Mark Olesen
2792624996 Expose STL std streams in a consistent manner for serial streams.
Previously Fstreams had stdStream() as a public member and the other
streams had stream() as a protected member.

All serial streams now have public method stdStream() and the stream()
method has been eliminated. This is not only more consistent, but also
avoids confusion (for the programmer, not the compiler) with the
ITstream::stream() method.
2009-12-21 10:24:35 +01:00
Mark Olesen
7544164d53 regIOobject, Hasher, IOobject tweak
- regIOobject: don't re-register an unregister object on rename/assignment
- Hasher: split-off HasherInt with uint32_t specializations
- IOobject: writeBanner/writeDivider return Stream for easier chaining.

... also dropped some namespace bracketing while I was at it.
2009-03-05 12:06:57 +01:00
Mark Olesen
ffd9bb08a8 OSspecific: altered file tests
- removed the previously added fileName type(), isDir(), isFile() methods.

- added optional bool parameter to isFile() function to explicitly
  enable/disable the check for gzip files.

- fixed minor bugginess where the default usage of isFile() would result in
  false positive matches.

- be slightly more stringent and use isDir() and isFile() instead of
  exists() function when we actually know the expected type.
2009-02-06 10:25:41 +01:00
Mark Olesen
e5c5829244 OSspecific: isDir(), isFile() instead of dir(), file() 2009-02-02 16:50:18 +01:00
Mark Olesen
95dcb6ded7 Simplify checking of container (List/HashTable, strings) sizes
- can use 'XX.empty()' instead of 'XX.size() == 0', 'XX.size() < 1' or
  'XX.size() <= 0' or for simpler coding.
  It also has the same number of characters as '!XX.size()' and /might/ be
  more readable

- many size checking had 'XX.size() > 0', 'XX.size() != 0', or 'XX.size() >= 1'
  when a simple 'XX.size()' suffices
2009-01-10 20:28:06 +01:00
Mark Olesen
1d866d7fe8 reworked IOstreams
- Istream and Ostream now retain backslashes when reading/writing strings.
  The previous implementation simply discarded them, except when used to
  escape a double-quote or a newline. It is now vitally important to retain
  them, eg for quoting regular expression meta-characters.

  The backslash continues to be used as an escape character for double-quote
  and newline, but otherwise get passed through "as-is" without any other
  special meaning (ie, they are *NOT* C-style strings). This helps avoid
  'backslash hell'!
  For example,
     string:   "match real dots \.+, question mark \? or any char .*"
     C-style:  "match real dots \\.+, question mark \\? or any char .*"

- combined subfiles in db/IOstreams, some had more copyright info than code
- OPstreamI.H contained only private methods, moved into OPstream.C

Are these really correct?
   IOstreams/Istream.H:#   include "HashTable.C"
   token/token.H:#define NoHashTableC
2009-01-03 12:52:27 +01:00
Mark Olesen
28b200bcd9 update copyrights for 2009 2008-12-31 19:01:56 +01:00
Mark Olesen
02cabc3cf2 updated Copyright (C) \d+-2008 OpenCFD Ltd. 2008-06-25 15:01:46 +02:00
OpenFOAM-admin
3170c7c0c9 Creation of OpenFOAM-dev repository 15/04/2008 2008-04-15 18:56:58 +01:00