Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:30

0001 #ifndef BOOST_ARCHIVE_DINKUMWARE_HPP
0002 #define BOOST_ARCHIVE_DINKUMWARE_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // dinkumware.hpp:
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 // this file adds a couple of things that are missing from the dinkumware
0020 // implementation of the standard library.
0021 
0022 #include <iterator>
0023 #include <string>
0024 
0025 #include <boost/config.hpp>
0026 #include <boost/cstdint.hpp>
0027 
0028 namespace std {
0029 
0030 // define i/o operators for 64 bit integers
0031 template<class CharType>
0032 basic_ostream<CharType> &
0033 operator<<(basic_ostream<CharType> & os, boost::uint64_t t){
0034     // octal rendering of 64 bit number would be 22 octets + eos
0035     CharType d[23];
0036     unsigned int radix;
0037 
0038     if(os.flags() & (int)std::ios_base::hex)
0039         radix = 16;
0040     else
0041     if(os.flags() & (int)std::ios_base::oct)
0042         radix = 8;
0043     else
0044     //if(s.flags() & (int)std::ios_base::dec)
0045         radix =  10;
0046     unsigned int i = 0;
0047     do{
0048         unsigned int j = t % radix;
0049         d[i++] = j + ((j < 10) ? '0' : ('a' - 10));
0050         t /= radix;
0051     }
0052     while(t > 0);
0053     d[i--] = '\0';
0054 
0055     // reverse digits
0056     unsigned int j = 0;
0057     while(j < i){
0058         CharType k = d[i];
0059         d[i] = d[j];
0060         d[j] = k;
0061         --i;++j;
0062     }
0063     os << d;
0064     return os;
0065 
0066 }
0067 
0068 template<class CharType>
0069 basic_ostream<CharType> &
0070 operator<<(basic_ostream<CharType> &os, boost::int64_t t){
0071     if(0 <= t){
0072         os << static_cast<boost::uint64_t>(t);
0073     }
0074     else{
0075         os.put('-');
0076         os << -t;
0077     }
0078     return os;
0079 }
0080 
0081 template<class CharType>
0082 basic_istream<CharType> &
0083 operator>>(basic_istream<CharType> &is, boost::int64_t & t){
0084     CharType d;
0085     do{
0086         d = is.get();
0087     }
0088     while(::isspace(d));
0089     bool negative = (d == '-');
0090     if(negative)
0091         d = is.get();
0092     unsigned int radix;
0093     if(is.flags() & (int)std::ios_base::hex)
0094         radix = 16;
0095     else
0096     if(is.flags() & (int)std::ios_base::oct)
0097         radix = 8;
0098     else
0099     //if(s.flags() & (int)std::ios_base::dec)
0100         radix =  10;
0101     t = 0;
0102     do{
0103         if('0' <= d && d <= '9')
0104             t = t * radix + (d - '0');
0105         else
0106         if('a' <= d && d <= 'f')
0107             t = t * radix + (d - 'a' + 10);
0108         else
0109             break;
0110         d = is.get();
0111     }
0112     while(!is.fail());
0113     // restore the delimiter
0114     is.putback(d);
0115     is.clear();
0116     if(negative)
0117         t = -t;
0118     return is;
0119 }
0120 
0121 template<class CharType>
0122 basic_istream<CharType> &
0123 operator>>(basic_istream<CharType> &is, boost::uint64_t & t){
0124     boost::int64_t it;
0125     is >> it;
0126     t = it;
0127     return is;
0128 }
0129 
0130 template<>
0131 class back_insert_iterator<basic_string<char> > : public
0132     iterator<output_iterator_tag, char>
0133 {
0134 public:
0135     typedef basic_string<char> container_type;
0136     typedef container_type::reference reference;
0137 
0138     explicit back_insert_iterator(container_type & s)
0139         : container(& s)
0140     {}    // construct with container
0141 
0142     back_insert_iterator<container_type> & operator=(
0143         container_type::const_reference Val_
0144     ){    // push value into container
0145         //container->push_back(Val_);
0146         *container += Val_;
0147         return (*this);
0148     }
0149 
0150     back_insert_iterator<container_type> & operator*(){
0151         return (*this);
0152     }
0153 
0154     back_insert_iterator<container_type> & operator++(){
0155         // pretend to preincrement
0156         return (*this);
0157     }
0158 
0159     back_insert_iterator<container_type> operator++(int){
0160         // pretend to postincrement
0161         return (*this);
0162     }
0163 
0164 protected:
0165     container_type *container;    // pointer to container
0166 };
0167 
0168 template<char>
0169 inline back_insert_iterator<basic_string<char> > back_inserter(
0170     basic_string<char> & s
0171 ){
0172     return (std::back_insert_iterator<basic_string<char> >(s));
0173 }
0174 
0175 template<>
0176 class back_insert_iterator<basic_string<wchar_t> > : public
0177     iterator<output_iterator_tag, wchar_t>
0178 {
0179 public:
0180     typedef basic_string<wchar_t> container_type;
0181     typedef container_type::reference reference;
0182 
0183     explicit back_insert_iterator(container_type & s)
0184         : container(& s)
0185     {}    // construct with container
0186 
0187     back_insert_iterator<container_type> & operator=(
0188         container_type::const_reference Val_
0189     ){    // push value into container
0190         //container->push_back(Val_);
0191         *container += Val_;
0192         return (*this);
0193     }
0194 
0195     back_insert_iterator<container_type> & operator*(){
0196         return (*this);
0197     }
0198 
0199     back_insert_iterator<container_type> & operator++(){
0200         // pretend to preincrement
0201         return (*this);
0202     }
0203 
0204     back_insert_iterator<container_type> operator++(int){
0205         // pretend to postincrement
0206         return (*this);
0207     }
0208 
0209 protected:
0210     container_type *container;    // pointer to container
0211 };
0212 
0213 template<wchar_t>
0214 inline back_insert_iterator<basic_string<wchar_t> > back_inserter(
0215     basic_string<wchar_t> & s
0216 ){
0217     return (std::back_insert_iterator<basic_string<wchar_t> >(s));
0218 }
0219 
0220 } // namespace std
0221 
0222 #endif //BOOST_ARCHIVE_DINKUMWARE_HPP