|
1 | 1 | #include "c_plus_plus_serializer.h" |
2 | 2 | #include <limits> |
3 | 3 |
|
4 | | -static void save_simple (const std::string filename) |
5 | | -{ |
6 | | - std::cout << "save to " << filename << std::endl; |
7 | | - std::ofstream out(filename, std::ios::binary ); |
| 4 | +static void save_simple(const std::string filename) { |
| 5 | + std::cout << "save to " << filename << std::endl; |
| 6 | + std::ofstream out(filename, std::ios::binary); |
8 | 7 |
|
9 | | - char a = 42; |
10 | | - unsigned short b = 65535; |
11 | | - int c = 123456; |
12 | | - float d = std::numeric_limits<float>::max(); |
13 | | - double e = std::numeric_limits<double>::max(); |
14 | | - std::string f("hello"); |
15 | | - wchar_t g = L'💩'; |
16 | | - std::wstring h(L"wide string 💩"); |
17 | | - std::pair<int, std::string> p(42, "life"); |
| 8 | + char a = 42; |
| 9 | + unsigned short b = 65535; |
| 10 | + int c = 123456; |
| 11 | + float d = std::numeric_limits< float >::max(); |
| 12 | + double e = std::numeric_limits< double >::max(); |
| 13 | + std::string f("hello"); |
| 14 | + wchar_t g = L'💩'; |
| 15 | + std::wstring h(L"wide string 💩"); |
| 16 | + std::pair< int, std::string > p(42, "life"); |
18 | 17 |
|
19 | | - std::cout << std::endl; |
20 | | - std::cout << "write:" << std::endl; |
21 | | - std::cout << " a: char " << a << std::endl; |
22 | | - std::cout << " b: unsigned short " << b << std::endl; |
23 | | - std::cout << " c: int " << c << std::endl; |
24 | | - std::cout << " d: float " << d << std::endl; |
25 | | - std::cout << " e: double " << e << std::endl; |
26 | | - std::cout << " f: std::string " << f << std::endl; |
27 | | - std::wcout << " g: wchar_t " << g << std::endl; |
28 | | - std::wcout << " h: std::wstring " << h << std::endl; |
29 | | - std::cout << " p: std::pair " << p.first << " " << p.second << std::endl; |
| 18 | + std::cout << std::endl; |
| 19 | + std::cout << "write:" << std::endl; |
| 20 | + std::cout << " a: char " << a << std::endl; |
| 21 | + std::cout << " b: unsigned short " << b << std::endl; |
| 22 | + std::cout << " c: int " << c << std::endl; |
| 23 | + std::cout << " d: float " << d << std::endl; |
| 24 | + std::cout << " e: double " << e << std::endl; |
| 25 | + std::cout << " f: std::string " << f << std::endl; |
| 26 | + std::wcout << " g: wchar_t " << g << std::endl; |
| 27 | + std::wcout << " h: std::wstring " << h << std::endl; |
| 28 | + std::cout << " p: std::pair " << p.first << " " << p.second << std::endl; |
30 | 29 |
|
31 | | - std::cout << std::endl; |
| 30 | + std::cout << std::endl; |
32 | 31 |
|
33 | | - out << bits(a) << bits(b) << bits(c) << bits(d); |
34 | | - out << bits(e) << bits(f) << bits(g) << bits(h); |
35 | | - out << bits(p); |
| 32 | + out << bits(a) << bits(b) << bits(c) << bits(d); |
| 33 | + out << bits(e) << bits(f) << bits(g) << bits(h); |
| 34 | + out << bits(p); |
36 | 35 | } |
37 | 36 |
|
38 | | -static void load_simple (const std::string filename) |
39 | | -{ |
40 | | - std::cout << "read from " << filename << std::endl; |
41 | | - std::ifstream in(filename); |
| 37 | +static void load_simple(const std::string filename) { |
| 38 | + std::cout << "read from " << filename << std::endl; |
| 39 | + std::ifstream in(filename); |
42 | 40 |
|
43 | | - char a; |
44 | | - unsigned short b; |
45 | | - int c; |
46 | | - float d; |
47 | | - double e; |
48 | | - std::string f; |
49 | | - wchar_t g; |
50 | | - std::wstring h; |
51 | | - std::pair<int, std::string> p; |
| 41 | + char a; |
| 42 | + unsigned short b; |
| 43 | + int c; |
| 44 | + float d; |
| 45 | + double e; |
| 46 | + std::string f; |
| 47 | + wchar_t g; |
| 48 | + std::wstring h; |
| 49 | + std::pair< int, std::string > p; |
52 | 50 |
|
53 | | - in >> bits(a) >> bits(b) >> bits(c) >> bits(d); |
54 | | - in >> bits(e) >> bits(f) >> bits(g) >> bits(h); |
55 | | - in >> bits(p); |
| 51 | + in >> bits(a) >> bits(b) >> bits(c) >> bits(d); |
| 52 | + in >> bits(e) >> bits(f) >> bits(g) >> bits(h); |
| 53 | + in >> bits(p); |
56 | 54 |
|
57 | | - std::cout << std::endl; |
58 | | - std::cout << "read:" << std::endl; |
59 | | - std::cout << " a: char " << a << std::endl; |
60 | | - std::cout << " b: unsigned short " << b << std::endl; |
61 | | - std::cout << " c: int " << c << std::endl; |
62 | | - std::cout << " d: float " << d << std::endl; |
63 | | - std::cout << " e: double " << e << std::endl; |
64 | | - std::cout << " f: std::string " << f << std::endl; |
65 | | - std::wcout << " g: wchar_t " << g << std::endl; |
66 | | - std::wcout << " h: std::wstring " << h << std::endl; |
67 | | - std::cout << " p: std::pair " << p.first << " " << p.second << std::endl; |
68 | | - std::cout << std::endl; |
| 55 | + std::cout << std::endl; |
| 56 | + std::cout << "read:" << std::endl; |
| 57 | + std::cout << " a: char " << a << std::endl; |
| 58 | + std::cout << " b: unsigned short " << b << std::endl; |
| 59 | + std::cout << " c: int " << c << std::endl; |
| 60 | + std::cout << " d: float " << d << std::endl; |
| 61 | + std::cout << " e: double " << e << std::endl; |
| 62 | + std::cout << " f: std::string " << f << std::endl; |
| 63 | + std::wcout << " g: wchar_t " << g << std::endl; |
| 64 | + std::wcout << " h: std::wstring " << h << std::endl; |
| 65 | + std::cout << " p: std::pair " << p.first << " " << p.second << std::endl; |
| 66 | + std::cout << std::endl; |
69 | 67 | } |
70 | 68 |
|
71 | | -void basic_example (void) |
72 | | -{ |
73 | | - // |
74 | | - // Need this to get the poop emoji printed! :) |
75 | | - // |
76 | | - std::locale loc(""); |
77 | | - std::ios_base::sync_with_stdio(false); |
78 | | - std::wcout.imbue(loc); |
| 69 | +void basic_example(void) { |
| 70 | + // |
| 71 | + // Need this to get the poop emoji printed! :) |
| 72 | + // |
| 73 | + std::locale loc(""); |
| 74 | + std::ios_base::sync_with_stdio(false); |
| 75 | + std::wcout.imbue(loc); |
79 | 76 |
|
80 | | - std::cout << "basic_example" << std::endl; |
81 | | - std::cout << "=============" << std::endl; |
82 | | - save_simple(std::string("basic_example.bin")); |
83 | | - load_simple(std::string("basic_example.bin")); |
| 77 | + std::cout << "basic_example" << std::endl; |
| 78 | + std::cout << "=============" << std::endl; |
| 79 | + save_simple(std::string("basic_example.bin")); |
| 80 | + load_simple(std::string("basic_example.bin")); |
84 | 81 | } |
0 commit comments