libcruft-util/cruft/util/stream.hpp

78 lines
2.1 KiB
C++
Raw Permalink Normal View History

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
*
* Copyright 2011-2016 Danny Robson <danny@nerdcruft.net>
2011-05-23 17:18:52 +10:00
*/
#pragma once
2011-05-23 17:18:52 +10:00
2018-03-22 16:10:06 +11:00
#include <iosfwd>
#include <cstdint>
#include <ostream>
2011-05-23 17:18:52 +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
};
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
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);
2017-01-05 20:21:20 +11:00
std::ostream & flush (void);
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);
}