mirror of
https://github.com/USCiLab/cereal.git
synced 2025-09-27 20:59:32 +02:00
progress on #113
still not working properly - StaticObject will correctly be initialized but then we'll end up with more than one of them (one in DLL one in app)
This commit is contained in:
parent
292f9760bd
commit
27ce5592f3
@ -37,6 +37,7 @@
|
||||
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) */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define CEREAL_DLL_EXPORT __declspec(dllexport)
|
||||
# define CEREAL_USED
|
||||
@ -64,26 +65,27 @@ namespace cereal
|
||||
//! Forces instantiation at pre-execution time
|
||||
static void instantiate( T const & ) {}
|
||||
|
||||
CEREAL_DLL_EXPORT static T & create()
|
||||
static T & create()
|
||||
{
|
||||
static T t;
|
||||
instantiate(instance);
|
||||
std::cerr << "I AM A STATIC OBJECT AT " << typeid(T).name() << " " << std::addressof(t) << std::endl;
|
||||
return t;
|
||||
}
|
||||
|
||||
StaticObject( StaticObject const & /*other*/ ) {}
|
||||
|
||||
public:
|
||||
CEREAL_DLL_EXPORT static T & getInstance()
|
||||
static T & getInstance()
|
||||
{
|
||||
return create();
|
||||
}
|
||||
|
||||
private:
|
||||
CEREAL_DLL_EXPORT static T & instance;
|
||||
static T & instance;
|
||||
};
|
||||
|
||||
template <class T> CEREAL_DLL_EXPORT T & StaticObject<T>::instance = StaticObject<T>::create();
|
||||
template <class T> T & StaticObject<T>::instance = StaticObject<T>::create();
|
||||
} // namespace detail
|
||||
} // namespace cereal
|
||||
|
||||
|
@ -103,7 +103,7 @@
|
||||
#define CEREAL_REGISTER_SHARED_LIBRARY(LibName) \
|
||||
namespace cereal { \
|
||||
namespace detail { \
|
||||
void load_library_dummy_##LibName() {} \
|
||||
void CEREAL_DLL_EXPORT load_library_dummy_##LibName() {} \
|
||||
} } /* end namespaces */
|
||||
|
||||
//! Forces the linker to link a previously registered
|
||||
|
@ -40,6 +40,11 @@
|
||||
#include <type_traits>
|
||||
#include <functional>
|
||||
|
||||
#include <base.hpp>
|
||||
#include <derived.hpp>
|
||||
|
||||
CEREAL_FORCE_LINK_SHARED_LIBRARY(Sandbox)
|
||||
|
||||
struct Archive {};
|
||||
CEREAL_SETUP_ARCHIVE_TRAITS(Archive, Archive)
|
||||
|
||||
@ -232,10 +237,20 @@ int main()
|
||||
std::cout << cereal::traits::has_member_save_minimal<MemberMinimal, Archive>::value << std::endl;
|
||||
std::cout << cereal::traits::has_member_load_minimal<MemberMinimal, Archive>::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<Base> p = std::make_shared<Derived>();
|
||||
out(x);
|
||||
//out( p );
|
||||
}
|
||||
|
||||
cereal::JSONInputArchive bla(std::cin);
|
||||
long l;
|
||||
bla.loadValue(l);
|
||||
std::cout << dllSS1.str() << std::endl;
|
||||
std::cout << "yo" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,18 +66,20 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)\sandbox_vs_dll;$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)\Debug;E:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\sandbox_vs_dll;$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)\x64\Debug;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)\sandbox_vs_dll;$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)\Release;E:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\sandbox_vs_dll;$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)\x64\Release;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -87,7 +89,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>sandbox_vs_dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -98,6 +100,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>sandbox_vs_dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -112,7 +115,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>sandbox_vs_dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -127,6 +130,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>sandbox_vs_dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "base.hpp"
|
||||
|
||||
CEREAL_CLASS_VERSION(VersionTest, 1)
|
||||
CEREAL_REGISTER_SHARED_LIBRARY(Sandbox)
|
||||
template void Base::serialize<cereal::XMLOutputArchive>
|
||||
( cereal::XMLOutputArchive & ar, std::uint32_t const version );
|
||||
template void Base::serialize<cereal::XMLInputArchive>
|
||||
|
@ -11,6 +11,17 @@
|
||||
#define DECLSPECIFIER __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
int doit();
|
||||
|
||||
class VersionTest
|
||||
{
|
||||
public:
|
||||
int x;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, const std::uint32_t /* version */ )
|
||||
{ ar( x ); }
|
||||
};
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "derived.hpp"
|
||||
|
||||
//CEREAL_REGISTER_TYPE(Derived)
|
||||
CEREAL_REGISTER_TYPE(Derived)
|
||||
|
||||
template void Derived::serialize<cereal::XMLOutputArchive>
|
||||
( cereal::XMLOutputArchive & ar, std::uint32_t const version );
|
||||
|
@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
VisualStudioVersion = 12.0.30324.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sandbox_vs", "sandbox_vs\sandbox_vs.vcxproj", "{A67E36D2-32BE-4D4D-BA2E-8FD59378E734}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{95D6662F-4166-40D2-87D7-CABFB60C199A} = {95D6662F-4166-40D2-87D7-CABFB60C199A}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sandbox_json", "sandbox_json\sandbox_json.vcxproj", "{52E96EC3-125A-4525-BC72-F3C524F24640}"
|
||||
EndProject
|
||||
|
Loading…
x
Reference in New Issue
Block a user