Branch data Line data Source code
1 : : /*
2 : : * Copyright 2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * https://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines serialization functions for SSRC_UNIQUE_PTR,
20 : : * which may be std::auto_ptr or std::unique_ptr depending on the
21 : : * compilation environment.
22 : : */
23 : :
24 : : #ifndef __SSRC_WSPR_UTILITY_SERIALIZE_UNIQUE_PTR_H
25 : : #define __SSRC_WSPR_UTILITY_SERIALIZE_UNIQUE_PTR_H
26 : :
27 : : #include <ssrc/wispers-packages.h>
28 : :
29 : : #include <memory>
30 : :
31 : : #include <boost/serialization/split_free.hpp>
32 : : #include <boost/serialization/nvp.hpp>
33 : :
34 : : namespace boost {
35 : : namespace serialization {
36 : : template<class Archive, class T>
37 : 2 : inline void save(Archive & ar, const SSRC_UNIQUE_PTR<T> & value,
38 : : const unsigned int /*version*/)
39 : : {
40 : 2 : const T *v = value.get();
41 : 2 : ar << boost::serialization::make_nvp("px", v);
42 : 2 : }
43 : :
44 : : template<class Archive, class T>
45 : 2 : inline void load(Archive & ar, SSRC_UNIQUE_PTR<T> & value,
46 : : const unsigned int /*version*/)
47 : : {
48 : 2 : T *v = 0;
49 : 2 : ar >> boost::serialization::make_nvp("px", v);
50 : :
51 [ + + ]: 2 : if(v == 0) {
52 : 1 : value.reset();
53 : : } else {
54 : 1 : value.reset(v);
55 : : }
56 : 2 : }
57 : :
58 : : template<class Archive, class T>
59 : 4 : inline void serialize(Archive & ar, SSRC_UNIQUE_PTR<T> & value,
60 : : const unsigned int version)
61 : : {
62 : 4 : boost::serialization::split_free(ar, value, version);
63 : 4 : }
64 : : }
65 : : }
66 : :
67 : : #endif
|