ossrv_pub/boost_apis/boost/archive/basic_text_oprimitive.hpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP
       
     2 #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_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 // basic_text_oprimitive.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 // archives stored as text - note these ar templated on the basic
       
    20 // stream templates to accommodate wide (and other?) kind of characters
       
    21 //
       
    22 // note the fact that on libraries without wide characters, ostream is
       
    23 // is not a specialization of basic_ostream which in fact is not defined
       
    24 // in such cases.   So we can't use basic_ostream<OStream::char_type> but rather
       
    25 // use two template parameters
       
    26 
       
    27 #include <iomanip>
       
    28 #include <locale>
       
    29 #include <cstddef> // size_t
       
    30 #include <cmath> // isnan
       
    31 #include <cassert>
       
    32 
       
    33 #include <boost/config.hpp>
       
    34 #include <boost/detail/workaround.hpp>
       
    35 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
       
    36 #include <boost/archive/dinkumware.hpp>
       
    37 #endif
       
    38 
       
    39 #if defined(BOOST_NO_STDC_NAMESPACE)
       
    40 namespace std{ 
       
    41     using ::size_t;
       
    42     #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
       
    43         using ::locale;
       
    44     #endif
       
    45 } // namespace std
       
    46 #endif
       
    47 
       
    48 #include <boost/limits.hpp>
       
    49 #include <boost/io/ios_state.hpp>
       
    50 #include <boost/scoped_ptr.hpp>
       
    51 #include <boost/throw_exception.hpp>
       
    52 #include <boost/archive/archive_exception.hpp>
       
    53 
       
    54 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
       
    55 
       
    56 namespace boost {
       
    57 namespace archive {
       
    58 
       
    59 class save_access;
       
    60 
       
    61 /////////////////////////////////////////////////////////////////////////
       
    62 // class basic_text_oprimitive - output of prmitives to stream
       
    63 template<class OStream>
       
    64 class basic_text_oprimitive
       
    65 {
       
    66 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
       
    67 protected:
       
    68 #else
       
    69 public:
       
    70 #endif
       
    71     OStream &os;
       
    72     io::ios_flags_saver flags_saver;
       
    73     io::ios_precision_saver precision_saver;
       
    74     boost::scoped_ptr<std::locale> archive_locale;
       
    75     io::basic_ios_locale_saver<
       
    76         BOOST_DEDUCED_TYPENAME OStream::char_type, BOOST_DEDUCED_TYPENAME OStream::traits_type
       
    77     > locale_saver;
       
    78 
       
    79     // default saving of primitives.
       
    80     template<class T>
       
    81     void save(const T &t){
       
    82         if(os.fail())
       
    83             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
    84         os << t;
       
    85     }
       
    86 
       
    87     /////////////////////////////////////////////////////////
       
    88     // fundamental types that need special treatment
       
    89     void save(const bool t){
       
    90         // trap usage of invalid uninitialized boolean which would
       
    91         // otherwise crash on load.
       
    92         int i = t;
       
    93         assert(0 == i || 1 == i);
       
    94         if(os.fail())
       
    95             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
    96         os << t;
       
    97     }
       
    98     void save(const signed char t)
       
    99     {
       
   100         if(os.fail())
       
   101             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   102         os << static_cast<short int>(t);
       
   103     }
       
   104     void save(const unsigned char t)
       
   105     {
       
   106         if(os.fail())
       
   107             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   108         os << static_cast<short unsigned int>(t);
       
   109     }
       
   110     void save(const char t)
       
   111     {
       
   112         if(os.fail())
       
   113             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   114         os << static_cast<short int>(t);
       
   115     }
       
   116     #ifndef BOOST_NO_INTRINSIC_WCHAR_T
       
   117     void save(const wchar_t t)
       
   118     {
       
   119         if(os.fail())
       
   120             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   121         os << static_cast<int>(t);
       
   122     }
       
   123     #endif
       
   124     void save(const float t)
       
   125     {
       
   126         // must be a user mistake - can't serialize un-initialized data
       
   127         if(os.fail())
       
   128             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   129         os << std::setprecision(std::numeric_limits<float>::digits10 + 2);
       
   130         os << t;
       
   131     }
       
   132     void save(const double t)
       
   133     {
       
   134         // must be a user mistake - can't serialize un-initialized data
       
   135         if(os.fail())
       
   136             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   137         os << std::setprecision(std::numeric_limits<double>::digits10 + 2);
       
   138         os << t;
       
   139     }
       
   140     BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
       
   141     basic_text_oprimitive(OStream & os, bool no_codecvt);
       
   142     BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) 
       
   143     ~basic_text_oprimitive();
       
   144 public:
       
   145     // unformatted append of one character
       
   146     void put(int c){
       
   147         if(os.fail())
       
   148             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   149         os.put(c);
       
   150     }
       
   151     // unformatted append of null terminated string
       
   152     void put(const char * s){
       
   153         if(os.fail())
       
   154             boost::throw_exception(archive_exception(archive_exception::stream_error));
       
   155         while('\0' != *s)
       
   156             os.put(*s++);
       
   157     }
       
   158     BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) 
       
   159     save_binary(const void *address, std::size_t count);
       
   160 };
       
   161 
       
   162 } //namespace boost 
       
   163 } //namespace archive 
       
   164 
       
   165 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
       
   166 
       
   167 #endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP