williamr@2: #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP williamr@2: #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP williamr@2: williamr@2: // MS compatible compilers support #pragma once williamr@2: #if defined(_MSC_VER) && (_MSC_VER >= 1020) williamr@2: # pragma once williamr@2: #endif williamr@2: williamr@2: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 williamr@2: // basic_text_oprimitive.hpp williamr@2: williamr@2: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . williamr@2: // Use, modification and distribution is subject to the Boost Software williamr@2: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at williamr@2: // http://www.boost.org/LICENSE_1_0.txt) williamr@2: williamr@2: // See http://www.boost.org for updates, documentation, and revision history. williamr@2: williamr@2: // archives stored as text - note these ar templated on the basic williamr@2: // stream templates to accommodate wide (and other?) kind of characters williamr@2: // williamr@2: // note the fact that on libraries without wide characters, ostream is williamr@2: // is not a specialization of basic_ostream which in fact is not defined williamr@2: // in such cases. So we can't use basic_ostream but rather williamr@2: // use two template parameters williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include // size_t williamr@2: #include // isnan williamr@2: #include williamr@2: williamr@2: #include williamr@2: #include williamr@2: #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: #if defined(BOOST_NO_STDC_NAMESPACE) williamr@2: namespace std{ williamr@2: using ::size_t; williamr@2: #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT) williamr@2: using ::locale; williamr@2: #endif williamr@2: } // namespace std williamr@2: #endif williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: #include // must be the last header williamr@2: williamr@2: namespace boost { williamr@2: namespace archive { williamr@2: williamr@2: class save_access; williamr@2: williamr@2: ///////////////////////////////////////////////////////////////////////// williamr@2: // class basic_text_oprimitive - output of prmitives to stream williamr@2: template williamr@2: class basic_text_oprimitive williamr@2: { williamr@2: #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS williamr@2: protected: williamr@2: #else williamr@2: public: williamr@2: #endif williamr@2: OStream &os; williamr@2: io::ios_flags_saver flags_saver; williamr@2: io::ios_precision_saver precision_saver; williamr@2: boost::scoped_ptr archive_locale; williamr@2: io::basic_ios_locale_saver< williamr@2: BOOST_DEDUCED_TYPENAME OStream::char_type, BOOST_DEDUCED_TYPENAME OStream::traits_type williamr@2: > locale_saver; williamr@2: williamr@2: // default saving of primitives. williamr@2: template williamr@2: void save(const T &t){ williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << t; williamr@2: } williamr@2: williamr@2: ///////////////////////////////////////////////////////// williamr@2: // fundamental types that need special treatment williamr@2: void save(const bool t){ williamr@2: // trap usage of invalid uninitialized boolean which would williamr@2: // otherwise crash on load. williamr@2: int i = t; williamr@2: assert(0 == i || 1 == i); williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << t; williamr@2: } williamr@2: void save(const signed char t) williamr@2: { williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << static_cast(t); williamr@2: } williamr@2: void save(const unsigned char t) williamr@2: { williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << static_cast(t); williamr@2: } williamr@2: void save(const char t) williamr@2: { williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << static_cast(t); williamr@2: } williamr@2: #ifndef BOOST_NO_INTRINSIC_WCHAR_T williamr@2: void save(const wchar_t t) williamr@2: { williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << static_cast(t); williamr@2: } williamr@2: #endif williamr@2: void save(const float t) williamr@2: { williamr@2: // must be a user mistake - can't serialize un-initialized data williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << std::setprecision(std::numeric_limits::digits10 + 2); williamr@2: os << t; williamr@2: } williamr@2: void save(const double t) williamr@2: { williamr@2: // must be a user mistake - can't serialize un-initialized data williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os << std::setprecision(std::numeric_limits::digits10 + 2); williamr@2: os << t; williamr@2: } williamr@2: BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) williamr@2: basic_text_oprimitive(OStream & os, bool no_codecvt); williamr@2: BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) williamr@2: ~basic_text_oprimitive(); williamr@2: public: williamr@2: // unformatted append of one character williamr@2: void put(int c){ williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: os.put(c); williamr@2: } williamr@2: // unformatted append of null terminated string williamr@2: void put(const char * s){ williamr@2: if(os.fail()) williamr@2: boost::throw_exception(archive_exception(archive_exception::stream_error)); williamr@2: while('\0' != *s) williamr@2: os.put(*s++); williamr@2: } williamr@2: BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) williamr@2: save_binary(const void *address, std::size_t count); williamr@2: }; williamr@2: williamr@2: } //namespace boost williamr@2: } //namespace archive williamr@2: williamr@2: #include // pops abi_suffix.hpp pragmas williamr@2: williamr@2: #endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP