Savarese Software Research Corporation
serialize_unique_ptr.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 Savarese Software Research Corporation
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     https://www.savarese.com/software/ApacheLicense-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00024 #ifndef __SSRC_WSPR_UTILITY_SERIALIZE_UNIQUE_PTR_H
00025 #define __SSRC_WSPR_UTILITY_SERIALIZE_UNIQUE_PTR_H
00026 
00027 #include <ssrc/wispers-packages.h>
00028 
00029 #include <memory>
00030 
00031 #include <boost/serialization/split_free.hpp>
00032 #include <boost/serialization/nvp.hpp>
00033 
00034 namespace boost {
00035   namespace serialization {
00036     template<class Archive, class T>
00037     inline void save(Archive & ar, const SSRC_UNIQUE_PTR<T> & value,
00038                      const unsigned int /*version*/)
00039     {
00040       const T *v = value.get();
00041       ar << boost::serialization::make_nvp("px", v);
00042     }
00043 
00044     template<class Archive, class T>
00045     inline void load(Archive & ar, SSRC_UNIQUE_PTR<T> & value,
00046                      const unsigned int /*version*/)
00047     {
00048       T *v = 0;
00049       ar >> boost::serialization::make_nvp("px", v);
00050 
00051       if(v == 0) {
00052         value.reset();
00053       } else {
00054         value.reset(v);
00055       }
00056     }
00057 
00058     template<class Archive, class T>
00059     inline void serialize(Archive & ar, SSRC_UNIQUE_PTR<T> & value,
00060                           const unsigned int version)
00061     {
00062       boost::serialization::split_free(ar, value, version);
00063     }
00064   }
00065 }
00066 
00067 #endif

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.