]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_ARCHIVE_DINKUMWARE_HPP |
2 | #define BOOST_ARCHIVE_DINKUMWARE_HPP | |
3 | ||
4 | // MS compatible compilers support #pragma once | |
5 | #if defined(_MSC_VER) | |
6 | # pragma once | |
7 | #endif | |
8 | ||
9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
10 | // dinkumware.hpp: | |
11 | ||
f67539c2 | 12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
7c673cae FG |
13 | // Use, modification and distribution is subject to the Boost Software |
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
15 | // http://www.boost.org/LICENSE_1_0.txt) | |
16 | ||
17 | // See http://www.boost.org for updates, documentation, and revision history. | |
18 | ||
19 | // this file adds a couple of things that are missing from the dinkumware | |
20 | // implementation of the standard library. | |
21 | ||
22 | #include <iterator> | |
23 | #include <string> | |
24 | ||
25 | #include <boost/config.hpp> | |
26 | #include <boost/cstdint.hpp> | |
27 | ||
28 | namespace std { | |
29 | ||
30 | // define i/o operators for 64 bit integers | |
31 | template<class CharType> | |
f67539c2 | 32 | basic_ostream<CharType> & |
7c673cae FG |
33 | operator<<(basic_ostream<CharType> & os, boost::uint64_t t){ |
34 | // octal rendering of 64 bit number would be 22 octets + eos | |
35 | CharType d[23]; | |
36 | unsigned int radix; | |
37 | ||
38 | if(os.flags() & (int)std::ios_base::hex) | |
39 | radix = 16; | |
40 | else | |
41 | if(os.flags() & (int)std::ios_base::oct) | |
42 | radix = 8; | |
43 | else | |
44 | //if(s.flags() & (int)std::ios_base::dec) | |
45 | radix = 10; | |
46 | unsigned int i = 0; | |
47 | do{ | |
48 | unsigned int j = t % radix; | |
49 | d[i++] = j + ((j < 10) ? '0' : ('a' - 10)); | |
50 | t /= radix; | |
51 | } | |
52 | while(t > 0); | |
53 | d[i--] = '\0'; | |
54 | ||
55 | // reverse digits | |
56 | unsigned int j = 0; | |
57 | while(j < i){ | |
58 | CharType k = d[i]; | |
59 | d[i] = d[j]; | |
60 | d[j] = k; | |
61 | --i;++j; | |
62 | } | |
63 | os << d; | |
64 | return os; | |
65 | ||
66 | } | |
67 | ||
68 | template<class CharType> | |
f67539c2 | 69 | basic_ostream<CharType> & |
7c673cae FG |
70 | operator<<(basic_ostream<CharType> &os, boost::int64_t t){ |
71 | if(0 <= t){ | |
72 | os << static_cast<boost::uint64_t>(t); | |
73 | } | |
74 | else{ | |
75 | os.put('-'); | |
76 | os << -t; | |
77 | } | |
78 | return os; | |
79 | } | |
80 | ||
81 | template<class CharType> | |
f67539c2 | 82 | basic_istream<CharType> & |
7c673cae FG |
83 | operator>>(basic_istream<CharType> &is, boost::int64_t & t){ |
84 | CharType d; | |
85 | do{ | |
86 | d = is.get(); | |
87 | } | |
88 | while(::isspace(d)); | |
89 | bool negative = (d == '-'); | |
90 | if(negative) | |
91 | d = is.get(); | |
92 | unsigned int radix; | |
93 | if(is.flags() & (int)std::ios_base::hex) | |
94 | radix = 16; | |
95 | else | |
96 | if(is.flags() & (int)std::ios_base::oct) | |
97 | radix = 8; | |
98 | else | |
99 | //if(s.flags() & (int)std::ios_base::dec) | |
100 | radix = 10; | |
101 | t = 0; | |
102 | do{ | |
103 | if('0' <= d && d <= '9') | |
104 | t = t * radix + (d - '0'); | |
105 | else | |
106 | if('a' <= d && d <= 'f') | |
107 | t = t * radix + (d - 'a' + 10); | |
108 | else | |
109 | break; | |
110 | d = is.get(); | |
111 | } | |
112 | while(!is.fail()); | |
113 | // restore the delimiter | |
114 | is.putback(d); | |
115 | is.clear(); | |
116 | if(negative) | |
117 | t = -t; | |
118 | return is; | |
119 | } | |
120 | ||
121 | template<class CharType> | |
f67539c2 | 122 | basic_istream<CharType> & |
7c673cae FG |
123 | operator>>(basic_istream<CharType> &is, boost::uint64_t & t){ |
124 | boost::int64_t it; | |
125 | is >> it; | |
126 | t = it; | |
127 | return is; | |
128 | } | |
129 | ||
7c673cae | 130 | template<> |
f67539c2 | 131 | class back_insert_iterator<basic_string<char> > : public |
7c673cae FG |
132 | iterator<output_iterator_tag, char> |
133 | { | |
134 | public: | |
135 | typedef basic_string<char> container_type; | |
136 | typedef container_type::reference reference; | |
137 | ||
138 | explicit back_insert_iterator(container_type & s) | |
139 | : container(& s) | |
140 | {} // construct with container | |
f67539c2 | 141 | |
7c673cae FG |
142 | back_insert_iterator<container_type> & operator=( |
143 | container_type::const_reference Val_ | |
144 | ){ // push value into container | |
145 | //container->push_back(Val_); | |
146 | *container += Val_; | |
147 | return (*this); | |
148 | } | |
149 | ||
150 | back_insert_iterator<container_type> & operator*(){ | |
151 | return (*this); | |
152 | } | |
153 | ||
154 | back_insert_iterator<container_type> & operator++(){ | |
155 | // pretend to preincrement | |
156 | return (*this); | |
157 | } | |
158 | ||
159 | back_insert_iterator<container_type> operator++(int){ | |
160 | // pretend to postincrement | |
161 | return (*this); | |
162 | } | |
163 | ||
164 | protected: | |
165 | container_type *container; // pointer to container | |
166 | }; | |
167 | ||
f67539c2 | 168 | template<char> |
7c673cae FG |
169 | inline back_insert_iterator<basic_string<char> > back_inserter( |
170 | basic_string<char> & s | |
171 | ){ | |
172 | return (std::back_insert_iterator<basic_string<char> >(s)); | |
173 | } | |
174 | ||
175 | template<> | |
f67539c2 | 176 | class back_insert_iterator<basic_string<wchar_t> > : public |
7c673cae FG |
177 | iterator<output_iterator_tag, wchar_t> |
178 | { | |
179 | public: | |
180 | typedef basic_string<wchar_t> container_type; | |
181 | typedef container_type::reference reference; | |
182 | ||
183 | explicit back_insert_iterator(container_type & s) | |
184 | : container(& s) | |
185 | {} // construct with container | |
f67539c2 | 186 | |
7c673cae FG |
187 | back_insert_iterator<container_type> & operator=( |
188 | container_type::const_reference Val_ | |
189 | ){ // push value into container | |
190 | //container->push_back(Val_); | |
191 | *container += Val_; | |
192 | return (*this); | |
193 | } | |
194 | ||
195 | back_insert_iterator<container_type> & operator*(){ | |
196 | return (*this); | |
197 | } | |
198 | ||
199 | back_insert_iterator<container_type> & operator++(){ | |
200 | // pretend to preincrement | |
201 | return (*this); | |
202 | } | |
203 | ||
204 | back_insert_iterator<container_type> operator++(int){ | |
205 | // pretend to postincrement | |
206 | return (*this); | |
207 | } | |
208 | ||
209 | protected: | |
210 | container_type *container; // pointer to container | |
211 | }; | |
212 | ||
f67539c2 | 213 | template<wchar_t> |
7c673cae FG |
214 | inline back_insert_iterator<basic_string<wchar_t> > back_inserter( |
215 | basic_string<wchar_t> & s | |
216 | ){ | |
217 | return (std::back_insert_iterator<basic_string<wchar_t> >(s)); | |
218 | } | |
219 | ||
220 | } // namespace std | |
221 | ||
222 | #endif //BOOST_ARCHIVE_DINKUMWARE_HPP |