Files CCore/inc/BinaryFile.h CCore/src/BinaryFile.cpp
A BinaryFile object can be used as a serialization output device. It puts data bytes into the output file. This class is similar to the PrintFile class, but provides binary output capabilities rather than textual.
class BinaryFile : NoCopy , public PutDevBase<BinaryFile>
{
....
public:
// constructors
BinaryFile() noexcept;
explicit BinaryFile(StrLen file_name,FileOpenFlags oflags=Open_ToWrite);
~BinaryFile();
// methods
bool isOpened() const;
void open(StrLen file_name,FileOpenFlags oflags=Open_ToWrite);
void disableExceptions();
void soft_close(FileMultiError &errout);
void close();
void preserveFile();
// put
void do_put(uint8 value);
void do_put(const uint8 *ptr,ulen len);
PtrLen<uint8> do_putRange(ulen len);
void flush();
};
A BinaryFile object can be opened or closed. To output to the particular file, the BinaryFile object must be opened and the file name and open flags must be provided. It can be done using the constructor or the method open(). Default constructor creates an object in the closed state. Non-default opens a file. In case of error an exception is thrown.
Destructor flushes and closes an opened object. Errors are reported.
isOpened() returns true, if the object is opened, and false otherwise.
open() opens a closed object with the given file name and open flags. In case of error an exception is thrown.
close() closes an opened object. In case of error and if there is a pending output error an exception is thrown.
soft_close() does not throw, it returns a group of errors using the FileMultiError object.
disableExceptions() disables exceptions during output operations. You may call this method after the open(). If exceptions are disabled, the special internal error flag is set in case of output error. This flag is added in the error list during a close operation.
preserveFile() preserves a file, opened with the AutoDelete open flag.
do_putRange() operation is not implemented and throw an exception.
flush() flushes data from the buffer to the file.