Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg/tcg_deleter_types.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_function_types.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <typeinfo></typeinfo>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tpersistset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
//    TPersistSet  implementation
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TPersistSet, "persistSet")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPersistSet::~TPersistSet()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::for_each(m_objects.begin(), m_objects.end(),
Toshihiro Shimizu 890ddd
				  tcg::deleter<tpersist>());</tpersist>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TPersistSet::insert(std::auto_ptr<tpersist> object)</tpersist>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	struct locals {
Toshihiro Shimizu 890ddd
		inline static bool sameType(TPersist *a, TPersist *b)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			return (typeid(*a) == typeid(*b));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Remove any object with the same type id
Toshihiro Shimizu 890ddd
	std::vector<tpersist *="">::iterator pt = std::remove_if(</tpersist>
Toshihiro Shimizu 890ddd
		m_objects.begin(), m_objects.end(),
Toshihiro Shimizu 890ddd
		tcg::bind1st(&locals::sameType, object.get()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::for_each(pt, m_objects.end(), tcg::deleter<tpersist>());</tpersist>
Toshihiro Shimizu 890ddd
	m_objects.erase(pt, m_objects.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Push back the supplied object
Toshihiro Shimizu 890ddd
	m_objects.push_back(object.release());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TPersistSet::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::vector<tpersist *="">::iterator pt, pEnd = m_objects.end();</tpersist>
Toshihiro Shimizu 890ddd
	for (pt = m_objects.begin(); pt != pEnd; ++pt)
Toshihiro Shimizu 890ddd
		os << *pt;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TPersistSet::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	while (!is.eos()) {
Toshihiro Shimizu 890ddd
		TPersist *object = 0;
Toshihiro Shimizu 890ddd
		is >> object;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_objects.push_back(object);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}