Chris@16: #ifndef BOOST_ARCHIVE_DETAIL_CHECK_HPP Chris@16: #define BOOST_ARCHIVE_DETAIL_CHECK_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #pragma inline_depth(511) Chris@16: #pragma inline_recursion(on) Chris@16: #endif Chris@16: Chris@16: #if defined(__MWERKS__) Chris@16: #pragma inline_depth(511) Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // check.hpp: interface for serialization system. Chris@16: Chris@16: // (C) Copyright 2009 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace detail { Chris@16: Chris@16: // checks for objects Chris@16: Chris@16: template Chris@16: inline void check_object_level(){ Chris@16: typedef Chris@101: typename mpl::greater_equal< Chris@16: serialization::implementation_level< T >, Chris@16: mpl::int_ Chris@16: >::type typex; Chris@16: Chris@16: // trap attempts to serialize objects marked Chris@16: // not_serializable Chris@16: BOOST_STATIC_ASSERT(typex::value); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void check_object_versioning(){ Chris@16: typedef Chris@101: typename mpl::or_< Chris@101: typename mpl::greater< Chris@16: serialization::implementation_level< T >, Chris@16: mpl::int_ Chris@16: >, Chris@101: typename mpl::equal_to< Chris@16: serialization::version< T >, Chris@16: mpl::int_<0> Chris@16: > Chris@16: > typex; Chris@16: // trap attempts to serialize with objects that don't Chris@16: // save class information in the archive with versioning. Chris@16: BOOST_STATIC_ASSERT(typex::value); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void check_object_tracking(){ Chris@16: // presume it has already been determined that Chris@16: // T is not a const Chris@16: BOOST_STATIC_ASSERT(! boost::is_const< T >::value); Chris@101: typedef typename mpl::equal_to< Chris@16: serialization::tracking_level< T >, Chris@16: mpl::int_ Chris@16: >::type typex; Chris@16: // saving an non-const object of a type not marked "track_never) Chris@16: Chris@16: // may be an indicator of an error usage of the Chris@16: // serialization library and should be double checked. Chris@16: // See documentation on object tracking. Also, see the Chris@16: // "rationale" section of the documenation Chris@16: // for motivation for this checking. Chris@16: Chris@16: BOOST_STATIC_WARNING(typex::value); Chris@16: } Chris@16: Chris@16: // checks for pointers Chris@16: Chris@16: template Chris@16: inline void check_pointer_level(){ Chris@16: // we should only invoke this once we KNOW that T Chris@16: // has been used as a pointer!! Chris@16: typedef Chris@101: typename mpl::or_< Chris@101: typename mpl::greater< Chris@16: serialization::implementation_level< T >, Chris@16: mpl::int_ Chris@16: >, Chris@101: typename mpl::not_< Chris@101: typename mpl::equal_to< Chris@16: serialization::tracking_level< T >, Chris@16: mpl::int_ Chris@16: > Chris@16: > Chris@16: > typex; Chris@16: // Address the following when serializing to a pointer: Chris@16: Chris@16: // a) This type doesn't save class information in the Chris@16: // archive. That is, the serialization trait implementation Chris@16: // level <= object_serializable. Chris@16: // b) Tracking for this type is set to "track selectively" Chris@16: Chris@16: // in this case, indication that an object is tracked is Chris@16: // not stored in the archive itself - see level == object_serializable Chris@16: // but rather the existence of the operation ar >> T * is used to Chris@16: // infer that an object of this type should be tracked. So, if Chris@16: // you save via a pointer but don't load via a pointer the operation Chris@16: // will fail on load without given any valid reason for the failure. Chris@16: Chris@16: // So if your program traps here, consider changing the Chris@16: // tracking or implementation level traits - or not Chris@16: // serializing via a pointer. Chris@16: BOOST_STATIC_WARNING(typex::value); Chris@16: } Chris@16: Chris@16: template Chris@16: void inline check_pointer_tracking(){ Chris@101: typedef typename mpl::greater< Chris@16: serialization::tracking_level< T >, Chris@16: mpl::int_ Chris@16: >::type typex; Chris@16: // serializing an object of a type marked "track_never" through a pointer Chris@16: // could result in creating more objects than were saved! Chris@16: BOOST_STATIC_WARNING(typex::value); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void check_const_loading(){ Chris@16: typedef Chris@101: typename mpl::or_< Chris@101: typename boost::serialization::is_wrapper< T >, Chris@101: typename mpl::not_< Chris@101: typename boost::is_const< T > Chris@16: > Chris@16: >::type typex; Chris@16: // cannot load data into a "const" object unless it's a Chris@16: // wrapper around some other non-const object. Chris@16: BOOST_STATIC_ASSERT(typex::value); Chris@16: } Chris@16: Chris@16: } // detail Chris@16: } // archive Chris@16: } // boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_DETAIL_CHECK_HPP