Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::StdioStreamFactory Class Reference

A concrete implementation of StreamFactory that creates instances of StdioInputStream and StdioOutputStream. More...

#include <bond/io/stdiostreamfactory.h>

Inheritance diagram for Bond::StdioStreamFactory:
Bond::StreamFactory

Public Member Functions

 StdioStreamFactory (Allocator &allocator, const char *rootPath=nullptr, StreamFactory *delegateFactory=nullptr, bool throwOnFailure=true)
 Constructs a StdioStreamFactory object.
virtual ~StdioStreamFactory ()
 Destroys a StdioStreamFactory object.
virtual InputStreamHandle CreateInputStream (const char *fileName) override
 Opens the given file for reading in binary mode and returns a StdioInputStream that owns it, or the stream created by the delegate factory if the file fails to open.
virtual OutputStreamHandle CreateOutputStream (const char *fileName, bool append=false) override
 Opens the given file for writing in binary mode and returns a StdioOutputStream that owns it, or the stream created by the delegate factory if the file fails to open.
void SetRootPath (const char *rootPath)
 Sets the root path prepended to file names when opening files.
void SetDelegateFactory (StreamFactory *delegateFactory)
 Sets the fallback StreamFactory used when this factory cannot provide a stream.
Public Member Functions inherited from Bond::StreamFactory
virtual ~StreamFactory ()
 Destroys a StreamFactory object.

Detailed Description

A concrete implementation of StreamFactory that creates instances of StdioInputStream and StdioOutputStream.

Constructor & Destructor Documentation

◆ StdioStreamFactory()

Bond::StdioStreamFactory::StdioStreamFactory ( Allocator & allocator,
const char * rootPath = nullptr,
StreamFactory * delegateFactory = nullptr,
bool throwOnFailure = true )
inlineexplicit

Constructs a StdioStreamFactory object.

Parameters
allocatorThe memory allocator from which StdioInputStreams and StdioOutputStreams are allocated.
rootPathOptional root path that is prepended to each file name, followed by BOND_PATH_SEPARATOR_CHAR, when opening files. The string is not copied and must remain valid for the lifetime of the factory.
delegateFactoryIf this factory cannot provide a stream, this factory is used as a fallback. May be null.
throwOnFailureIf true, stream creation failures are reported by throwing an Exception. Otherwise, stream creation failures return a null handle.

◆ ~StdioStreamFactory()

virtual Bond::StdioStreamFactory::~StdioStreamFactory ( )
inlinevirtual

Destroys a StdioStreamFactory object.

Member Function Documentation

◆ CreateInputStream()

virtual InputStreamHandle Bond::StdioStreamFactory::CreateInputStream ( const char * fileName)
overridevirtual

Opens the given file for reading in binary mode and returns a StdioInputStream that owns it, or the stream created by the delegate factory if the file fails to open.

The opened path is BOND_FILESYSTEM_PREFIX followed by the root path, if any, and the file name. The file fails to open if the path is longer than BOND_MAX_PATH_LENGTH bytes, including the terminating null.

Parameters
fileNameThe name of the file for which an input stream is created.

Implements Bond::StreamFactory.

◆ CreateOutputStream()

virtual OutputStreamHandle Bond::StdioStreamFactory::CreateOutputStream ( const char * fileName,
bool append = false )
overridevirtual

Opens the given file for writing in binary mode and returns a StdioOutputStream that owns it, or the stream created by the delegate factory if the file fails to open.

The opened path is formed as described for CreateInputStream().

Parameters
fileNameThe name of the file for which an output stream is created.
appendWhether bytes are written to the end of an existing file. Otherwise, an existing file is truncated.

Implements Bond::StreamFactory.

◆ SetDelegateFactory()

void Bond::StdioStreamFactory::SetDelegateFactory ( StreamFactory * delegateFactory)
inline

Sets the fallback StreamFactory used when this factory cannot provide a stream.

Parameters
delegateFactoryThe fallback StreamFactory, or null.

◆ SetRootPath()

void Bond::StdioStreamFactory::SetRootPath ( const char * rootPath)
inline

Sets the root path prepended to file names when opening files.

Parameters
rootPathThe new root path, or null to use file names as given. The string is not copied and must remain valid for the lifetime of the factory.

The documentation for this class was generated from the following file:
  • include/bond/io/stdiostreamfactory.h