| IOLink 1.11.0

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
iolink::StreamAccessFactory Class Reference

A factory to create StreamAccess instances from various ressources. More...

`#include <iolink/storage/StreamAccessFactory.h>`

## Public Member Functions
| StreamAccessFactory (const StreamAccessFactory &other)=delete
| StreamAccessFactory (StreamAccessFactory &&other)=delete
StreamAccessFactory & | operator= (const StreamAccessFactory &other)=delete
StreamAccessFactory & | operator= (StreamAccessFactory &&other)=delete

## Static Public Member Functions
static std::shared_ptr< StreamAccess > | allocate (size_t size=0)
| Create a stream in local memory.
static std::shared_ptr< StreamAccess > | copyInMemory (std::shared_ptr< StreamAccess > streamAccess)
| Load a stream into local memory.
static std::shared_ptr< StreamAccess > | fromStdStream (std::shared_ptr< std::istream > stream)
| Create a stream storage from a standard input stream.
static std::shared_ptr< StreamAccess > | fromStdStream (std::shared_ptr< std::ostream > stream)
| Create a stream storage from a standard output stream.
static std::shared_ptr< StreamAccess > | fromStdStream (std::shared_ptr< std::iostream > stream)
| Create a stream storage from a standard I/O stream.
static std::shared_ptr< std::istream > | toStdIStream (std::shared_ptr< StreamAccess > streamAccess)
| Create a standard Input stream from a StreamAccess.
static std::shared_ptr< std::ostream > | toStdOStream (std::shared_ptr< StreamAccess > streamAccess)
| Create a standard Output stream from a StreamAccess.
static std::shared_ptr< std::iostream > | toStdStream (std::shared_ptr< StreamAccess > streamAccess)
| Create a standard Input/Output stream from a StreamAccess.
static std::shared_ptr< StreamAccess > | openFileRead (const std::string &filePath)
| Create a stream that can read data from a file.
static std::shared_ptr< StreamAccess > | openFileWrite (const std::string &filePath)
| Create a stream that can write data to a file.
static std::shared_ptr< StreamAccess > | openFile (const std::string &filePath)
| Create a stream that can read and write data from/to a file.
static std::shared_ptr< StreamAccess > | openURIWrite (const Uri &uri)
| Create a stream that can write data to an URI.
static std::shared_ptr< StreamAccess > | openHTTPWrite (const Uri &uri, const std::string &method, const HTTPHeaders &headers)
| Create a stream that can post data to an HTTP URI.
static std::shared_ptr< StreamAccess > | fromRandomAccess (std::shared_ptr< RandomAccess > randomAccess)
| Create a StreamAccess that will delegate to a RandomAccess.

## Detailed Description

A factory to create StreamAccess instances from various ressources.

## Member Function Documentation

## ◆ allocate()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::allocate | ( | size_t | size = `0` | ) |
| static

Create a stream in local memory.

Parameters

  size | memory size (in byte) to allocate for the stream.

Returns
  a MemoryStreamAccess with all capabilities (`read`, `write` and `seek`)

## ◆ copyInMemory()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::copyInMemory | ( | std::shared_ptr< StreamAccess > | streamAccess | ) |
| static

Load a stream into local memory.

Parameters

  streamAccess | stream with at least `read` capability to load in memory

Returns
  a MemoryStreamAccess with all capabilities (`read`, `write` and `seek`)

Exceptions

  InvalidArgument | if input streamAccess is null
  Error | if the input streamAccess has no read or seek capability

## ◆ fromRandomAccess()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::fromRandomAccess | ( | std::shared_ptr< RandomAccess > | randomAccess | ) |
| static

Create a StreamAccess that will delegate to a RandomAccess.

Parameters

  randomAccess | RandomAccess from which a StreamAccess is created

Returns
  a StreamAccess object which can provide `read`, `write` and `seek` capability (see StreamAccessCapability)

Exceptions

  InvalidArgument | if input randomAccess is null
  Error | if the input randomAccess has nor read and write capability

