Here is a c++ header file I found somewhere else.
#include "opencv\cv.h"
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
BOOST_SERIALIZATION_SPLIT_FREE(cv::Mat)
namespace boost {
namespace serialization {
/** Serialization support for cv::Mat */
template <class Archive>
void save(Archive & ar, const ::cv::Mat& m, const unsigned int version)
{
size_t elem_size = m.elemSize();
size_t elem_type = m.type();
ar & m.cols;
ar & m.rows;
ar & elem_size;
ar & elem_type;
const size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
};
}
My question is: What does the following code mean?
BOOST_SERIALIZATION_SPLIT_FREE(cv::Mat)
Is it a macro definition? Then where is the pound sign "#"?
In short words, it's a macro . BOOST_SERIALIZATION_SPLIT_FREE(my_class)
is the macro, which is short for the following free serialize function template:
namespace boost { namespace serialization {
template<class Archive>
inline void serialize(
Archive & ar,
my_class & t,
const unsigned int file_version
){
split_free(ar, t, file_version);
}
}}
Also note that BOOST_SERIALIZATION_SPLIT_FREE
must be used outside of any namespace. Check out here for further info.
宏,用于将序列化函数拆分为保存和加载函数
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.