/* Copyright (c) 2013, Randolph Voorhies, Shane Grant All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of cereal nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include namespace cereal { namespace detail { struct InputArchiveBase; struct OutputArchiveBase; //TODO template struct InputBinding {}; template struct OutputBinding {}; struct adl_tag {}; //! Causes the static object bindings between an archive type and a serializable type T template struct create_bindings { static const InputBinding & load(std::true_type) { return cereal::detail::StaticObject>::getInstance(); } static const OutputBinding & save(std::true_type) { return cereal::detail::StaticObject>::getInstance(); } inline static void load(std::false_type) {} inline static void save(std::false_type) {} }; //! When specialized, causes the compiler to instantiate its parameter template struct instantiate_function {}; template struct polymorphic_serialization_support { static void instantiate(); typedef instantiate_function unused; }; template void polymorphic_serialization_support::instantiate() { create_bindings::save( std::is_base_of() ); create_bindings::load( std::is_base_of() ); } namespace detail2 { template struct bind_to_archives { void bind(std::false_type) const { instantiate_polymorphic_binding( (T*)0, 0, adl_tag{} ); } void bind(std::true_type) const { } bind_to_archives const & bind() const { bind( std::is_abstract() ); return *this; } }; template struct init_binding; } // end namespace template void instantiate_polymorphic_binding( T*, int, adl_tag ) {}; #define CEREAL_REGISTER_ARCHIVE(Archive) \ namespace cereal { namespace detail { \ template \ typename polymorphic_serialization_support::type \ instantiate_polymorphic_binding( T*, Archive*, adl_tag ); \ } } // end namespaces #define CEREAL_BIND_TO_ARCHIVES(T) \ namespace cereal { \ namespace detail { \ namespace detail2 { \ template<> \ struct init_binding { \ static bind_to_archives const & b; \ }; \ bind_to_archives const & init_binding::b = \ ::cereal::detail::StaticObject< \ bind_to_archives \ >::getInstance().bind(); \ }}} // end namespaces } // namespace detail } // namespace cereal #include struct MyType {}; CEREAL_REGISTER_ARCHIVE(BinaryInputArchive); CEREAL_BIND_TO_ARCHIVES(MyType); template void nop(T&&t) {} int main() { //cereal::Singleton>::getInstance(); }