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