summaryrefslogtreecommitdiff
path: root/lib/streamSupport.cpp
blob: f3c88cf93121dd9f85b54ce23f5936da8b3845dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "streamSupport.h"
#include "bitset.h"
#include "compileTimeFormatter.h"
#include "dbTypes.h"
#include <cstdint>
#include <string_view>
#include <type_traits>
struct timespec;
struct tm;

namespace std {
	std::ostream &
	operator<<(std::ostream & strm, const std::byte byt)
	{
		return MyGrate::scprintf<"%#02x">(strm, std::to_integer<uint8_t>(byt));
	}

	std::ostream &
	operator<<(std::ostream & s, const MARIADB_STRING & str)
	{
		return s << *str;
	}

	std::ostream &
	operator<<(std::ostream & s, const tm & tm)
	{
		return MyGrate::scprintf<"%04d-%02d-%02d %02d:%02d:%02d">(
				s, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
	}

	std::ostream &
	operator<<(std::ostream & s, const timespec & ts)
	{
		return MyGrate::scprintf<"%d.%09d">(s, ts.tv_sec, ts.tv_nsec);
	}

	std::ostream &
	operator<<(std::ostream & s, const MyGrate::Date & d)
	{
		return MyGrate::scprintf<"%04d-%02d-%02d">(s, d.year, d.month, d.day);
	}

	std::ostream &
	operator<<(std::ostream & s, const MyGrate::Time & t)
	{
		return MyGrate::scprintf<"%02d:%02d:%02d">(s, t.hour, t.minute, t.second);
	}

	std::ostream &
	operator<<(std::ostream & s, const MyGrate::DateTime & dt)
	{
		return MyGrate::scprintf<"%? %?">(s, (const MyGrate::Date)dt, (const MyGrate::Time)dt);
	}

	std::ostream &
	operator<<(std::ostream & s, const MyGrate::BitSet & bs)
	{
		return s << std::make_pair(bs.begin(), bs.end());
	}
}