-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,531 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; coding:utf-8 -*- | ||
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi | ||
// | ||
// Copyright 2024 Justine Alexandra Roberts Tunney | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for | ||
// any purpose with or without fee is hereby granted, provided that the | ||
// above copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | ||
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
// PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#include "ios.h" | ||
|
||
namespace ctl { | ||
|
||
ios::ios(FILE* file) : file_(file) | ||
{ | ||
} | ||
|
||
ios::~ios() = default; | ||
|
||
ios& | ||
ios::operator=(ios&& other) noexcept | ||
{ | ||
if (this != &other) { | ||
file_ = other.file_; | ||
other.file_ = nullptr; | ||
} | ||
return *this; | ||
} | ||
|
||
} // namespace ctl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*- | ||
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi | ||
#ifndef CTL_IOS_H_ | ||
#define CTL_IOS_H_ | ||
#include "ios_base.h" | ||
|
||
struct FILE; | ||
|
||
namespace ctl { | ||
|
||
class ios : public ios_base | ||
{ | ||
public: | ||
explicit ios(FILE*); | ||
virtual ~ios(); | ||
|
||
protected: | ||
ios& operator=(ios&&) noexcept; | ||
FILE* file_; | ||
|
||
private: | ||
ios(const ios&) = delete; | ||
}; | ||
|
||
} // namespace ctl | ||
|
||
#endif // CTL_IOS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; coding:utf-8 -*- | ||
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi | ||
// | ||
// Copyright 2024 Justine Alexandra Roberts Tunney | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for | ||
// any purpose with or without fee is hereby granted, provided that the | ||
// above copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | ||
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
// PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#include "ios_base.h" | ||
|
||
namespace ctl { | ||
|
||
ios_base::ios_base() : state_(goodbit), flags_(skipws | dec) | ||
{ | ||
} | ||
|
||
ios_base::~ios_base() = default; | ||
|
||
ios_base::fmtflags | ||
ios_base::flags() const | ||
{ | ||
return static_cast<ios_base::fmtflags>(flags_); | ||
} | ||
|
||
ios_base::fmtflags | ||
ios_base::flags(fmtflags fmtfl) | ||
{ | ||
int old = flags_; | ||
flags_ = fmtfl; | ||
return static_cast<ios_base::fmtflags>(old); | ||
} | ||
|
||
ios_base::fmtflags | ||
ios_base::setf(fmtflags fmtfl) | ||
{ | ||
int old = flags_; | ||
flags_ |= fmtfl; | ||
return static_cast<ios_base::fmtflags>(old); | ||
} | ||
|
||
ios_base::fmtflags | ||
ios_base::setf(fmtflags fmtfl, fmtflags mask) | ||
{ | ||
int old = flags_; | ||
flags_ = (flags_ & ~mask) | (fmtfl & mask); | ||
return static_cast<ios_base::fmtflags>(old); | ||
} | ||
|
||
void | ||
ios_base::unsetf(fmtflags mask) | ||
{ | ||
flags_ &= ~mask; | ||
} | ||
|
||
ios_base::iostate | ||
ios_base::rdstate() const | ||
{ | ||
return static_cast<ios_base::iostate>(state_); | ||
} | ||
|
||
void | ||
ios_base::clear(int state) | ||
{ | ||
state_ = state; | ||
} | ||
|
||
void | ||
ios_base::setstate(int state) | ||
{ | ||
state_ |= state; | ||
} | ||
|
||
bool | ||
ios_base::good() const | ||
{ | ||
return state_ == goodbit; | ||
} | ||
|
||
bool | ||
ios_base::eof() const | ||
{ | ||
return (state_ & eofbit) != 0; | ||
} | ||
|
||
bool | ||
ios_base::fail() const | ||
{ | ||
return (state_ & (failbit | badbit)) != 0; | ||
} | ||
|
||
bool | ||
ios_base::bad() const | ||
{ | ||
return (state_ & badbit) != 0; | ||
} | ||
|
||
bool | ||
ios_base::operator!() const | ||
{ | ||
return fail(); | ||
} | ||
|
||
ios_base::operator bool() const | ||
{ | ||
return !fail(); | ||
} | ||
|
||
} // namespace ctl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*- | ||
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi | ||
#ifndef CTL_IOS_BASE_H_ | ||
#define CTL_IOS_BASE_H_ | ||
|
||
namespace ctl { | ||
|
||
class ios_base | ||
{ | ||
public: | ||
typedef size_t streamsize; | ||
|
||
enum iostate | ||
{ | ||
goodbit = 0, | ||
badbit = 1, | ||
failbit = 2, | ||
eofbit = 4 | ||
}; | ||
|
||
enum fmtflags | ||
{ | ||
boolalpha = 1 << 0, | ||
dec = 1 << 1, | ||
fixed = 1 << 2, | ||
hex = 1 << 3, | ||
internal = 1 << 4, | ||
left = 1 << 5, | ||
oct = 1 << 6, | ||
right = 1 << 7, | ||
scientific = 1 << 8, | ||
showbase = 1 << 9, | ||
showpoint = 1 << 10, | ||
showpos = 1 << 11, | ||
skipws = 1 << 12, | ||
unitbuf = 1 << 13, | ||
uppercase = 1 << 14, | ||
adjustfield = left | right | internal, | ||
basefield = dec | oct | hex, | ||
floatfield = scientific | fixed | ||
}; | ||
|
||
enum openmode | ||
{ | ||
app = 1 << 0, | ||
binary = 1 << 1, | ||
in = 1 << 2, | ||
out = 1 << 3, | ||
trunc = 1 << 4, | ||
ate = 1 << 5 | ||
}; | ||
|
||
protected: | ||
ios_base(); | ||
virtual ~ios_base(); | ||
|
||
int state_; | ||
int flags_; | ||
|
||
public: | ||
fmtflags flags() const; | ||
fmtflags flags(fmtflags); | ||
fmtflags setf(fmtflags); | ||
fmtflags setf(fmtflags, fmtflags); | ||
void unsetf(fmtflags); | ||
|
||
iostate rdstate() const; | ||
void clear(int = goodbit); | ||
void setstate(int); | ||
|
||
bool good() const; | ||
bool eof() const; | ||
bool fail() const; | ||
bool bad() const; | ||
|
||
bool operator!() const; | ||
explicit operator bool() const; | ||
|
||
private: | ||
ios_base(const ios_base&) = delete; | ||
ios_base& operator=(const ios_base&) = delete; | ||
}; | ||
|
||
} // namespace ctl | ||
|
||
#endif // CTL_IOS_BASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.