// singleton.cpp : 定义控制台应用程序的入口点。
//BOOST实现单体的两种方式
//1.通过boost的pool的singleton实现
//2.通过boost的serialization的singleton实现,采用继承或则定义一个单体类型
//而且serilization模块的单体类具备锁功能。
#include "stdafx.h"
#include <boost/pool/singleton_pool.hpp>
#include <boost/serialization/singleton.hpp>
#define SGOBJ(e, type)\
void set##e(const type& t) {e = t;};\
type get##e() const {return e;};
class PointManager : public boost::serialization::singleton<PointManager>
{
public:
SGOBJ(x, int);
SGOBJ(y, int);
SGOBJ(z, int);
private:
int x,y,z;
};
int _tmain(int argc, _TCHAR* argv[])
{
PointManager & pm = PointManager::get_mutable_instance();
assert(pm.is_locked() == false);
pm.lock();
assert(pm.is_locked() == true);
pm.unlock();
assert(pm.is_locked() == false);
return 0;
}