## ◆ fromStdStream() [1/3]

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::fromStdStream | ( | std::shared_ptr< std::iostream > | stream | ) |
| static

Create a stream storage from a standard I/O stream.

Parameters

  stream | Standard I/O stream from which a StreamAccess is bridge is created

Returns
  a StreamAccess with `read`, `write` and `seek` capabilities (see StreamAccessCapability)

## ◆ fromStdStream() [2/3]

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::fromStdStream | ( | std::shared_ptr< std::istream > | stream | ) |
| static

Create a stream storage from a standard input stream.

Parameters

  stream | Standard Input Stream on which a bridge is created

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ fromStdStream() [3/3]

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::fromStdStream | ( | std::shared_ptr< std::ostream > | stream | ) |
| static

Create a stream storage from a standard output stream.

Parameters

  stream | Standard Output Stream on which a bridge is created

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ openFile()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::openFile | ( | const std::string & | filePath | ) |
| static

Create a stream that can read and write data from/to a file.

Parameters

  filePath | path toward the file which it's tried to access for reading and writing

Returns
  a StreamAccess object which can provide `read`, `write` and eventually `seek` capability (see StreamAccessCapability)

## ◆ openFileRead()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::openFileRead | ( | const std::string & | filePath | ) |
| static

Create a stream that can read data from a file.

Parameters

  filePath | path toward the file which it's tried to access for reading

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ openFileWrite()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::openFileWrite | ( | const std::string & | filePath | ) |
| static

Create a stream that can write data to a file.

Parameters

  filePath | path toward the file which it's tried to access for writing

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ openHTTPWrite()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::openHTTPWrite | ( | const Uri & | uri,
|  | const std::string & | method,
|  | const HTTPHeaders & | headers
| ) |  |
| static

Create a stream that can post data to an HTTP URI.

HTTP server must support chunked transfer encoding.

Parameters

  uri | The HTTP(S) URI to post to.
  method | The HTTP request method.
  headers | The HTTP request headers.

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ openURIWrite()

static std::shared_ptr< StreamAccess > iolink::StreamAccessFactory::openURIWrite | ( | const Uri & | uri | ) |
| static

Create a stream that can write data to an URI.

If the URI scheme is 'file': calls openFileWrite. If the URI scheme is 'http(s)': calls openHTTPWrite, using the POST method and no headers.

Parameters

  uri | URI to open for writing

Returns
  a StreamAccess object which can eventually provide `seek` capability (see StreamAccessCapability)

## ◆ toStdIStream()

static std::shared_ptr< std::istream > iolink::StreamAccessFactory::toStdIStream | ( | std::shared_ptr< StreamAccess > | streamAccess | ) |
| static

Create a standard Input stream from a StreamAccess.

Parameters

  streamAccess | stream with `read` capability from which a bridge is created

Returns
  a standard Input Stream

Exceptions

  InvalidArgument | if input streamAccess is null

## ◆ toStdOStream()

static std::shared_ptr< std::ostream > iolink::StreamAccessFactory::toStdOStream | ( | std::shared_ptr< StreamAccess > | streamAccess | ) |
| static

Create a standard Output stream from a StreamAccess.

Parameters

  streamAccess | StreamAccess with `write` capability from which a bridge is created

Exceptions

  InvalidArgument | if input streamAccess is null

Returns
  a standard Output Stream

## ◆ toStdStream()

static std::shared_ptr< std::iostream > iolink::StreamAccessFactory::toStdStream | ( | std::shared_ptr< StreamAccess > | streamAccess | ) |
| static

Create a standard Input/Output stream from a StreamAccess.

Parameters

  streamAccess | stream with `read` and `write` and `seek` capability from which a bridge is created

Exceptions

  InvalidArgument | if input streamAccess is null
  InvalidArgument | if `read`, `write`, or `seek` capabilities is missing

Returns
  a standard I/O Stream

The documentation for this class was generated from the following file:

- iolink/public/include/iolink/storage/StreamAccessFactory.h