|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.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 |
|
|
Shinya Kitaoka |
120a6e |
TPersistSet::~TPersistSet() {
|
|
otakuto |
675691 |
std::for_each(m_objects.begin(), m_objects.end(), std::default_delete<tpersist>());</tpersist>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
2a7129 |
void TPersistSet::insert(std::unique_ptr<tpersist> object) {</tpersist>
|
|
otakuto |
91a93e |
auto const sameType = [&object](TPersist *x) {
|
|
otakuto |
91a93e |
return typeid(*object.get()) == typeid(*x);
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Remove any object with the same type id
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpersist *="">::iterator pt =</tpersist>
|
|
otakuto |
91a93e |
std::remove_if(m_objects.begin(), m_objects.end(), sameType);
|
|
Shinya Kitaoka |
120a6e |
|
|
otakuto |
675691 |
std::for_each(pt, m_objects.end(), std::default_delete<tpersist>());</tpersist>
|
|
Shinya Kitaoka |
120a6e |
m_objects.erase(pt, m_objects.end());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Push back the supplied object
|
|
Shinya Kitaoka |
120a6e |
m_objects.push_back(object.release());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPersistSet::saveData(TOStream &os) {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpersist *="">::iterator pt, pEnd = m_objects.end();</tpersist>
|
|
Shinya Kitaoka |
120a6e |
for (pt = m_objects.begin(); pt != pEnd; ++pt) os << *pt;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TPersistSet::loadData(TIStream &is) {
|
|
Shinya Kitaoka |
120a6e |
while (!is.eos()) {
|
|
Shinya Kitaoka |
120a6e |
TPersist *object = 0;
|
|
Shinya Kitaoka |
120a6e |
is >> object;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_objects.push_back(object);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|