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_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
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>
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    inline static bool sameType(TPersist *a, TPersist *b) {
Shinya Kitaoka 120a6e
      return (typeid(*a) == typeid(*b));
Shinya Kitaoka 120a6e
    }
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>
Shinya Kitaoka 120a6e
      std::remove_if(m_objects.begin(), m_objects.end(),
Shinya Kitaoka 120a6e
                     tcg::bind1st(&locals::sameType, object.get()));
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
}