/* Copyright (c) 2014, 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 the copyright holder 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //CEREAL_FORCE_LINK_SHARED_LIBRARY(Sandbox) struct Archive {}; CEREAL_SETUP_ARCHIVE_TRAITS(Archive, Archive) struct Test { template void serialzize( Archive & ) { std::cout << "hey there" << std::endl; } template void save( Archive & ) const { std::cout << "saved by the bell" << std::endl; } template void load( Archive & ) { std::cout << "locked and loaded" << std::endl; } template static void load_and_construct( Archive &, cereal::construct & ) { } template int save_minimal() const { return 0; } template int save_minimal(const std::uint32_t) const { return 1; } template void load_minimal( int & ) { } }; template void serialize( Archive &, Test & ) { } template void load( Archive &, Test & ) { } template void save( Archive &, Test const & ) { } template int save_minimal( Test const & ) { return 0; } template int save_minimal( Test const &, const std::uint32_t ) { return 0; } namespace cereal { template <> struct LoadAndConstruct { template static void load_and_construct( Archive &, cereal::construct & construct ) { construct(); } }; } struct A { virtual void foo() = 0; virtual ~A() {} }; struct B : A { virtual ~B() {} void foo() {} template void serialize( Archive & ) { std::cout << "i'm in your b" << std::endl; } }; struct C { char a; }; CEREAL_REGISTER_TYPE(B) CEREAL_REGISTER_POLYMORPHIC_RELATION(A, B) class MemberMinimal { public: MemberMinimal() = default; template int save_minimal( Archive const & ) const { return x; } template void load_minimal( Archive const &, int const & str ) { x = str; } public: int x; }; int main() { typedef Test T; std::cout << std::boolalpha; // Test Load and Construct internal/external std::cout << "\tload_and_construct" << std::endl; std::cout << cereal::traits::has_member_load_and_construct::value << std::endl; std::cout << cereal::traits::has_non_member_load_and_construct::value << std::endl; // serialize std::cout << "\tserialize" << std::endl; std::cout << cereal::traits::has_member_serialize::value << std::endl; std::cout << cereal::traits::has_non_member_serialize::value << std::endl; // load std::cout << "\tload" << std::endl; std::cout << cereal::traits::has_member_load::value << std::endl; std::cout << cereal::traits::has_non_member_load::value << std::endl; // load minimal std::cout << "\tload minimal" << std::endl; std::cout << cereal::traits::has_member_load::value << std::endl; // save std::cout << "\tsave" << std::endl; std::cout << cereal::traits::has_member_save::value << std::endl; std::cout << cereal::traits::has_non_member_save::value << std::endl; // save_minimal std::cout << "\tsave_minimal" << std::endl; std::cout << cereal::traits::has_member_save_minimal::value << std::endl; std::cout << cereal::traits::has_non_member_save_minimal::value << std::endl; // save_minimal_versioned std::cout << "\tsave_minimal versioned" << std::endl; std::cout << cereal::traits::has_member_versioned_save_minimal::value << std::endl; std::cout << cereal::traits::has_non_member_versioned_save_minimal::value << std::endl; // splittable std::cout << "\t splittable" << std::endl; std::cout << cereal::traits::has_member_split::value << std::endl; std::cout << cereal::traits::has_non_member_split::value << std::endl; // serialiable std::cout << "\toutput serializable" << std::endl; std::cout << cereal::traits::is_output_serializable::value << std::endl; #if !defined(__INTEL_COMPILER) //! TODO: This causes icc to crash std::cout << cereal::traits::is_input_serializable::value << std::endl; #endif // specialized std::cout << "\tspecialized" << std::endl; std::cout << cereal::traits::detail::is_specialized_member_serialize::value << std::endl; std::cout << cereal::traits::detail::is_specialized_member_load_save::value << std::endl; std::cout << cereal::traits::detail::is_specialized_non_member_serialize::value << std::endl; std::cout << cereal::traits::detail::is_specialized_non_member_load_save::value << std::endl; std::cout << cereal::traits::detail::count_specializations::value << std::endl; std::cout << cereal::traits::is_specialized::value << std::endl; // array size std::cout << typeid(A).name() << std::endl; std::cout << typeid(cereal::traits::has_load_and_construct).name() << std::endl; // extra testing std::cout << "\textra" << std::endl; std::cout << cereal::traits::has_member_save_minimal::value << std::endl; std::cout << cereal::traits::has_member_load_minimal::value << std::endl; // DLL testing std::cout << "------DLL TESTING------" << std::endl; std::stringstream dllSS1; std::stringstream dllSS2; { cereal::XMLOutputArchive out(dllSS1); VersionTest x{1}; std::shared_ptr p = std::make_shared(); out(x); out( p ); std::shared_ptr ay = std::make_shared(); out(ay); } std::cout << dllSS1.str() << std::endl; { VersionTest x; std::shared_ptr p; std::shared_ptr ay; { cereal::XMLInputArchive in(dllSS1); in(x); in( p ); in( ay ); } { cereal::XMLOutputArchive out(dllSS2); out( x ); out( p ); out( ay ); } } std::cout << dllSS2.str() << std::endl; return 0; }