source: mainline/uspace/lib/cpp/include/__bits/locale/locale.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: 5.3 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_BITS_LOCALE
30#define LIBCPP_BITS_LOCALE
31
32#include <__bits/string/string.hpp>
33
34namespace std
35{
36 class locale;
37
38 /**
39 * 22.3.1, class locale:
40 */
41
42 class locale
43 {
44 public:
45 class facet
46 {
47 protected:
48 explicit facet(size_t refs = 0);
49
50 virtual ~facet();
51
52 facet(const facet&) = delete;
53 void operator=(const facet&) = delete;
54 };
55
56 class id
57 {
58 public:
59 id() = default;
60
61 id(const id&) = delete;
62 void operator=(const id&) = delete;
63 };
64
65 using category = int;
66
67 static const category none = 0b000'0001;
68 static const category collate = 0b000'0010;
69 static const category ctype = 0b000'0100;
70 static const category monetary = 0b000'1000;
71 static const category numeric = 0b001'0000;
72 static const category time = 0b010'0000;
73 static const category messages = 0b100'0000;
74 static const category all = collate | ctype | monetary |
75 numeric | time | messages;
76
77 locale() noexcept;
78
79 locale(const locale& other) noexcept;
80
81 explicit locale(const char* name);
82
83 explicit locale(const string& name);
84
85 locale(const locale& other, const char* name, category);
86
87 locale(const locale& other, const string& name, category);
88
89 template<class Facet>
90 locale(const locale& other, Facet* f)
91 : name_{other.name_}
92 { /* DUMMY BODY */ }
93
94 locale(const locale& other, const locale& one, category);
95
96 ~locale() = default;
97
98 const locale& operator=(const locale& other) noexcept;
99
100 template<class Facet>
101 locale combine(const locale& other) const
102 {
103 return other;
104 }
105
106 string name() const;
107
108 bool operator==(const locale& other) const;
109 bool operator!=(const locale& other) const;
110
111 template<class Char, class Traits, class Allocator>
112 bool operator()(const basic_string<Char, Traits, Allocator>& s1,
113 const basic_string<Char, Traits, Allocator>& s2) const
114 {
115 // TODO: define outside locale
116 /* return use_facet<collate<Char>>(*this).compare( */
117 /* s1.begin(), s1.end(), s2.begin(), s2.end() */
118 /* ) < 0; */
119 return false;
120 }
121
122 static locale global(const locale&)
123 {
124 return *the_locale_;
125 }
126
127 static const locale& classic()
128 {
129 return *the_locale_;
130 }
131
132 private:
133 string name_;
134
135 // TODO: implement the_locale_
136 static constexpr locale* the_locale_{nullptr};
137
138 template<class Facet>
139 friend bool has_facet(const locale&);
140
141 template<class Facet>
142 bool has_()
143 { // Our single locale atm has all facets.
144 return true;
145 }
146
147 template<class Facet>
148 /* friend const Facet& use_facet(const locale&); */
149 friend Facet use_facet(const locale&);
150
151 template<class Facet>
152 /* const Facet& get_() const */
153 Facet get_() const
154 {
155 return Facet{0U};
156 }
157 };
158
159 template<class Facet>
160 /* const Facet& use_facet(const locale& loc) */
161 Facet use_facet(const locale& loc)
162 {
163 return loc.get_<Facet>();
164 }
165
166 template<class Facet>
167 bool has_facet(const locale& loc)
168 {
169 return loc.has_<Facet>();
170 }
171}
172
173#endif
Note: See TracBrowser for help on using the repository browser.