wavelength 1.0.0
Loading...
Searching...
No Matches
prnstream.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <map>
5#include <vector>
6
16class PrnStream {
17public:
23 PrnStream() : mDumpLevel(0) {
24 }
25
32 virtual ~PrnStream() {
33 }
34
42 virtual void Print(const char *pszText) = 0;
43
51 void Printf(const char *pszFormat, ...);
52
61 PrnStream &operator<<(const char *pszText);
62
72
81 PrnStream &operator<<(short nValue);
82
91 PrnStream &operator<<(int nValue);
92
101 PrnStream &operator<<(unsigned char nValue);
102
111 PrnStream &operator<<(unsigned short nValue);
112
121 PrnStream &operator<<(unsigned int nValue);
122
131 PrnStream &operator<<(unsigned long long nValue);
132
141 PrnStream &operator<<(float fValue);
142
151 PrnStream &operator<<(bool bValue);
152
162 void Space(int nCount);
163
166 int GetDumpLevel() const {
167 return mDumpLevel;
168 }
169
170private:
176 int mDumpLevel;
177};
178
180constexpr int kPrnModeFull = 10;
181
222template <typename T>
223PrnStream &operator<<(PrnStream &stream, const std::list<T> &list) {
224 stream << "(size:" << static_cast<unsigned int>(list.size()) << ")";
225 int nIndex = 0;
226 for (const auto &element : list) {
227 stream << "\n" << nIndex << "\t" << element;
228 ++nIndex;
229 }
230 return stream;
231}
232
284template <typename T>
285PrnStream &operator<<(PrnStream &stream, const std::vector<T> &elements) {
286 stream << "(size:" << static_cast<unsigned int>(elements.size()) << ")";
287 int nIndex = 0;
288 for (const T &element : elements) {
289 stream << "\n" << nIndex << "\t" << element;
290 ++nIndex;
291 }
292 return stream;
293}
294
311template <typename Key, typename Value, typename Compare>
312PrnStream &operator<<(PrnStream &stream, const std::map<Key, Value, Compare> &map) {
313 stream << "(size:" << static_cast<unsigned int>(map.size()) << ")";
314 for (const auto &entry : map) {
315 stream << "\n\t" << "key:" << entry.first << " value:" << entry.second;
316 }
317 return stream;
318}
319
329template <typename Key, typename Value>
330PrnStream &operator<<(PrnStream &stream, const std::map<Key, Value> &map);
Text output stream.
Definition prnstream.h:16
PrnStream & operator<<(bool bValue)
Write true or false.
void Printf(const char *pszFormat,...)
Format text into the shared format buffer and write the result through Print().
PrnStream & operator<<(float fValue)
Write a number with two decimals.
PrnStream & operator<<(unsigned char nValue)
Write a byte as an unsigned integer in decimal.
int GetDumpLevel() const
Definition prnstream.h:166
void Space(int nCount)
Write a number of spaces, one Print() call each.
virtual ~PrnStream()
Release the stream.
Definition prnstream.h:32
virtual void Print(const char *pszText)=0
Write text to the stream's destination.
PrnStream & operator<<(unsigned int nValue)
Write an unsigned integer in decimal.
PrnStream & operator<<(unsigned long long nValue)
Write an unsigned 64-bit number in decimal.
PrnStream & operator<<(short nValue)
Write a short integer in decimal.
PrnStream & operator<<(char ch)
Write a character.
PrnStream & operator<<(unsigned short nValue)
Write an unsigned short integer in decimal.
PrnStream & operator<<(int nValue)
Write an integer in decimal.
PrnStream()
Construct a stream with a dump level of 0.
Definition prnstream.h:23
PrnStream & operator<<(const char *pszText)
Write text.
PrnStream & operator<<(PrnStream &stream, const std::list< T > &list)
Write a list as its size followed by one tab-indented line per element.
Definition prnstream.h:223
constexpr int kPrnModeFull
The PrnStream::mDumpLevel value that includes the fourth word of a written Vector3.
Definition prnstream.h:180