serialize_shared_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 00025 #ifndef __SSRC_WSPR_UTILITY_SERIALIZE_SHARED_PTR_H 00026 #define __SSRC_WSPR_UTILITY_SERIALIZE_SHARED_PTR_H 00027 00028 #include <ssrc/wispers-packages.h> 00029 00030 #include <boost/mpl/integral_c.hpp> 00031 #include <boost/mpl/integral_c_tag.hpp> 00032 00033 #include <boost/shared_ptr.hpp> 00034 #include <boost/serialization/split_free.hpp> 00035 #include <boost/serialization/nvp.hpp> 00036 #include <boost/serialization/version.hpp> 00037 00038 namespace boost { 00039 namespace serialization { 00040 00041 template<typename T> 00042 struct version<boost::shared_ptr<T> > { 00043 typedef boost::mpl::integral_c_tag tag; 00044 typedef boost::mpl::int_<1> type; 00045 BOOST_STATIC_CONSTANT(int, value = type::value); 00046 }; 00047 00048 template<class T> 00049 struct tracking_level<boost::shared_ptr<T> > { 00050 typedef boost::mpl::integral_c_tag tag; 00051 typedef mpl::int_<boost::serialization::track_never> type; 00052 BOOST_STATIC_CONSTANT(int, value = type::value); 00053 }; 00054 00055 template<class Archive, class T> 00056 inline void save(Archive & ar, const boost::shared_ptr<T> & value, 00057 const unsigned int /*version*/) 00058 { 00059 const T *v = value.get(); 00060 ar << boost::serialization::make_nvp("px", v); 00061 } 00062 00063 template<class Archive, class T> 00064 inline void load(Archive & ar, boost::shared_ptr<T> & value, 00065 const unsigned int /*version*/) 00066 { 00067 T *v = 0; 00068 ar >> boost::serialization::make_nvp("px", v); 00069 00070 if(v == 0) { 00071 value.reset(); 00072 } else { 00073 value.reset(v); 00074 } 00075 } 00076 00077 template<class Archive, class T> 00078 inline void serialize(Archive & ar, boost::shared_ptr<T> & value, 00079 const unsigned int version) 00080 { 00081 boost::serialization::split_free(ar, value, version); 00082 } 00083 } 00084 } 00085 00086 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.