// SaveData.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
class BaseOperator;
class findLineOperator;
BOOST_CLASS_EXPORT(BaseOperator)
BOOST_CLASS_EXPORT(findLineOperator)
using namespace std;
class BaseNode
{
public:
virtual void print();
std::string a="this is BaseNode a";
std::string b="this is BaseNode b";
//为使当前的结构能支持序列化,得加入下面的代码段
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & a;
ar & b;
}
};
class BaseOperator :public BaseNode
{
public:
std::string c = "this is BaseOperator c";
std::string d = "this is BaseOperator d";
virtual void print();
//为使当前的结构能支持序列化,得加入下面的代码段
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<BaseNode>(*this);
ar & c;
ar & d;
}
};
class findLineOperator :public BaseOperator {
public:
int id=4;
std::string strName="me";
std::string strValue="you";
virtual void print();
findLineOperator() {}
findLineOperator(int id, std::string strName, std::string strValue)
{
this->id = id;
this->strName = strName;
this->strValue = strValue;
}
};
void BaseNode::print()
{
}
void BaseOperator::print()
{
}
void findLineOperator::print()
{
}
class ToolBlock
{
public:
std::vector<BaseNode*> listMR;
};
int main(int argc, _TCHAR* argv[])
{
std::stringstream ss;
//序列化
//findLineOperator p1(11, "anderson", "neo"); //被序列化的对象
ToolBlock *tool = new ToolBlock();
BaseOperator *mr = new findLineOperator(99,"eric","lili");
BaseOperator *mr2=new findLineOperator;
std::vector<void*> listMR;
//压入对象
tool->listMR.push_back(mr);
tool->listMR.push_back(mr2);
return 0;
}