source: mainline/uspace/lib/cpp/include/internal/locale/num_put.hpp@ 9cb221b

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

cpp: reorganized <locale> to avoid circular dependencies with ios_base

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2017 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_INTERNAL_LOCALE_NUM_PUT
30#define LIBCPP_INTERNAL_LOCALE_NUM_PUT
31
32#include <internal/locale.hpp>
33#include <internal/locale/numpunct.hpp>
34#include <ios>
35#include <iterator>
36
37namespace std
38{
39 /**
40 * 22.4.2.2, class template num_put:
41 */
42
43 template<class Char, class OutputIterator = ostreambuf_iterator<Char>>
44 class num_put: public locale::facet
45 {
46 public:
47 using char_type = Char;
48 using iter_type = OutputIterator;
49
50 explicit num_put(size_t refs = 0);
51
52 iter_type put(iter_type it, ios_base& base, char_type fill, bool v) const
53 {
54 return do_put(it, base, fill, v);
55 }
56
57 iter_type put(iter_type it, ios_base& base, char_type fill, long v) const
58 {
59 return do_put(it, base, fill, v);
60 }
61
62 iter_type put(iter_type it, ios_base& base, char_type fill, long long v) const
63 {
64 return do_put(it, base, fill, v);
65 }
66
67 iter_type put(iter_type it, ios_base& base, char_type fill, unsigned long v) const
68 {
69 return do_put(it, base, fill, v);
70 }
71
72 iter_type put(iter_type it, ios_base& base, char_type fill, unsigned long long v) const
73 {
74 return do_put(it, base, fill, v);
75 }
76
77 iter_type put(iter_type it, ios_base& base, char_type fill, double v) const
78 {
79 return do_put(it, base, fill, v);
80 }
81
82 iter_type put(iter_type it, ios_base& base, char_type fill, long double v) const
83 {
84 return do_put(it, base, fill, v);
85 }
86
87 iter_type put(iter_type it, ios_base& base, char_type fill, const void* v) const
88 {
89 return do_put(it, base, fill, v);
90 }
91
92 ~num_put();
93
94 protected:
95 iter_type do_put(iter_type it, ios_base& base, char_type fill, bool v) const
96 {
97 auto loc = base.getloc();
98
99 if ((base.flags() & ios_base::boolalpha) == 0)
100 return do_put(it, base, fill, (long)v);
101 else
102 {
103 auto s = v ? use_facet<numpunct<char_type>>(loc).truename()
104 : use_facet<numpunct<char_type>>(loc).falsename();
105 for (auto c: s)
106 *it++ = c;
107 }
108
109 return it;
110 }
111
112 iter_type do_put(iter_type it, ios_base& base, char_type fill, long v) const
113 {
114 // TODO: implement
115 }
116
117 iter_type do_put(iter_type it, ios_base& base, char_type fill, long long v) const
118 {
119 // TODO: implement
120 }
121
122 iter_type do_put(iter_type it, ios_base& base, char_type fill, unsigned long v) const
123 {
124 // TODO: implement
125 }
126
127 iter_type do_put(iter_type it, ios_base& base, char_type fill, unsigned long long v) const
128 {
129 // TODO: implement
130 }
131
132 iter_type do_put(iter_type it, ios_base& base, char_type fill, double v) const
133 {
134 // TODO: implement
135 }
136
137 iter_type do_put(iter_type it, ios_base& base, char_type fill, long double v) const
138 {
139 // TODO: implement
140 }
141
142 iter_type do_put(iter_type it, ios_base& base, char_type fill, const void* v) const
143 {
144 // TODO: implement
145 }
146 };
147}
148
149#endif
Note: See TracBrowser for help on using the repository browser.