PageRenderTime 46ms CodeModel.GetById 13ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/archive/dinkumware.hpp

http://hadesmem.googlecode.com/
C++ Header | 224 lines | 167 code | 34 blank | 23 comment | 13 complexity | 3986834efc4bd2ea98485e7dc7dfc7f6 MD5 | raw file
  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// define i/o operators for 64 bit integers
 31template<class CharType>
 32basic_ostream<CharType> & 
 33operator<<(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
 68template<class CharType>
 69basic_ostream<CharType> & 
 70operator<<(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
 81template<class CharType>
 82basic_istream<CharType> & 
 83operator>>(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
121template<class CharType>
122basic_istream<CharType> & 
123operator>>(basic_istream<CharType> &is, boost::uint64_t & t){
124    boost::int64_t it;
125    is >> it;
126    t = it;
127    return is;
128}
129
130//#endif
131
132template<>
133class back_insert_iterator<basic_string<char> > : public 
134    iterator<output_iterator_tag, char>
135{
136public:
137    typedef basic_string<char> container_type;
138    typedef container_type::reference reference;
139
140    explicit back_insert_iterator(container_type & s)
141        : container(& s)
142    {}    // construct with container
143    
144    back_insert_iterator<container_type> & operator=(
145        container_type::const_reference Val_
146    ){    // push value into container
147        //container->push_back(Val_);
148        *container += Val_;
149        return (*this);
150    }
151
152    back_insert_iterator<container_type> & operator*(){
153        return (*this);
154    }
155
156    back_insert_iterator<container_type> & operator++(){
157        // pretend to preincrement
158        return (*this);
159    }
160
161    back_insert_iterator<container_type> operator++(int){
162        // pretend to postincrement
163        return (*this);
164    }
165
166protected:
167    container_type *container;    // pointer to container
168};
169
170template<char> 
171inline back_insert_iterator<basic_string<char> > back_inserter(
172    basic_string<char> & s
173){
174    return (std::back_insert_iterator<basic_string<char> >(s));
175}
176
177template<>
178class back_insert_iterator<basic_string<wchar_t> > : public 
179    iterator<output_iterator_tag, wchar_t>
180{
181public:
182    typedef basic_string<wchar_t> container_type;
183    typedef container_type::reference reference;
184
185    explicit back_insert_iterator(container_type & s)
186        : container(& s)
187    {}    // construct with container
188    
189    back_insert_iterator<container_type> & operator=(
190        container_type::const_reference Val_
191    ){    // push value into container
192        //container->push_back(Val_);
193        *container += Val_;
194        return (*this);
195    }
196
197    back_insert_iterator<container_type> & operator*(){
198        return (*this);
199    }
200
201    back_insert_iterator<container_type> & operator++(){
202        // pretend to preincrement
203        return (*this);
204    }
205
206    back_insert_iterator<container_type> operator++(int){
207        // pretend to postincrement
208        return (*this);
209    }
210
211protected:
212    container_type *container;    // pointer to container
213};
214
215template<wchar_t> 
216inline back_insert_iterator<basic_string<wchar_t> > back_inserter(
217    basic_string<wchar_t> & s
218){
219    return (std::back_insert_iterator<basic_string<wchar_t> >(s));
220}
221
222} // namespace std
223
224#endif //BOOST_ARCHIVE_DINKUMWARE_HPP