source: NonGTP/Boost/boost/archive/dinkumware.hpp @ 857

Revision 857, 5.7 KB checked in by igarcia, 19 years ago (diff)
Line 
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) && (_MSC_VER >= 1020)
6# pragma once
7#endif
8
9/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10// dinkumware.hpp:
11
12// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
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
28namespace std {
29
30// and this native STL lib is old Dinkumware (has not defined _CPPLIB_VER)
31//#if (defined _STLPORT_VERSION) \
32//&& !(defined _STLP_USE_NO_IOSTREAMS) \
33//&& (defined _YVALS)  \
34//&& (defined __IBMCPP__)
35
36// define i/o operators for 64 bit integers
37template<class CharType>
38basic_ostream<CharType> &
39operator<<(basic_ostream<CharType> & os, boost::uint64_t t){
40    // octal rendering of 64 bit number would be 22 octets + eos
41    CharType d[23];
42    unsigned int radix;
43
44    if(os.flags() & (int)std::ios_base::hex)
45        radix = 16;
46    else
47    if(os.flags() & (int)std::ios_base::oct)
48        radix = 8;
49    else
50    //if(s.flags() & (int)std::ios_base::dec)
51        radix =  10;
52    unsigned int i = 0;
53    do{
54        unsigned int j = t % radix;
55        d[i++] = j + ((j < 10) ? '0' : 'a');
56        t /= radix;
57    }
58    while(t > 0);
59    d[i--] = '\0';
60
61    // reverse digits
62    unsigned int j = 0;
63    while(j < i){
64        CharType k = d[i];
65        d[i] = d[j];
66        d[j] = k;
67        --i;++j;
68    }
69    os << d;
70    return os;
71
72}
73
74template<class CharType>
75basic_ostream<CharType> &
76operator<<(basic_ostream<CharType> &os, boost::int64_t t){
77    if(0 <= t){
78        os << static_cast<boost::uint64_t>(t);
79    }
80    else{
81        os.put('-');
82        os << -t;
83    }
84    return os;
85}
86
87template<class CharType>
88basic_istream<CharType> &
89operator>>(basic_istream<CharType> &is, boost::int64_t & t){
90    CharType d;
91    do{
92        d = is.get();
93    }
94    while(::isspace(d));
95    bool negative = (d == '-');
96    if(negative)
97        d = is.get();
98    unsigned int radix;
99    if(is.flags() & (int)std::ios_base::hex)
100        radix = 16;
101    else
102    if(is.flags() & (int)std::ios_base::oct)
103        radix = 8;
104    else
105    //if(s.flags() & (int)std::ios_base::dec)
106        radix =  10;
107    t = 0;
108    do{
109        if('0' <= d && d <= '9')
110            t = t * radix + (d - '0');
111        else
112        if('a' <= d && d <= 'f')
113            t = t * radix + (d - 'a' + 10);
114        else
115            break;
116        d = is.get();
117    }
118    while(!is.fail());
119    // restore the delimiter
120    is.putback(d);
121    is.clear();
122    if(negative)
123        t = -t;
124    return is;
125}
126
127template<class CharType>
128basic_istream<CharType> &
129operator>>(basic_istream<CharType> &is, boost::uint64_t & t){
130    boost::int64_t it;
131    is >> it;
132    t = it;
133    return is;
134}
135
136//#endif
137
138template<>
139class back_insert_iterator<basic_string<char> > : public
140    iterator<output_iterator_tag, char>
141{
142public:
143    typedef basic_string<char> container_type;
144    typedef container_type::reference reference;
145
146    explicit back_insert_iterator(container_type & s)
147        : container(& s)
148    {}    // construct with container
149   
150    back_insert_iterator<container_type> & operator=(
151        container_type::const_reference Val_
152    ){    // push value into container
153        //container->push_back(Val_);
154        *container += Val_;
155        return (*this);
156    }
157
158    back_insert_iterator<container_type> & operator*(){
159        return (*this);
160    }
161
162    back_insert_iterator<container_type> & operator++(){
163        // pretend to preincrement
164        return (*this);
165    }
166
167    back_insert_iterator<container_type> operator++(int){
168        // pretend to postincrement
169        return (*this);
170    }
171
172protected:
173    container_type *container;    // pointer to container
174};
175
176template<char>
177inline back_insert_iterator<basic_string<char> > back_inserter(
178    basic_string<char> & s
179){
180    return (std::back_insert_iterator<basic_string<char> >(s));
181}
182
183template<>
184class back_insert_iterator<basic_string<wchar_t> > : public
185    iterator<output_iterator_tag, wchar_t>
186{
187public:
188    typedef basic_string<wchar_t> container_type;
189    typedef container_type::reference reference;
190
191    explicit back_insert_iterator(container_type & s)
192        : container(& s)
193    {}    // construct with container
194   
195    back_insert_iterator<container_type> & operator=(
196        container_type::const_reference Val_
197    ){    // push value into container
198        //container->push_back(Val_);
199        *container += Val_;
200        return (*this);
201    }
202
203    back_insert_iterator<container_type> & operator*(){
204        return (*this);
205    }
206
207    back_insert_iterator<container_type> & operator++(){
208        // pretend to preincrement
209        return (*this);
210    }
211
212    back_insert_iterator<container_type> operator++(int){
213        // pretend to postincrement
214        return (*this);
215    }
216
217protected:
218    container_type *container;    // pointer to container
219};
220
221template<wchar_t>
222inline back_insert_iterator<basic_string<wchar_t> > back_inserter(
223    basic_string<wchar_t> & s
224){
225    return (std::back_insert_iterator<basic_string<wchar_t> >(s));
226}
227
228} // namespace std
229
230#endif //BOOST_ARCHIVE_DINKUMWARE_HPP
Note: See TracBrowser for help on using the repository browser.