StreamManager.hpp

The StreamManager object links names to files or other streams.

Todo:

Ideally should also work with File

Note

Status: BETA

class StreamManager
#include <StreamManager.hpp>

A class to maintain files and other streams.

Public Types

enum class Type

Values:

enumerator NONE
enumerator FILE
enumerator STRING
enumerator OTHER
enum class Access

Values:

enumerator NONE
enumerator INPUT
enumerator OUTPUT
enumerator IO

Public Functions

inline StreamManager()
StreamManager(const StreamManager&) = delete
inline ~StreamManager()
inline bool Has(const std::string &name) const
inline bool HasInputFileStream(const std::string &name) const
inline bool HasOutputFileStream(const std::string &name) const
inline bool HasIOFileStream(const std::string &name) const
inline bool HasStringStream(const std::string &name) const
inline bool HasStdInputStream(const std::string &name) const
inline bool HasStdOutputStream(const std::string &name) const
inline bool HasStdIOStream(const std::string &name) const
inline bool HasInputOnlyStream(const std::string &name) const
inline bool HasOutputOnlyStream(const std::string &name) const
inline bool HasIOStream(const std::string &name) const
inline bool HasInputStream(const std::string &name) const
inline bool HasOutputStream(const std::string &name) const
template<typename T, Type TYPE, Access ACCESS>
inline T &AddStream(const std::string &name)
inline std::ifstream &AddInputFile(std::string name)
inline std::ofstream &AddOutputFile(std::string name)
inline std::fstream &AddFile(std::string name)
inline std::stringstream &AddStringStream(std::string name)
template<typename T>
inline T &AddStream(const std::string &name, T &in_stream)

Add a stream maintained outside of manager (do not delete without removing first!)

inline std::istream &AddInputStream(const std::string &name)

Build a default input stream.

inline std::ostream &AddOutputStream(const std::string &name)

Build a default output stream.

inline std::iostream &AddIOStream(const std::string &name)

Build a default IO stream.

inline void SetInputDefaultFile()
inline void SetOutputDefaultFile()
inline void SetIODefaultFile()
inline void SetInputDefaultString()
inline void SetOutputDefaultString()
inline void SetIODefaultString()
inline void SetInputDefaultStandard()
inline void SetOutputDefaultStandard()
inline std::istream &GetInputStream(const std::string &name)
inline std::ostream &GetOutputStream(const std::string &name)
inline std::iostream &GetIOStream(const std::string &name)
inline std::ostream &get_ostream(const std::string &name = "cout", const std::string &stdout_name = "cout")

Protected Functions

inline StreamInfo &GetInfo(const std::string &name)
inline const StreamInfo &GetInfo(const std::string &name) const

Protected Attributes

std::unordered_map<std::string, Ptr<StreamInfo>> streams
Type default_input_type = Type::OTHER
Type default_output_type = Type::OTHER
Type default_io_type = Type::STRING
StreamInfo_None info_none

Protected Static Functions

static inline std::iostream &GetDefaultStream()
class StreamInfo
#include <StreamManager.hpp>

Subclassed by StreamManager::StreamInfo_None, StreamManager::TypedStreamInfo< T, TYPE, ACCESS >

Public Functions

inline StreamInfo(const std::string &in_name, bool in_owned)
StreamInfo(const StreamInfo&) = delete
inline virtual ~StreamInfo()
virtual Type GetType() const = 0
virtual Access GetAccess() const = 0
inline bool IsFile() const
inline bool IsString() const
inline bool IsOther() const
inline bool IsInput() const
inline bool IsOutput() const
inline bool IsIO() const
inline bool IsInputFile() const
inline bool IsOutputFile() const
inline bool IsIOFile() const
inline bool IsOtherInput() const
inline bool IsOtherOutput() const
inline bool IsOtherIO() const
inline bool InputOK() const
inline bool OutputOK() const
inline bool IsOwned() const
virtual std::istream &GetInputStream() = 0
virtual std::ostream &GetOutputStream() = 0
virtual std::iostream &GetIOStream() = 0

Protected Attributes

std::string name
bool owned
struct StreamInfo_None : public StreamManager::StreamInfo
#include <StreamManager.hpp>

Public Functions

inline StreamInfo_None()
inline virtual Type GetType() const override
inline virtual Access GetAccess() const override
inline virtual std::istream &GetInputStream() override
inline virtual std::ostream &GetOutputStream() override
inline virtual std::iostream &GetIOStream() override
template<typename T, Type TYPE, Access ACCESS>
class TypedStreamInfo : public StreamManager::StreamInfo
#include <StreamManager.hpp>

Public Functions

inline TypedStreamInfo(const std::string &name)
inline TypedStreamInfo(const std::string &name, Ptr<T> in_ptr)
inline ~TypedStreamInfo()
inline virtual Type GetType() const override
inline virtual Access GetAccess() const override
inline T &GetStream()
inline virtual std::istream &GetInputStream() override
inline virtual std::ostream &GetOutputStream() override
inline virtual std::iostream &GetIOStream() override
inline void ResetStream()

Public Static Attributes

static constexpr bool INPUT_OK = (ACCESS == Access::INPUT || ACCESS == Access::IO)
static constexpr bool OUTPUT_OK = (ACCESS == Access::OUTPUT || ACCESS == Access::IO)

Protected Attributes

Ptr<T> ptr = nullptr