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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b57a3ee was b57a3ee, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: refactored the library layout, everything from the impl directory was moved to the bits directory for the sake of consistency, updated copyright notices and include guards

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2018 Jaroslav Jindrak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef LIBCPP_BITS_IO_IOMANIP_OBJS
30#define LIBCPP_BITS_IO_IOMANIP_OBJS
31
32#include <ios>
33#include <utility>
34
35namespace std::aux
36{
37 /**
38 * Note: This allows us to lower the amount
39 * of code duplication in this module
40 * as we can avoid operator<</>> overloading
41 * for the manipulators.
42 */
43 template<class Manipulator>
44 struct manip_wrapper
45 {
46 template<class... Args>
47 manip_wrapper(Args&&... args)
48 : manipulator{forward<Args>(args)...}
49 { /* DUMMY BODY */ }
50
51 void operator()(ios_base& str)
52 {
53 manipulator(str);
54 }
55
56 Manipulator manipulator;
57 };
58
59 template<class Char, class Traits, class Manipulator>
60 basic_ostream<Char, Traits>& operator<<(
61 basic_ostream<Char, Traits>& os, manip_wrapper<Manipulator> manip
62 )
63 {
64 manip(os);
65
66 return os;
67 }
68
69 template<class Char, class Traits, class Manipulator>
70 basic_istream<Char, Traits>& operator>>(
71 basic_istream<Char, Traits>& is, manip_wrapper<Manipulator> manip
72 )
73 {
74 manip(is);
75
76 return is;
77 }
78
79 struct resetiosflags_t
80 {
81 resetiosflags_t(ios_base::fmtflags m);
82
83 void operator()(ios_base& str) const;
84
85 ios_base::fmtflags mask;
86 };
87
88 struct setiosflags_t
89 {
90 setiosflags_t(ios_base::fmtflags m);
91
92 void operator()(ios_base& str) const;
93
94 ios_base::fmtflags mask;
95 };
96
97 struct setbase_t
98 {
99 setbase_t(int b);
100
101 void operator()(ios_base& str) const;
102
103 int base;
104 };
105
106 /**
107 * Note: setfill is only for basic_ostream so
108 * this is the only case where we overload
109 * the appropriate operator again.
110 */
111 template<class Char>
112 struct setfill_t
113 {
114 setfill_t(Char c)
115 : fill{c}
116 { /* DUMMY BODY */ }
117
118 template<class Traits>
119 void operator()(basic_ios<Char, Traits>& str) const
120 {
121 str.fill(fill);
122 }
123
124 Char fill;
125 };
126
127 template<class Char, class Traits>
128 basic_ostream<Char, Traits>& operator<<(
129 basic_ostream<Char, Traits>& is,
130 setfill_t<Char> manip
131 )
132 {
133 manip(is);
134
135 return is;
136 }
137
138 struct setprecision_t
139 {
140 setprecision_t(int);
141
142 void operator()(ios_base&) const;
143
144 int prec;
145 };
146
147 struct setw_t
148 {
149 setw_t(int);
150
151 void operator()(ios_base&) const;
152
153 int width;
154 };
155}
156
157#endif
Note: See TracBrowser for help on using the repository browser.