2011-05-23 17:18:52 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2016-03-11 12:48:19 +11:00
|
|
|
* Copyright 2011-2016 Danny Robson <danny@nerdcruft.net>
|
2011-05-23 17:18:52 +10:00
|
|
|
*/
|
|
|
|
|
2021-04-14 15:35:49 +10:00
|
|
|
#pragma once
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2018-03-22 16:10:06 +11:00
|
|
|
#include <iosfwd>
|
|
|
|
#include <cstdint>
|
2020-07-01 17:02:44 +10:00
|
|
|
#include <ostream>
|
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft::stream {
|
2017-01-05 20:21:20 +11:00
|
|
|
namespace scoped {
|
2017-05-23 12:50:51 +10:00
|
|
|
#define SCOPED(NAME,TYPE) \
|
|
|
|
class NAME { \
|
|
|
|
public: \
|
|
|
|
explicit NAME (std::ios_base&); \
|
|
|
|
~NAME (); \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
std::ios_base &m_ios; \
|
|
|
|
TYPE m_state; \
|
2017-01-05 20:21:20 +11:00
|
|
|
}
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
SCOPED(flags, std::ios_base::fmtflags);
|
|
|
|
SCOPED(precision, std::streamsize);
|
|
|
|
SCOPED(width, std::streamsize);
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
#undef SCOPED
|
|
|
|
};
|
2016-05-12 17:47:22 +10:00
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
class null_streambuf : public std::basic_streambuf<char> {
|
|
|
|
public:
|
|
|
|
virtual ~null_streambuf () { ; }
|
|
|
|
};
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2016-05-12 17:47:22 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
class null_ostream : public std::basic_ostream<char> {
|
|
|
|
public:
|
|
|
|
virtual ~null_ostream () { ; }
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
std::ostream & put (char c);
|
|
|
|
std::ostream & write (const char *s, std::streamsize n);
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
std::streampos tellp (void);
|
|
|
|
std::ostream & seekp (std::streampos pos);
|
|
|
|
std::ostream & seekp (std::streamoff off,
|
|
|
|
std::ios_base::seekdir dir);
|
2014-07-15 19:50:08 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
std::ostream & flush (void);
|
2015-04-09 20:41:24 +10:00
|
|
|
|
2017-01-05 20:21:20 +11:00
|
|
|
bool good (void) const;
|
|
|
|
bool bad (void) const;
|
|
|
|
bool eof (void) const;
|
|
|
|
bool fail (void) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
struct bits {
|
|
|
|
bits (uintmax_t value, unsigned count);
|
|
|
|
|
|
|
|
uintmax_t value;
|
|
|
|
unsigned count;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
std::ostream& operator<< (std::ostream&, bits);
|
2014-07-15 19:50:08 +10:00
|
|
|
}
|