Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// archive_serializer_map.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
//////////////////////////////////////////////////////////////////////
// implementation of basic_text_iprimitive overrides for the combination
// of template parameters used to implement a text_iprimitive
#include <boost/config.hpp>
#include <boost/archive/detail/archive_serializer_map.hpp>
#include <boost/archive/detail/basic_serializer_map.hpp>
#include <boost/serialization/singleton.hpp>
namespace boost {
namespace archive {
namespace detail {
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#endif
namespace extra_detail { // anon
template<class Archive>
class map : public basic_serializer_map
{};
}
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(bool)
archive_serializer_map<Archive>::insert(const basic_serializer * bs){
return boost::serialization::singleton<
extra_detail::map<Archive>
>::get_mutable_instance().insert(bs);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
archive_serializer_map<Archive>::erase(const basic_serializer * bs){
if(boost::serialization::singleton<
extra_detail::map<Archive>
>::is_destroyed())
return;
boost::serialization::singleton<
extra_detail::map<Archive>
>::get_mutable_instance().erase(bs);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(const basic_serializer *)
archive_serializer_map<Archive>::find(
const boost::serialization::extended_type_info & eti
) {
return boost::serialization::singleton<
extra_detail::map<Archive>
>::get_const_instance().find(eti);
}
} // namespace detail
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,129 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_binary_iarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <string>
#include <boost/assert.hpp>
#include <algorithm>
#include <cstring>
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
using ::strlen;
using ::size_t;
}
#endif
#include <boost/detail/workaround.hpp>
#include <boost/detail/endian.hpp>
#include <boost/archive/basic_binary_iarchive.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implementation of binary_binary_archive
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iarchive<Archive>::load_override(class_name_type & t, int){
std::string cn;
cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
load_override(cn, 0);
if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_class_name)
);
std::memcpy(t, cn.data(), cn.size());
// borland tweak
t.t[cn.size()] = '\0';
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iarchive<Archive>::init(){
// read signature in an archive version independent manner
std::string file_signature;
try {
std::size_t l;
this->This()->load(l);
if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != file_signature.data())
#endif
file_signature.resize(l);
// note breaking a rule here - could be a problem on some platform
if(0 < l)
this->This()->load_binary(&(*file_signature.begin()), l);
}
}
catch(archive_exception const &) { // catch stream_error archive exceptions
// will cause invalid_signature archive exception to be thrown below
file_signature = "";
}
if(file_signature != BOOST_ARCHIVE_SIGNATURE())
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_signature)
);
// make sure the version of the reading archive library can
// support the format of the archive being read
library_version_type input_library_version;
//* this->This() >> input_library_version;
{
int v = 0;
v = this->This()->m_sb.sbumpc();
#if defined(BOOST_LITTLE_ENDIAN)
if(v < 6){
;
}
else
if(v < 7){
// version 6 - next byte should be zero
this->This()->m_sb.sbumpc();
}
else
if(v < 8){
int x1;
// version 7 = might be followed by zero or some other byte
x1 = this->This()->m_sb.sgetc();
// it's =a zero, push it back
if(0 == x1)
this->This()->m_sb.sbumpc();
}
else{
// version 8+ followed by a zero
this->This()->m_sb.sbumpc();
}
#elif defined(BOOST_BIG_ENDIAN)
if(v == 0)
v = this->This()->m_sb.sbumpc();
#endif
input_library_version = static_cast<library_version_type>(v);
}
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
this->set_library_version(input_library_version);
#else
#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
detail::
#endif
basic_iarchive::set_library_version(input_library_version);
#endif
if(BOOST_ARCHIVE_VERSION() < input_library_version)
boost::serialization::throw_exception(
archive_exception(archive_exception::unsupported_version)
);
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,209 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_binary_iprimitive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/assert.hpp>
#include <cstddef> // size_t, NULL
#include <cstring> // memcpy
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
using ::memcpy;
} // namespace std
#endif
#include <boost/detail/workaround.hpp> // fixup for RogueWave
#include <boost/serialization/throw_exception.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/archive/codecvt_null.hpp>
#include <boost/archive/add_facet.hpp>
namespace boost {
namespace archive {
//////////////////////////////////////////////////////////////////////
// implementation of basic_binary_iprimitive
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iprimitive<Archive, Elem, Tr>::init()
{
// Detect attempts to pass native binary archives across
// incompatible platforms. This is not fool proof but its
// better than nothing.
unsigned char size;
this->This()->load(size);
if(sizeof(int) != size)
boost::serialization::throw_exception(
archive_exception(
archive_exception::incompatible_native_format,
"size of int"
)
);
this->This()->load(size);
if(sizeof(long) != size)
boost::serialization::throw_exception(
archive_exception(
archive_exception::incompatible_native_format,
"size of long"
)
);
this->This()->load(size);
if(sizeof(float) != size)
boost::serialization::throw_exception(
archive_exception(
archive_exception::incompatible_native_format,
"size of float"
)
);
this->This()->load(size);
if(sizeof(double) != size)
boost::serialization::throw_exception(
archive_exception(
archive_exception::incompatible_native_format,
"size of double"
)
);
// for checking endian
int i;
this->This()->load(i);
if(1 != i)
boost::serialization::throw_exception(
archive_exception(
archive_exception::incompatible_native_format,
"endian setting"
)
);
}
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iprimitive<Archive, Elem, Tr>::load(wchar_t * ws)
{
std::size_t l; // number of wchar_t !!!
this->This()->load(l);
load_binary(ws, l * sizeof(wchar_t) / sizeof(char));
ws[l] = L'\0';
}
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iprimitive<Archive, Elem, Tr>::load(std::string & s)
{
std::size_t l;
this->This()->load(l);
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != s.data())
#endif
s.resize(l);
// note breaking a rule here - could be a problem on some platform
if(0 < l)
load_binary(&(*s.begin()), l);
}
#ifndef BOOST_NO_CWCHAR
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iprimitive<Archive, Elem, Tr>::load(char * s)
{
std::size_t l;
this->This()->load(l);
load_binary(s, l);
s[l] = '\0';
}
#endif
#ifndef BOOST_NO_STD_WSTRING
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_iprimitive<Archive, Elem, Tr>::load(std::wstring & ws)
{
std::size_t l;
this->This()->load(l);
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != ws.data())
#endif
ws.resize(l);
// note breaking a rule here - is could be a problem on some platform
load_binary(const_cast<wchar_t *>(ws.data()), l * sizeof(wchar_t) / sizeof(char));
}
#endif
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive(
std::basic_streambuf<Elem, Tr> & sb,
bool no_codecvt
) :
#ifndef BOOST_NO_STD_LOCALE
m_sb(sb),
archive_locale(NULL),
locale_saver(m_sb)
{
if(! no_codecvt){
archive_locale.reset(
boost::archive::add_facet(
std::locale::classic(),
new codecvt_null<Elem>
)
);
m_sb.pubimbue(* archive_locale);
}
}
#else
m_sb(sb)
{}
#endif
// some libraries including stl and libcomo fail if the
// buffer isn't flushed before the code_cvt facet is changed.
// I think this is a bug. We explicity invoke sync to when
// we're done with the streambuf to work around this problem.
// Note that sync is a protected member of stream buff so we
// have to invoke it through a contrived derived class.
namespace detail {
// note: use "using" to get past msvc bug
using namespace std;
template<class Elem, class Tr>
class input_streambuf_access : public std::basic_streambuf<Elem, Tr> {
public:
virtual int sync(){
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
return this->basic_streambuf::sync();
#else
return this->basic_streambuf<Elem, Tr>::sync();
#endif
}
};
} // detail
// scoped_ptr requires that archive_locale be a complete type at time of
// destruction so define destructor here rather than in the header
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){
// push back unread characters
//destructor can't throw !
try{
static_cast<detail::input_streambuf_access<Elem, Tr> &>(m_sb).sync();
}
catch(...){
}
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,46 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_binary_oarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <string>
#include <boost/assert.hpp>
#include <algorithm>
#include <cstring>
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
}
#endif
#include <boost/archive/basic_binary_oarchive.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implementation of binary_binary_oarchive
template<class Archive>
#if !defined(__BORLANDC__)
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
#else
void
#endif
basic_binary_oarchive<Archive>::init(){
// write signature in an archive version independent manner
const std::string file_signature(BOOST_ARCHIVE_SIGNATURE());
* this->This() << file_signature;
// write library version
const library_version_type v(BOOST_ARCHIVE_VERSION());
* this->This() << v;
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,160 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_binary_oprimitive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <ostream>
#include <cstddef> // NULL
#include <cstring>
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
namespace std{
using ::strlen;
} // namespace std
#endif
#ifndef BOOST_NO_CWCHAR
#include <cwchar>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{ using ::wcslen; }
#endif
#endif
#include <boost/detail/workaround.hpp>
#include <boost/archive/add_facet.hpp>
#include <boost/archive/codecvt_null.hpp>
namespace boost {
namespace archive {
//////////////////////////////////////////////////////////////////////
// implementation of basic_binary_oprimitive
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_oprimitive<Archive, Elem, Tr>::init()
{
// record native sizes of fundamental types
// this is to permit detection of attempts to pass
// native binary archives accross incompatible machines.
// This is not foolproof but its better than nothing.
this->This()->save(static_cast<unsigned char>(sizeof(int)));
this->This()->save(static_cast<unsigned char>(sizeof(long)));
this->This()->save(static_cast<unsigned char>(sizeof(float)));
this->This()->save(static_cast<unsigned char>(sizeof(double)));
// for checking endianness
this->This()->save(int(1));
}
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_oprimitive<Archive, Elem, Tr>::save(const char * s)
{
std::size_t l = std::strlen(s);
this->This()->save(l);
save_binary(s, l);
}
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::string &s)
{
std::size_t l = static_cast<std::size_t>(s.size());
this->This()->save(l);
save_binary(s.data(), l);
}
#ifndef BOOST_NO_CWCHAR
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws)
{
std::size_t l = std::wcslen(ws);
this->This()->save(l);
save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
}
#endif
#ifndef BOOST_NO_STD_WSTRING
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws)
{
std::size_t l = ws.size();
this->This()->save(l);
save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
}
#endif
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive(
std::basic_streambuf<Elem, Tr> & sb,
bool no_codecvt
) :
#ifndef BOOST_NO_STD_LOCALE
m_sb(sb),
archive_locale(NULL),
locale_saver(m_sb)
{
if(! no_codecvt){
archive_locale.reset(
add_facet(
std::locale::classic(),
new codecvt_null<Elem>
)
);
m_sb.pubimbue(* archive_locale);
}
}
#else
m_sb(sb)
{}
#endif
// some libraries including stl and libcomo fail if the
// buffer isn't flushed before the code_cvt facet is changed.
// I think this is a bug. We explicity invoke sync to when
// we're done with the streambuf to work around this problem.
// Note that sync is a protected member of stream buff so we
// have to invoke it through a contrived derived class.
namespace detail {
// note: use "using" to get past msvc bug
using namespace std;
template<class Elem, class Tr>
class output_streambuf_access : public std::basic_streambuf<Elem, Tr> {
public:
virtual int sync(){
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
return this->basic_streambuf::sync();
#else
return this->basic_streambuf<Elem, Tr>::sync();
#endif
}
};
} // detail
// scoped_ptr requires that g be a complete type at time of
// destruction so define destructor here rather than in the header
template<class Archive, class Elem, class Tr>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){
// flush buffer
//destructor can't throw
try{
static_cast<detail::output_streambuf_access<Elem, Tr> &>(m_sb).sync();
}
catch(...){
}
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,79 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_iarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <string>
#include <algorithm>
#include <cstring>
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
}
#endif
#include <boost/detail/workaround.hpp>
#include <boost/serialization/string.hpp>
#include <boost/archive/basic_text_iarchive.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implementation of text_text_archive
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_iarchive<Archive>::load_override(class_name_type & t, int){
std::string cn;
cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
load_override(cn, 0);
if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_class_name)
);
std::memcpy(t, cn.data(), cn.size());
// borland tweak
t.t[cn.size()] = '\0';
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_iarchive<Archive>::init(void){
// read signature in an archive version independent manner
std::string file_signature;
* this->This() >> file_signature;
if(file_signature != BOOST_ARCHIVE_SIGNATURE())
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_signature)
);
// make sure the version of the reading archive library can
// support the format of the archive being read
library_version_type input_library_version;
* this->This() >> input_library_version;
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
this->set_library_version(input_library_version);
#else
#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
detail::
#endif
basic_iarchive::set_library_version(input_library_version);
#endif
// extra little .t is to get around borland quirk
if(BOOST_ARCHIVE_VERSION() < input_library_version)
boost::serialization::throw_exception(
archive_exception(archive_exception::unsupported_version)
);
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,154 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_iprimitive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // size_t
#include <cstddef> // NULL
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/serialization/throw_exception.hpp>
#include <boost/serialization/pfto.hpp>
#include <boost/archive/basic_text_iprimitive.hpp>
#include <boost/archive/codecvt_null.hpp>
#include <boost/archive/add_facet.hpp>
#include <boost/archive/iterators/remove_whitespace.hpp>
#include <boost/archive/iterators/istream_iterator.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
namespace boost {
namespace archive {
namespace {
template<class CharType>
bool is_whitespace(CharType c);
template<>
bool is_whitespace(char t){
return 0 != std::isspace(t);
}
#ifndef BOOST_NO_CWCHAR
template<>
bool is_whitespace(wchar_t t){
return 0 != std::iswspace(t);
}
#endif
}
// translate base64 text into binary and copy into buffer
// until buffer is full.
template<class IStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_iprimitive<IStream>::load_binary(
void *address,
std::size_t count
){
typedef BOOST_DEDUCED_TYPENAME IStream::char_type CharType;
if(0 == count)
return;
BOOST_ASSERT(
static_cast<std::size_t>((std::numeric_limits<std::streamsize>::max)())
> (count + sizeof(CharType) - 1)/sizeof(CharType)
);
if(is.fail())
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
// convert from base64 to binary
typedef BOOST_DEDUCED_TYPENAME
iterators::transform_width<
iterators::binary_from_base64<
iterators::remove_whitespace<
iterators::istream_iterator<CharType>
>
,CharType
>
,8
,6
,CharType
>
binary;
binary ti_begin = binary(
BOOST_MAKE_PFTO_WRAPPER(
iterators::istream_iterator<CharType>(is)
)
);
char * caddr = static_cast<char *>(address);
// take care that we don't increment anymore than necessary
while(--count > 0){
*caddr++ = static_cast<char>(*ti_begin);
++ti_begin;
}
*caddr++ = static_cast<char>(*ti_begin);
iterators::istream_iterator<CharType> i;
for(;;){
BOOST_DEDUCED_TYPENAME IStream::int_type r;
r = is.get();
if(is.eof())
break;
if(is_whitespace(static_cast<CharType>(r)))
break;
}
}
template<class IStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_text_iprimitive<IStream>::basic_text_iprimitive(
IStream &is_,
bool no_codecvt
) :
#ifndef BOOST_NO_STD_LOCALE
is(is_),
flags_saver(is_),
precision_saver(is_),
archive_locale(NULL),
locale_saver(* is_.rdbuf())
{
if(! no_codecvt){
archive_locale.reset(
add_facet(
std::locale::classic(),
new codecvt_null<BOOST_DEDUCED_TYPENAME IStream::char_type>
)
);
is.imbue(* archive_locale);
}
is >> std::noboolalpha;
}
#else
is(is_),
flags_saver(is_),
precision_saver(is_)
{}
#endif
template<class IStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_text_iprimitive<IStream>::~basic_text_iprimitive(){
is.sync();
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,62 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_oarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <string>
#include <boost/assert.hpp>
#include <cstring>
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
}
#endif
#include <boost/archive/basic_text_oarchive.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implementation of basic_text_oarchive
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_oarchive<Archive>::newtoken()
{
switch(delimiter){
default:
BOOST_ASSERT(false);
break;
case eol:
this->This()->put('\n');
delimiter = space;
break;
case space:
this->This()->put(' ');
break;
case none:
delimiter = space;
break;
}
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_oarchive<Archive>::init(){
// write signature in an archive version independent manner
const std::string file_signature(BOOST_ARCHIVE_SIGNATURE());
* this->This() << file_signature;
// write library version
const library_version_type v(BOOST_ARCHIVE_VERSION());
* this->This() << v;
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,114 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_oprimitive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // NULL
#include <boost/serialization/pfto.hpp>
#include <boost/archive/basic_text_oprimitive.hpp>
#include <boost/archive/codecvt_null.hpp>
#include <boost/archive/add_facet.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
namespace boost {
namespace archive {
// translate to base64 and copy in to buffer.
template<class OStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_text_oprimitive<OStream>::save_binary(
const void *address,
std::size_t count
){
typedef BOOST_DEDUCED_TYPENAME OStream::char_type CharType;
if(0 == count)
return;
if(os.fail())
boost::serialization::throw_exception(
archive_exception(archive_exception::output_stream_error)
);
os.put('\n');
typedef
boost::archive::iterators::insert_linebreaks<
boost::archive::iterators::base64_from_binary<
boost::archive::iterators::transform_width<
const char *,
6,
8
>
>
,72
,const char // cwpro8 needs this
>
base64_text;
boost::archive::iterators::ostream_iterator<CharType> oi(os);
std::copy(
base64_text(BOOST_MAKE_PFTO_WRAPPER(static_cast<const char *>(address))),
base64_text(
BOOST_MAKE_PFTO_WRAPPER(static_cast<const char *>(address) + count)
),
oi
);
std::size_t tail = count % 3;
if(tail > 0){
*oi++ = '=';
if(tail < 2)
*oi = '=';
}
}
template<class OStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_text_oprimitive<OStream>::basic_text_oprimitive(
OStream & os_,
bool no_codecvt
) :
#ifndef BOOST_NO_STD_LOCALE
os(os_),
flags_saver(os_),
precision_saver(os_),
archive_locale(NULL),
locale_saver(* os_.rdbuf())
{
if(! no_codecvt){
archive_locale.reset(
add_facet(
std::locale::classic(),
new codecvt_null<BOOST_DEDUCED_TYPENAME OStream::char_type>
)
);
os.imbue(* archive_locale);
}
os << std::noboolalpha;
}
#else
os(os_),
flags_saver(os_),
precision_saver(os_)
{}
#endif
template<class OStream>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_text_oprimitive<OStream>::~basic_text_oprimitive(){
os << std::endl;
}
} //namespace boost
} //namespace archive

View File

@@ -0,0 +1,178 @@
#ifndef BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP
#define BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_xml_grammar.hpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
// this module is derived from simplexml.cpp - an example shipped as part of
// the spirit parser. This example contains the following notice:
/*=============================================================================
simplexml.cpp
Spirit V1.3
URL: http://spirit.sourceforge.net/
Copyright (c) 2001, Daniel C. Nuffer
This software is provided 'as-is', without any express or implied
warranty. In no event will the copyright holder be held liable for
any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
=============================================================================*/
#include <string>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
// supress noise
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <boost/spirit/include/classic_rule.hpp>
#include <boost/spirit/include/classic_chset.hpp>
#include <boost/archive/basic_archive.hpp>
#include <boost/serialization/tracking.hpp>
#include <boost/serialization/version.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// XML grammar parsing
template<class CharType>
class basic_xml_grammar {
public:
// The following is not necessary according to DR45, but at least
// one compiler (Compaq C++ 6.5 in strict_ansi mode) chokes otherwise.
struct return_values;
friend struct return_values;
private:
typedef BOOST_DEDUCED_TYPENAME std::basic_istream<CharType> IStream;
typedef BOOST_DEDUCED_TYPENAME std::basic_string<CharType> StringType;
typedef BOOST_DEDUCED_TYPENAME boost::spirit::classic::chset<CharType> chset_t;
typedef BOOST_DEDUCED_TYPENAME boost::spirit::classic::chlit<CharType> chlit_t;
typedef BOOST_DEDUCED_TYPENAME boost::spirit::classic::scanner<
BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::iterator
> scanner_t;
typedef BOOST_DEDUCED_TYPENAME boost::spirit::classic::rule<scanner_t> rule_t;
// Start grammar definition
rule_t
Reference,
Eq,
STag,
ETag,
LetterOrUnderscoreOrColon,
AttValue,
CharRef1,
CharRef2,
CharRef,
AmpRef,
LTRef,
GTRef,
AposRef,
QuoteRef,
CharData,
CharDataChars,
content,
AmpName,
LTName,
GTName,
ClassNameChar,
ClassName,
Name,
XMLDecl,
XMLDeclChars,
DocTypeDecl,
DocTypeDeclChars,
ClassIDAttribute,
ObjectIDAttribute,
ClassNameAttribute,
TrackingAttribute,
VersionAttribute,
UnusedAttribute,
Attribute,
SignatureAttribute,
SerializationWrapper,
NameHead,
NameTail,
AttributeList,
S;
// XML Character classes
chset_t
BaseChar,
Ideographic,
Char,
Letter,
Digit,
CombiningChar,
Extender,
Sch,
NameChar;
void init_chset();
bool my_parse(
IStream & is,
const rule_t &rule_,
const CharType delimiter = L'>'
) const ;
public:
struct return_values {
StringType object_name;
StringType contents;
//class_id_type class_id;
int_least16_t class_id;
//object_id_type object_id;
uint_least32_t object_id;
//version_type version;
unsigned int version;
tracking_type tracking_level;
StringType class_name;
return_values() :
version(0),
tracking_level(false)
{}
} rv;
bool parse_start_tag(IStream & is) /*const*/;
bool parse_end_tag(IStream & is) const;
bool parse_string(IStream & is, StringType & s) /*const*/;
void init(IStream & is);
void windup(IStream & is);
basic_xml_grammar();
};
} // namespace archive
} // namespace boost
#endif // BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP

View File

@@ -0,0 +1,114 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_xml_iarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/assert.hpp>
#include <cstddef> // NULL
#include <algorithm>
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/xml_archive_exception.hpp>
#include <boost/archive/basic_xml_iarchive.hpp>
#include <boost/serialization/tracking.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implementation of xml_text_archive
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_start(const char *name){
// if there's no name
if(NULL == name)
return;
bool result = this->This()->gimpl->parse_start_tag(this->This()->get_is());
if(true != result){
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
}
// don't check start tag at highest level
++depth;
return;
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_end(const char *name){
// if there's no name
if(NULL == name)
return;
bool result = this->This()->gimpl->parse_end_tag(this->This()->get_is());
if(true != result){
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
}
// don't check start tag at highest level
if(0 == --depth)
return;
if(0 == (this->get_flags() & no_xml_tag_checking)){
// double check that the tag matches what is expected - useful for debug
if(0 != name[this->This()->gimpl->rv.object_name.size()]
|| ! std::equal(
this->This()->gimpl->rv.object_name.begin(),
this->This()->gimpl->rv.object_name.end(),
name
)
){
boost::serialization::throw_exception(
xml_archive_exception(
xml_archive_exception::xml_archive_tag_mismatch,
name
)
);
}
}
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_override(object_id_type & t, int){
t = object_id_type(this->This()->gimpl->rv.object_id);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_override(version_type & t, int){
t = version_type(this->This()->gimpl->rv.version);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_override(class_id_type & t, int){
t = class_id_type(this->This()->gimpl->rv.class_id);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_iarchive<Archive>::load_override(tracking_type & t, int){
t = this->This()->gimpl->rv.tracking_level;
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_xml_iarchive<Archive>::basic_xml_iarchive(unsigned int flags) :
detail::common_iarchive<Archive>(flags),
depth(0)
{}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_xml_iarchive<Archive>::~basic_xml_iarchive(){}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,275 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_xml_oarchive.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <algorithm>
#include <cstddef> // NULL
#include <cstring>
#if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
namespace std{
using ::strlen;
} // namespace std
#endif
#include <boost/archive/basic_xml_archive.hpp>
#include <boost/archive/basic_xml_oarchive.hpp>
#include <boost/archive/xml_archive_exception.hpp>
#include <boost/detail/no_exceptions_support.hpp>
namespace boost {
namespace archive {
namespace detail {
template<class CharType>
struct XML_name {
void operator()(CharType t) const{
const unsigned char lookup_table[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0, // -.
1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, // 0-9
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // A-
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // -Z _
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // a-
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // -z
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
if((unsigned)t > 127)
return;
if(0 == lookup_table[(unsigned)t])
boost::serialization::throw_exception(
xml_archive_exception(
xml_archive_exception::xml_archive_tag_name_error
)
);
}
};
} // namespace detail
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implemenations of functions common to both types of xml output
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::write_attribute(
const char *attribute_name,
int t,
const char *conjunction
){
this->This()->put(' ');
this->This()->put(attribute_name);
this->This()->put(conjunction);
this->This()->save(t);
this->This()->put('"');
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::write_attribute(
const char *attribute_name,
const char *key
){
this->This()->put(' ');
this->This()->put(attribute_name);
this->This()->put("=\"");
this->This()->save(key);
this->This()->put('"');
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::indent(){
int i;
for(i = depth; i-- > 0;)
this->This()->put('\t');
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_start(const char *name)
{
if(NULL == name)
return;
// be sure name has no invalid characters
std::for_each(name, name + std::strlen(name), detail::XML_name<const char>());
end_preamble();
if(depth > 0){
this->This()->put('\n');
indent();
}
++depth;
this->This()->put('<');
this->This()->save(name);
pending_preamble = true;
indent_next = false;
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_end(const char *name)
{
if(NULL == name)
return;
// be sure name has no invalid characters
std::for_each(name, name + std::strlen(name), detail::XML_name<const char>());
end_preamble();
--depth;
if(indent_next){
this->This()->put('\n');
indent();
}
indent_next = true;
this->This()->put("</");
this->This()->save(name);
this->This()->put('>');
if(0 == depth)
this->This()->put('\n');
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::end_preamble(){
if(pending_preamble){
this->This()->put('>');
pending_preamble = false;
}
}
#if 0
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const object_id_type & t, int)
{
int i = t.t; // extra .t is for borland
write_attribute(BOOST_ARCHIVE_XML_OBJECT_ID(), i, "=\"_");
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(
const object_reference_type & t,
int
){
int i = t.t; // extra .t is for borland
write_attribute(BOOST_ARCHIVE_XML_OBJECT_REFERENCE(), i, "=\"_");
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const version_type & t, int)
{
int i = t.t; // extra .t is for borland
write_attribute(BOOST_ARCHIVE_XML_VERSION(), i);
}
#endif
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const object_id_type & t, int)
{
// borland doesn't do conversion of STRONG_TYPEDEFs very well
const unsigned int i = t;
write_attribute(BOOST_ARCHIVE_XML_OBJECT_ID(), i, "=\"_");
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(
const object_reference_type & t,
int
){
const unsigned int i = t;
write_attribute(BOOST_ARCHIVE_XML_OBJECT_REFERENCE(), i, "=\"_");
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const version_type & t, int)
{
const unsigned int i = t;
write_attribute(BOOST_ARCHIVE_XML_VERSION(), i);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const class_id_type & t, int)
{
write_attribute(BOOST_ARCHIVE_XML_CLASS_ID(), t);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(
const class_id_reference_type & t,
int
){
write_attribute(BOOST_ARCHIVE_XML_CLASS_ID_REFERENCE(), t);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(
const class_id_optional_type & t,
int
){
write_attribute(BOOST_ARCHIVE_XML_CLASS_ID(), t);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const class_name_type & t, int)
{
const char * key = t;
if(NULL == key)
return;
write_attribute(BOOST_ARCHIVE_XML_CLASS_NAME(), key);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::save_override(const tracking_type & t, int)
{
write_attribute(BOOST_ARCHIVE_XML_TRACKING(), t.t);
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
basic_xml_oarchive<Archive>::init(){
// xml header
this->This()->put("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n");
this->This()->put("<!DOCTYPE boost_serialization>\n");
// xml document wrapper - outer root
this->This()->put("<boost_serialization");
write_attribute("signature", BOOST_ARCHIVE_SIGNATURE());
write_attribute("version", BOOST_ARCHIVE_VERSION());
this->This()->put(">\n");
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_xml_oarchive<Archive>::basic_xml_oarchive(unsigned int flags) :
detail::common_oarchive<Archive>(flags),
depth(0),
indent_next(false),
pending_preamble(false)
{
}
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
basic_xml_oarchive<Archive>::~basic_xml_oarchive(){
if(0 == (this->get_flags() & no_header)){
BOOST_TRY{
this->This()->put("</boost_serialization>\n");
}
BOOST_CATCH(...){}
BOOST_CATCH_END
}
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,128 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// text_iarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
//////////////////////////////////////////////////////////////////////
// implementation of basic_text_iprimitive overrides for the combination
// of template parameters used to implement a text_iprimitive
#include <cstddef> // size_t, NULL
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/detail/workaround.hpp> // RogueWave
#include <boost/archive/text_iarchive.hpp>
namespace boost {
namespace archive {
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load(char *s)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
// Works on all tested platforms
is.read(s, size);
s[size] = '\0';
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load(std::string &s)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != s.data())
#endif
s.resize(size);
if(0 < size)
is.read(&(*s.begin()), size);
}
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load(wchar_t *ws)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
is.read((char *)ws, size * sizeof(wchar_t)/sizeof(char));
ws[size] = L'\0';
}
#endif // BOOST_NO_INTRINSIC_WCHAR_T
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load(std::wstring &ws)
{
std::size_t size;
* this->This() >> size;
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != ws.data())
#endif
ws.resize(size);
// skip separating space
is.get();
is.read((char *)ws.data(), size * sizeof(wchar_t)/sizeof(char));
}
#endif // BOOST_NO_STD_WSTRING
#endif // BOOST_NO_CWCHAR
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load_override(class_name_type & t, int){
basic_text_iarchive<Archive>::load_override(t, 0);
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::init(){
basic_text_iarchive<Archive>::init();
}
template<class Archive>
BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
text_iarchive_impl<Archive>::text_iarchive_impl(
std::istream & is,
unsigned int flags
) :
basic_text_iprimitive<std::istream>(
is,
0 != (flags & no_codecvt)
),
basic_text_iarchive<Archive>(flags)
{
if(0 == (flags & no_header))
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
this->init();
#else
this->basic_text_iarchive<Archive>::init();
#endif
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,124 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// text_oarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <string>
#include <boost/config.hpp>
#include <locale>
#include <cstddef> // size_t
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#ifndef BOOST_NO_CWCHAR
#include <cwchar>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{ using ::wcslen; }
#endif
#endif
#include <boost/archive/add_facet.hpp>
#include <boost/archive/text_oarchive.hpp>
namespace boost {
namespace archive {
//////////////////////////////////////////////////////////////////////
// implementation of basic_text_oprimitive overrides for the combination
// of template parameters used to create a text_oprimitive
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_oarchive_impl<Archive>::save(const char * s)
{
const std::size_t len = std::ostream::traits_type::length(s);
*this->This() << len;
this->This()->newtoken();
os << s;
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_oarchive_impl<Archive>::save(const std::string &s)
{
const std::size_t size = s.size();
*this->This() << size;
this->This()->newtoken();
os << s;
}
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_oarchive_impl<Archive>::save(const wchar_t * ws)
{
const std::size_t l = std::wcslen(ws);
* this->This() << l;
this->This()->newtoken();
os.write((const char *)ws, l * sizeof(wchar_t)/sizeof(char));
}
#endif
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_oarchive_impl<Archive>::save(const std::wstring &ws)
{
const std::size_t l = ws.size();
* this->This() << l;
this->This()->newtoken();
os.write((const char *)(ws.data()), l * sizeof(wchar_t)/sizeof(char));
}
#endif
#endif // BOOST_NO_CWCHAR
template<class Archive>
BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
text_oarchive_impl<Archive>::text_oarchive_impl(
std::ostream & os,
unsigned int flags
) :
basic_text_oprimitive<std::ostream>(
os,
0 != (flags & no_codecvt)
),
basic_text_oarchive<Archive>(flags)
{
if(0 == (flags & no_header))
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
this->init();
#else
this->basic_text_oarchive<Archive>::init();
#endif
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){
put('\n');
this->end_preamble();
#if ! defined(__MWERKS__)
this->basic_text_oprimitive<std::ostream>::save_binary(
#else
this->basic_text_oprimitive::save_binary(
#endif
address,
count
);
this->delimiter = this->eol;
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,118 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// text_text_wiarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // size_t, NULL
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
} // namespace std
#endif
#include <boost/detail/workaround.hpp> // fixup for RogueWave
#ifndef BOOST_NO_STD_WSTREAMBUF
#include <boost/archive/basic_text_iprimitive.hpp>
namespace boost {
namespace archive {
//////////////////////////////////////////////////////////////////////
// implementation of wiprimtives functions
//
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_wiarchive_impl<Archive>::load(char *s)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
while(size-- > 0){
*s++ = is.narrow(is.get(), '\0');
}
*s = '\0';
}
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_wiarchive_impl<Archive>::load(std::string &s)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != s.data())
#endif
s.resize(0);
s.reserve(size);
while(size-- > 0){
int x = is.narrow(is.get(), '\0');
s += x;
}
}
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_wiarchive_impl<Archive>::load(wchar_t *s)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
// Works on all tested platforms
is.read(s, size);
s[size] = L'\0';
}
#endif
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_wiarchive_impl<Archive>::load(std::wstring &ws)
{
std::size_t size;
* this->This() >> size;
// skip separating space
is.get();
// borland complains about resize
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != ws.data())
#endif
ws.resize(size);
// note breaking a rule here - is this a problem on some platform
is.read(const_cast<wchar_t *>(ws.data()), size);
}
#endif
template<class Archive>
BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
text_wiarchive_impl<Archive>::text_wiarchive_impl(
std::wistream & is,
unsigned int flags
) :
basic_text_iprimitive<std::wistream>(
is,
0 != (flags & no_codecvt)
),
basic_text_iarchive<Archive>(flags)
{
if(0 == (flags & no_header))
basic_text_iarchive<Archive>::init();
}
} // archive
} // boost
#endif // BOOST_NO_STD_WSTREAMBUF

View File

@@ -0,0 +1,85 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// text_woarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp>
#ifndef BOOST_NO_STD_WSTREAMBUF
#include <cstring>
#include <cstddef> // size_t
#if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
namespace std{
using ::strlen;
using ::size_t;
} // namespace std
#endif
#include <ostream>
#include <boost/archive/text_woarchive.hpp>
namespace boost {
namespace archive {
//////////////////////////////////////////////////////////////////////
// implementation of woarchive functions
//
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_woarchive_impl<Archive>::save(const char *s)
{
// note: superfluous local variable fixes borland warning
const std::size_t size = std::strlen(s);
* this->This() << size;
this->This()->newtoken();
while(*s != '\0')
os.put(os.widen(*s++));
}
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_woarchive_impl<Archive>::save(const std::string &s)
{
const std::size_t size = s.size();
* this->This() << size;
this->This()->newtoken();
const char * cptr = s.data();
for(std::size_t i = size; i-- > 0;)
os.put(os.widen(*cptr++));
}
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_woarchive_impl<Archive>::save(const wchar_t *ws)
{
const std::size_t size = std::wostream::traits_type::length(ws);
* this->This() << size;
this->This()->newtoken();
os.write(ws, size);
}
#endif
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_WARCHIVE_DECL(void)
text_woarchive_impl<Archive>::save(const std::wstring &ws)
{
const std::size_t size = ws.length();
* this->This() << size;
this->This()->newtoken();
os.write(ws.data(), size);
}
#endif
} // namespace archive
} // namespace boost
#endif

View File

@@ -0,0 +1,204 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// xml_iarchive_impl.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp>
#include <cstring> // memcpy
#include <cstddef> // NULL
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
} // namespace std
#endif
#ifndef BOOST_NO_CWCHAR
#include <cstdlib> // mbtowc
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::mbtowc;
} // namespace std
#endif
#endif // BOOST_NO_CWCHAR
#include <boost/detail/workaround.hpp> // RogueWave and Dinkumware
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
#include <boost/archive/dinkumware.hpp>
#endif
#include <boost/detail/no_exceptions_support.hpp>
#include <boost/archive/xml_archive_exception.hpp>
#include <boost/archive/iterators/dataflow_exception.hpp>
#include <boost/archive/basic_xml_archive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include "basic_xml_grammar.hpp"
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implemenations of functions specific to char archives
// wide char stuff used by char archives
#ifndef BOOST_NO_CWCHAR
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::load(std::wstring &ws){
std::string s;
bool result = gimpl->parse_string(is, s);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != ws.data())
#endif
ws.resize(0);
const char * start = s.data();
const char * end = start + s.size();
while(start < end){
wchar_t wc;
int resultx = std::mbtowc(&wc, start, end - start);
if(0 < resultx){
start += resultx;
ws += wc;
continue;
}
boost::serialization::throw_exception(
iterators::dataflow_exception(
iterators::dataflow_exception::invalid_conversion
)
);
}
}
#endif // BOOST_NO_STD_WSTRING
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::load(wchar_t * ws){
std::string s;
bool result = gimpl->parse_string(is, s);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
const char * start = s.data();
const char * end = start + s.size();
while(start < end){
wchar_t wc;
int result = std::mbtowc(&wc, start, end - start);
if(0 < result){
start += result;
*ws++ = wc;
continue;
}
boost::serialization::throw_exception(
iterators::dataflow_exception(
iterators::dataflow_exception::invalid_conversion
)
);
}
*ws = L'\0';
}
#endif // BOOST_NO_INTRINSIC_WCHAR_T
#endif // BOOST_NO_CWCHAR
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::load(std::string &s){
bool result = gimpl->parse_string(is, s);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::load(char * s){
std::string tstring;
bool result = gimpl->parse_string(is, tstring);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
std::memcpy(s, tstring.data(), tstring.size());
s[tstring.size()] = 0;
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::load_override(class_name_type & t, int){
const std::string & s = gimpl->rv.class_name;
if(s.size() > BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_class_name)
);
char * tptr = t;
std::memcpy(tptr, s.data(), s.size());
tptr[s.size()] = '\0';
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_iarchive_impl<Archive>::init(){
gimpl->init(is);
this->set_library_version(
library_version_type(gimpl->rv.version)
);
}
template<class Archive>
BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
xml_iarchive_impl<Archive>::xml_iarchive_impl(
std::istream &is_,
unsigned int flags
) :
basic_text_iprimitive<std::istream>(
is_,
0 != (flags & no_codecvt)
),
basic_xml_iarchive<Archive>(flags),
gimpl(new xml_grammar())
{
if(0 == (flags & no_header)){
BOOST_TRY{
init();
}
BOOST_CATCH(...){
delete gimpl;
#ifndef BOOST_NO_EXCEPTIONS
throw; // re-throw
#endif
}
BOOST_CATCH_END
}
}
template<class Archive>
BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
xml_iarchive_impl<Archive>::~xml_iarchive_impl(){
if(0 == (this->get_flags() & no_header)){
BOOST_TRY{
gimpl->windup(is);
}
BOOST_CATCH(...){}
BOOST_CATCH_END
}
delete gimpl;
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,117 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// xml_oarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <ostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring> // strlen
#include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::strlen;
} // namespace std
#endif
#include <boost/archive/iterators/xml_escape.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#ifndef BOOST_NO_CWCHAR
#include <boost/archive/wcslen.hpp>
#include <boost/archive/iterators/mb_from_wchar.hpp>
#endif
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implemenations of functions specific to char archives
// wide char stuff used by char archives
#ifndef BOOST_NO_CWCHAR
// copy chars to output escaping to xml and translating wide chars to mb chars
template<class InputIterator>
void save_iterator(std::ostream &os, InputIterator begin, InputIterator end){
typedef boost::archive::iterators::mb_from_wchar<
boost::archive::iterators::xml_escape<InputIterator>
> translator;
std::copy(
translator(BOOST_MAKE_PFTO_WRAPPER(begin)),
translator(BOOST_MAKE_PFTO_WRAPPER(end)),
boost::archive::iterators::ostream_iterator<char>(os)
);
}
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_oarchive_impl<Archive>::save(const std::wstring & ws){
// at least one library doesn't typedef value_type for strings
// so rather than using string directly make a pointer iterator out of it
// save_iterator(os, ws.data(), ws.data() + std::wcslen(ws.data()));
save_iterator(os, ws.data(), ws.data() + ws.size());
}
#endif
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_oarchive_impl<Archive>::save(const wchar_t * ws){
save_iterator(os, ws, ws + std::wcslen(ws));
}
#endif
#endif // BOOST_NO_CWCHAR
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_oarchive_impl<Archive>::save(const std::string & s){
// at least one library doesn't typedef value_type for strings
// so rather than using string directly make a pointer iterator out of it
typedef boost::archive::iterators::xml_escape<
const char *
> xml_escape_translator;
std::copy(
xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s.data())),
xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s.data()+ s.size())),
boost::archive::iterators::ostream_iterator<char>(os)
);
}
template<class Archive>
BOOST_ARCHIVE_DECL(void)
xml_oarchive_impl<Archive>::save(const char * s){
typedef boost::archive::iterators::xml_escape<
const char *
> xml_escape_translator;
std::copy(
xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s)),
xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s + std::strlen(s))),
boost::archive::iterators::ostream_iterator<char>(os)
);
}
template<class Archive>
BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
xml_oarchive_impl<Archive>::xml_oarchive_impl(
std::ostream & os_,
unsigned int flags
) :
basic_text_oprimitive<std::ostream>(
os_,
0 != (flags & no_codecvt)
),
basic_xml_oarchive<Archive>(flags)
{
if(0 == (flags & no_header))
this->init();
}
} // namespace archive
} // namespace boost

View File

@@ -0,0 +1,206 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// xml_wiprimitive.cpp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
#include <cstring>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
} //std
#endif
#include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
#ifndef BOOST_NO_STD_WSTREAMBUF
#include <boost/assert.hpp>
#include <algorithm>
#include <boost/detail/workaround.hpp> // Dinkumware and RogueWave
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
#include <boost/archive/dinkumware.hpp>
#endif
#include <boost/io/ios_state.hpp>
#include <boost/detail/no_exceptions_support.hpp>
#include <boost/serialization/pfto.hpp>
#include <boost/serialization/string.hpp>
#include <boost/archive/add_facet.hpp>
#include <boost/archive/xml_archive_exception.hpp>
#include <boost/archive/detail/utf8_codecvt_facet.hpp>
#include <boost/archive/iterators/mb_from_wchar.hpp>
#include <boost/archive/basic_xml_archive.hpp>
#include <boost/archive/xml_wiarchive.hpp>
#include "basic_xml_grammar.hpp"
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implemenations of functions specific to wide char archives
namespace { // anonymous
void copy_to_ptr(char * s, const std::wstring & ws){
std::copy(
iterators::mb_from_wchar<std::wstring::const_iterator>(
BOOST_MAKE_PFTO_WRAPPER(ws.begin())
),
iterators::mb_from_wchar<std::wstring::const_iterator>(
BOOST_MAKE_PFTO_WRAPPER(ws.end())
),
s
);
s[ws.size()] = 0;
}
} // anonymous
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::load(std::string & s){
std::wstring ws;
bool result = gimpl->parse_string(is, ws);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != s.data())
#endif
s.resize(0);
s.reserve(ws.size());
std::copy(
iterators::mb_from_wchar<std::wstring::iterator>(
BOOST_MAKE_PFTO_WRAPPER(ws.begin())
),
iterators::mb_from_wchar<std::wstring::iterator>(
BOOST_MAKE_PFTO_WRAPPER(ws.end())
),
std::back_inserter(s)
);
}
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::load(std::wstring & ws){
bool result = gimpl->parse_string(is, ws);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
}
#endif
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::load(char * s){
std::wstring ws;
bool result = gimpl->parse_string(is, ws);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
copy_to_ptr(s, ws);
}
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::load(wchar_t * ws){
std::wstring twstring;
bool result = gimpl->parse_string(is, twstring);
if(! result)
boost::serialization::throw_exception(
xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
);
std::memcpy(ws, twstring.c_str(), twstring.size());
ws[twstring.size()] = L'\0';
}
#endif
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::load_override(class_name_type & t, int){
const std::wstring & ws = gimpl->rv.class_name;
if(ws.size() > BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_class_name)
);
copy_to_ptr(t, ws);
}
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_wiarchive_impl<Archive>::init(){
gimpl->init(is);
this->set_library_version(
library_version_type(gimpl->rv.version)
);
}
template<class Archive>
BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
xml_wiarchive_impl<Archive>::xml_wiarchive_impl(
std::wistream &is_,
unsigned int flags
) :
basic_text_iprimitive<std::wistream>(
is_,
true // don't change the codecvt - use the one below
),
basic_xml_iarchive<Archive>(flags),
gimpl(new xml_wgrammar())
{
if(0 == (flags & no_codecvt)){
archive_locale.reset(
add_facet(
std::locale::classic(),
new boost::archive::detail::utf8_codecvt_facet
)
);
is.imbue(* archive_locale);
}
if(0 == (flags & no_header)){
BOOST_TRY{
this->init();
}
BOOST_CATCH(...){
delete gimpl;
#ifndef BOOST_NO_EXCEPTIONS
throw; // re-throw
#endif
}
BOOST_CATCH_END
}
}
template<class Archive>
BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
xml_wiarchive_impl<Archive>::~xml_wiarchive_impl(){
if(0 == (this->get_flags() & no_header)){
BOOST_TRY{
gimpl->windup(is);
}
BOOST_CATCH(...){}
BOOST_CATCH_END
}
delete gimpl;
}
} // namespace archive
} // namespace boost
#endif // BOOST_NO_STD_WSTREAMBUF

View File

@@ -0,0 +1,160 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// xml_woarchive_impl.ipp:
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/config.hpp>
#ifndef BOOST_NO_STD_WSTREAMBUF
#include <ostream>
#include <string>
#include <algorithm>
#include <locale>
#include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
// for BOOST_DEDUCED_TYPENAME
#include <cstring> // strlen
#include <cstdlib> // mbtowc
#include <cwchar> // wcslen
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::strlen;
#if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
using ::mbtowc;
using ::wcslen;
#endif
} // namespace std
#endif
#include <boost/serialization/throw_exception.hpp>
#include <boost/serialization/pfto.hpp>
#include <boost/archive/iterators/xml_escape.hpp>
#include <boost/archive/iterators/wchar_from_mb.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#include <boost/archive/iterators/dataflow_exception.hpp>
#include <boost/archive/add_facet.hpp>
#include <boost/archive/detail/utf8_codecvt_facet.hpp>
namespace boost {
namespace archive {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// implemenations of functions specific to wide char archives
// copy chars to output escaping to xml and widening characters as we go
template<class InputIterator>
void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
typedef iterators::wchar_from_mb<
iterators::xml_escape<InputIterator>
> xmbtows;
std::copy(
xmbtows(BOOST_MAKE_PFTO_WRAPPER(begin)),
xmbtows(BOOST_MAKE_PFTO_WRAPPER(end)),
boost::archive::iterators::ostream_iterator<wchar_t>(os)
);
}
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_woarchive_impl<Archive>::save(const std::string & s){
// note: we don't use s.begin() and s.end() because dinkumware
// doesn't have string::value_type defined. So use a wrapper
// around these values to implement the definitions.
const char * begin = s.data();
const char * end = begin + s.size();
save_iterator(os, begin, end);
}
#ifndef BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_woarchive_impl<Archive>::save(const std::wstring & ws){
#if 0
typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
std::copy(
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.begin())),
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.end())),
boost::archive::iterators::ostream_iterator<wchar_t>(os)
);
#endif
typedef iterators::xml_escape<const wchar_t *> xmbtows;
std::copy(
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.data())),
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.data() + ws.size())),
boost::archive::iterators::ostream_iterator<wchar_t>(os)
);
}
#endif //BOOST_NO_STD_WSTRING
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_woarchive_impl<Archive>::save(const char * s){
save_iterator(os, s, s + std::strlen(s));
}
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
template<class Archive>
BOOST_WARCHIVE_DECL(void)
xml_woarchive_impl<Archive>::save(const wchar_t * ws){
os << ws;
typedef iterators::xml_escape<const wchar_t *> xmbtows;
std::copy(
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws)),
xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws + std::wcslen(ws))),
boost::archive::iterators::ostream_iterator<wchar_t>(os)
);
}
#endif
template<class Archive>
BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
xml_woarchive_impl<Archive>::xml_woarchive_impl(
std::wostream & os_,
unsigned int flags
) :
basic_text_oprimitive<std::wostream>(
os_,
true // don't change the codecvt - use the one below
),
basic_xml_oarchive<Archive>(flags)
{
// Standard behavior is that imbue can be called
// a) before output is invoked or
// b) after flush has been called. This prevents one-to-many
// transforms (such as one to many transforms from getting
// mixed up. Unfortunately, STLPort doesn't respect b) above
// so the restoration of the original archive locale done by
// the locale_saver doesn't get processed,
// before the current one is destroyed.
// so the codecvt doesn't get replaced with the orginal
// so closing the stream invokes codecvt::do_unshift
// so it crashes because the corresponding locale that contained
// the codecvt isn't around any more.
// we can hack around this by using a static codecvt that never
// gets destroyed.
if(0 == (flags & no_codecvt)){
boost::archive::detail::utf8_codecvt_facet *pfacet;
#if defined(__SGI_STL_PORT)
static boost::archive::detail::utf8_codecvt_facet
facet(static_cast<size_t>(1));
pfacet = & facet;
#else
pfacet = new boost::archive::detail::utf8_codecvt_facet;
#endif
archive_locale.reset(add_facet(std::locale::classic(), pfacet));
os.imbue(* archive_locale);
}
if(0 == (flags & no_header))
this->init();
}
} // namespace archive
} // namespace boost
#endif //BOOST_NO_STD_WSTREAMBUF