NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

FgSharedPtrSerialization.h
1#pragma once
2
3#pragma once
4
5#include <boost/archive/binary_oarchive.hpp>
6#include <boost/archive/binary_iarchive.hpp>
7#include <boost/archive/xml_iarchive.hpp>
8#include <boost/archive/xml_oarchive.hpp>
9#include <boost/serialization/nvp.hpp>
10#include <boost/serialization/split_free.hpp>
11#include <boost/unordered_map.hpp>
12
13 namespace boost
14{
15 namespace serialization
16 {
17 template<class Archive, class Type>
18 void save(Archive& archive, const std::shared_ptr<Type>& value, const unsigned int /*version*/)
19 {
20 Type* data = value.get();
21 archive << data;
22 }
23
24 template<class Archive, class Type>
25 void load(Archive& archive, std::shared_ptr<Type>& value, const unsigned int /*version*/)
26 {
27 Type* data;
28 archive >> data;
29
30 typedef std::weak_ptr<Type> WeakPtr;
31 static boost::unordered_map<void*, WeakPtr> hash;
32
33 if (hash[data].expired())
34 {
35 value = std::shared_ptr<Type>(data);
36 hash[data] = value;
37 }
38 else value = hash[data].lock();
39 }
40
41 template<class Archive, class Type>
42 inline void serialize(Archive& archive, std::shared_ptr<Type>& value, const unsigned int version)
43 {
44 split_free(archive, value, version);
45 }
46 }
47}