VirtualBox

source: vbox/trunk/include/iprt/nocrt/iomanip

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/** @file
2 * IPRT / No-CRT - Minimal C++ iomanip header.
3 */
4
5/*
6 * Copyright (C) 2022-2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_SRC_nocrt_iomanip
37#define VBOX_INCLUDED_SRC_nocrt_iomanip
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/nocrt/ios>
43
44
45namespace std
46{
47 /**
48 * Used by all flag manipulators.
49 */
50 struct rtNoCrtIosSetFlagsEx
51 {
52 ios_base::fmtflags m_fSet;
53 ios_base::fmtflags m_fMask;
54 };
55
56 template<typename a_CharType, typename a_CharTraits>
57 inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc,
58 struct rtNoCrtIosSetFlagsEx a_Change)
59 {
60 a_rSrc.setf(a_Change.m_fSet, a_Change.m_fMask);
61 return a_rSrc;
62 }
63
64 template<typename a_CharType, typename a_CharTraits>
65 inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst,
66 struct rtNoCrtIosSetFlagsEx a_Change)
67 {
68 a_rDst.setf(a_Change.m_fSet, a_Change.m_fMask);
69 return a_rDst;
70 }
71
72
73 /*
74 * Flag modification functions.
75 */
76
77 inline struct rtNoCrtIosSetFlagsEx setiosflags(ios_base::fmtflags a_fFlags)
78 {
79 struct rtNoCrtIosSetFlagsEx Ret = { a_fFlags, a_fFlags };
80 return Ret;
81 }
82
83 inline struct rtNoCrtIosSetFlagsEx resetiosflags(ios_base::fmtflags a_fFlags)
84 {
85 struct rtNoCrtIosSetFlagsEx Ret = { ios_base::fmtflags(0), a_fFlags };
86 return Ret;
87 }
88
89 inline struct rtNoCrtIosSetFlagsEx setbase(int a_iBase)
90 {
91 struct rtNoCrtIosSetFlagsEx Ret =
92 {
93 a_iBase == 10 ? ios_base::dec
94 : a_iBase == 16 ? ios_base::hex
95 : a_iBase == 8 ? ios_base::oct
96 : ios_base::fmtflags(0),
97 ios_base::basefield
98 };
99 return Ret;
100 }
101
102 /*
103 * Modify precision.
104 */
105 struct rtNoCrtIosSetPrecision
106 {
107 int m_cchPrecision;
108 };
109
110 template<typename a_CharType, typename a_CharTraits>
111 inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc,
112 struct rtNoCrtIosSetPrecision a_Change)
113 {
114 a_rSrc.precision(a_Change.m_cchPrecision);
115 return a_rSrc;
116 }
117
118 template<typename a_CharType, typename a_CharTraits>
119 inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst,
120 struct rtNoCrtIosSetPrecision a_Change)
121 {
122 a_rDst.precision(a_Change.m_cchPrecision);
123 return a_rDst;
124 }
125
126 inline struct rtNoCrtIosSetPrecision setprecision(int a_cchPrecision)
127 {
128 struct rtNoCrtIosSetPrecision Ret = { a_cchPrecision };
129 return Ret;
130 }
131
132 /*
133 * Modify width.
134 */
135 struct rtNoCrtIosSetWidth
136 {
137 int m_cchWidth;
138 };
139
140 template<typename a_CharType, typename a_CharTraits>
141 inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc,
142 struct rtNoCrtIosSetWidth a_Change)
143 {
144 a_rSrc.width(a_Change.m_cchWidth);
145 return a_rSrc;
146 }
147
148 template<typename a_CharType, typename a_CharTraits>
149 inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst,
150 struct rtNoCrtIosSetWidth a_Change)
151 {
152 a_rDst.width(a_Change.m_cchWidth);
153 return a_rDst;
154 }
155
156 inline struct rtNoCrtIosSetWidth setw(int a_cchWidth)
157 {
158 struct rtNoCrtIosSetWidth Ret = { a_cchWidth };
159 return Ret;
160 }
161
162 /** @todo setfil, get_money, set_money, get_time, set_time */
163}
164
165#endif /* !VBOX_INCLUDED_SRC_nocrt_iomanip */
166
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette