Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tparamcontainer.h"
Toshihiro Shimizu 890ddd
//#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tparam.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamVar::setParamObserver(TParamObserver *obs) {
Shinya Kitaoka 120a6e
  if (m_paramObserver == obs) return;
Shinya Kitaoka 120a6e
  TParam *param = getParam();
Shinya Kitaoka 120a6e
  if (param) {
Shinya Kitaoka 120a6e
    if (obs) param->addObserver(obs);
Shinya Kitaoka 120a6e
    if (m_paramObserver) param->removeObserver(m_paramObserver);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_paramObserver = obs;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TParamContainer::Imp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  std::map<std::string, *="" tparamvar=""> m_nameTable;</std::string,>
Shinya Kitaoka 120a6e
  std::vector<tparamvar *=""> m_vars;</tparamvar>
Shinya Kitaoka 120a6e
  TParamObserver *m_paramObserver;
Shinya Kitaoka 120a6e
  Imp() : m_paramObserver(0) {}
Shinya Kitaoka 120a6e
  ~Imp() { clearPointerContainer(m_vars); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParamContainer::TParamContainer() : m_imp(new Imp()) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParamContainer::~TParamContainer() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamContainer::setParamObserver(TParamObserver *observer) {
Shinya Kitaoka 120a6e
  m_imp->m_paramObserver = observer;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParamObserver *TParamContainer::getParamObserver() const {
Shinya Kitaoka 120a6e
  return m_imp->m_paramObserver;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamContainer::add(TParamVar *var) {
Shinya Kitaoka 120a6e
  m_imp->m_vars.push_back(var);
Shinya Kitaoka 120a6e
  m_imp->m_nameTable[var->getName()] = var;
Shinya Kitaoka 120a6e
  var->setParamObserver(m_imp->m_paramObserver);
Shinya Kitaoka 120a6e
  var->getParam()->setName(var->getName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TParamContainer::getParamCount() const { return m_imp->m_vars.size(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParam *TParamContainer::getParam(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return m_imp->m_vars[index]->getParam();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TParamContainer::isParamHidden(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return m_imp->m_vars[index]->isHidden();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TParamContainer::getParamName(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return m_imp->m_vars[index]->getName();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TParamVar *TParamContainer::getParamVar(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return m_imp->m_vars[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParam *TParamContainer::getParam(std::string name) const {
shun-iwasawa 9d0856
  TParamVar *var = getParamVar(name);
shun-iwasawa 9d0856
  return (var) ? var->getParam() : 0;
shun-iwasawa 9d0856
}
shun-iwasawa 9d0856
shun-iwasawa 9d0856
TParamVar *TParamContainer::getParamVar(std::string name) const {
Shinya Kitaoka 120a6e
  std::map<std::string, *="" tparamvar="">::const_iterator it;</std::string,>
Shinya Kitaoka 120a6e
  it = m_imp->m_nameTable.find(name);
Shinya Kitaoka 120a6e
  if (it == m_imp->m_nameTable.end())
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  else
shun-iwasawa 9d0856
    return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamContainer::unlink() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < getParamCount(); i++) {
Shinya Kitaoka 120a6e
    // TRangeParam *p0;//,*p1;
Shinya Kitaoka 120a6e
    TParamVar *var = m_imp->m_vars[i];
Shinya Kitaoka 120a6e
    TParam *param  = var->getParam();
Shinya Kitaoka 120a6e
    // p0 = dynamic_cast<trangeparam *="">(param);</trangeparam>
Shinya Kitaoka 120a6e
    var->setParam(param->clone());
Shinya Kitaoka 120a6e
    /*p1 = dynamic_cast<trangeparam *="">(var->getParam());</trangeparam>
Shinya Kitaoka 120a6e
if(p0 && p1)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
string name = p0->getName();
Shinya Kitaoka 120a6e
name = p1->getName();
Shinya Kitaoka 120a6e
}*/
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamContainer::link(const TParamContainer *src) {
Shinya Kitaoka 120a6e
  assert(getParamCount() == src->getParamCount());
Shinya Kitaoka 120a6e
  for (int i = 0; i < getParamCount(); i++) {
Shinya Kitaoka 120a6e
    assert(getParamName(i) == src->getParamName(i));
Shinya Kitaoka 120a6e
    assert(m_imp->m_vars[i]->getName() == getParamName(i));
Shinya Kitaoka 120a6e
    m_imp->m_vars[i]->setParam(src->getParam(i));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TParamContainer::copy(const TParamContainer *src) {
Shinya Kitaoka 120a6e
  assert(getParamCount() == src->getParamCount());
Shinya Kitaoka 120a6e
  for (int i = 0; i < getParamCount(); i++) {
Shinya Kitaoka 120a6e
    assert(getParamName(i) == src->getParamName(i));
Shinya Kitaoka 120a6e
    assert(m_imp->m_vars[i]->getName() == getParamName(i));
Shinya Kitaoka 120a6e
    getParam(i)->copy(src->getParam(i));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}