source: mainline/uspace/lib/cpp/include/__bits/io/iomanip_objs.hpp@ 5d7a247

Last change on this file since 5d7a247 was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 4 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef LIBCPP_BITS_IO_IOMANIP_OBJS
8#define LIBCPP_BITS_IO_IOMANIP_OBJS
9
10#include <ios>
11#include <utility>
12
13namespace std::aux
14{
15 /**
16 * Note: This allows us to lower the amount
17 * of code duplication in this module
18 * as we can avoid operator<</>> overloading
19 * for the manipulators.
20 */
21 template<class Manipulator>
22 struct manip_wrapper
23 {
24 template<class... Args>
25 manip_wrapper(Args&&... args)
26 : manipulator{forward<Args>(args)...}
27 { /* DUMMY BODY */ }
28
29 void operator()(ios_base& str)
30 {
31 manipulator(str);
32 }
33
34 Manipulator manipulator;
35 };
36
37 template<class Char, class Traits, class Manipulator>
38 basic_ostream<Char, Traits>& operator<<(
39 basic_ostream<Char, Traits>& os, manip_wrapper<Manipulator> manip
40 )
41 {
42 manip(os);
43
44 return os;
45 }
46
47 template<class Char, class Traits, class Manipulator>
48 basic_istream<Char, Traits>& operator>>(
49 basic_istream<Char, Traits>& is, manip_wrapper<Manipulator> manip
50 )
51 {
52 manip(is);
53
54 return is;
55 }
56
57 struct resetiosflags_t
58 {
59 resetiosflags_t(ios_base::fmtflags m);
60
61 void operator()(ios_base& str) const;
62
63 ios_base::fmtflags mask;
64 };
65
66 struct setiosflags_t
67 {
68 setiosflags_t(ios_base::fmtflags m);
69
70 void operator()(ios_base& str) const;
71
72 ios_base::fmtflags mask;
73 };
74
75 struct setbase_t
76 {
77 setbase_t(int b);
78
79 void operator()(ios_base& str) const;
80
81 int base;
82 };
83
84 /**
85 * Note: setfill is only for basic_ostream so
86 * this is the only case where we overload
87 * the appropriate operator again.
88 */
89 template<class Char>
90 struct setfill_t
91 {
92 setfill_t(Char c)
93 : fill{c}
94 { /* DUMMY BODY */ }
95
96 template<class Traits>
97 void operator()(basic_ios<Char, Traits>& str) const
98 {
99 str.fill(fill);
100 }
101
102 Char fill;
103 };
104
105 template<class Char, class Traits>
106 basic_ostream<Char, Traits>& operator<<(
107 basic_ostream<Char, Traits>& is,
108 setfill_t<Char> manip
109 )
110 {
111 manip(is);
112
113 return is;
114 }
115
116 struct setprecision_t
117 {
118 setprecision_t(int);
119
120 void operator()(ios_base&) const;
121
122 int prec;
123 };
124
125 struct setw_t
126 {
127 setw_t(int);
128
129 void operator()(ios_base&) const;
130
131 int width;
132 };
133}
134
135#endif
Note: See TracBrowser for help on using the repository browser.