ActiveLib
Loading...
Searching...
No Matches
IOBase.h
1
6#ifndef ACTIVE_FILE_IO_BASE
7#define ACTIVE_FILE_IO_BASE
8
9#include <ios>
10
11namespace active::file {
12
13 class IOBase {
14 public:
15
16 // MARK: - Types
17
19 using flag_type = std::ios_base::iostate;
20
21 // MARK: - Constructors
22
26 IOBase() noexcept { m_stateFlags = std::ios_base::goodbit; }
31 IOBase(const IOBase& source) noexcept { m_stateFlags = source.m_stateFlags; }
35 virtual ~IOBase() noexcept = default;
36
37 // MARK: - Operators
38
43 bool operator! () const noexcept { return fail(); }
48 operator void* () const noexcept { return fail() ? nullptr : (void*) 1; }
49
50 // MARK: - Functions (const)
51
56 virtual bool good() const noexcept { return (m_stateFlags == 0); }
61 virtual bool eof() const noexcept { return ((m_stateFlags & std::ios_base::eofbit) != 0); }
66 virtual bool fail() const noexcept { return ((m_stateFlags & (std::ios_base::failbit | std::ios_base::badbit)) != 0); }
71 virtual bool bad() const noexcept { return ((m_stateFlags & std::ios_base::badbit) != 0); }
76 virtual flag_type state() const noexcept { return m_stateFlags; }
77
78 // MARK: - Functions (mutating)
79
84 virtual void clear(flag_type f = std::ios_base::goodbit) { m_stateFlags = f; }
89 virtual void setState(flag_type f) { clear(state() | f); }
94 virtual void unsetState(flag_type f) { clear((state() | f) ^ f); }
95
96 protected:
101 void setCompleteState(flag_type state) { m_stateFlags = state; }
106 void clear(flag_type f = std::ios_base::goodbit) const { m_stateFlags = f; }
111 void setState(flag_type f) const { clear(state() | f); }
116 virtual void unsetState(flag_type f) const { clear((state() | f) ^ f); }
117
118 private:
120 mutable flag_type m_stateFlags;
121 };
122
123}
124
125#endif //ACTIVE_FILE_IO_BASE
Definition IOBase.h:13
virtual void unsetState(flag_type f)
Definition IOBase.h:94
virtual bool eof() const noexcept
Definition IOBase.h:61
virtual void unsetState(flag_type f) const
Definition IOBase.h:116
virtual bool fail() const noexcept
Definition IOBase.h:66
virtual void clear(flag_type f=std::ios_base::goodbit)
Definition IOBase.h:84
virtual void setState(flag_type f)
Definition IOBase.h:89
virtual flag_type state() const noexcept
Definition IOBase.h:76
void setState(flag_type f) const
Definition IOBase.h:111
virtual bool good() const noexcept
Definition IOBase.h:56
virtual bool bad() const noexcept
Definition IOBase.h:71
virtual ~IOBase() noexcept=default
void clear(flag_type f=std::ios_base::goodbit) const
Definition IOBase.h:106
std::ios_base::iostate flag_type
The state flag representation type.
Definition IOBase.h:19
IOBase() noexcept
Definition IOBase.h:26
void setCompleteState(flag_type state)
Definition IOBase.h:101
IOBase(const IOBase &source) noexcept
Definition IOBase.h:31
Definition Directory.h:12