Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tnotanimatableparam.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TIntParam, "intParam")
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TBoolParam, "boolParam")
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TFilePathParam, "filePathParam")
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TStringParam, "stringParam")
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TNADoubleParam, "naDoubleParam")
Shinya Kitaoka 120a6e
// PERSIST_IDENTIFIER(TIntEnumParam, "intEnumParam")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPersistDeclarationT<tenumparam> TEnumParam::m_declaration("intEnumParam");</tenumparam>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TIntParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  int def, value;
Shinya Kitaoka 120a6e
  is >> def;
Shinya Kitaoka 120a6e
  if (is.eos()) {
Shinya Kitaoka 120a6e
    def += 1;
Shinya Kitaoka 120a6e
    setDefaultValue(def);
Shinya Kitaoka 120a6e
    setValue(def, false);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setDefaultValue(def);
Shinya Kitaoka 120a6e
  is >> value;
Shinya Kitaoka 120a6e
  setValue(value, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TIntParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << getDefaultValue();
Shinya Kitaoka 120a6e
  os << getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TIntParam::isWheelEnabled() const { return m_isWheelEnabled; }
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TIntParam::enableWheel(bool on) { m_isWheelEnabled = on; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBoolParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  int def, value;
Shinya Kitaoka 120a6e
  is >> def >> value;
Shinya Kitaoka 120a6e
  setDefaultValue(def ? true : false);
Shinya Kitaoka 120a6e
  setValue(value ? true : false, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBoolParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << (int)getDefaultValue() << (int)getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFilePathParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  TFilePath def, value;
Shinya Kitaoka 120a6e
  is >> def >> value;
Shinya Kitaoka 120a6e
  setDefaultValue(def);
Shinya Kitaoka 120a6e
  setValue(value, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFilePathParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << getDefaultValue();
Shinya Kitaoka 120a6e
  os << getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Shinya Kitaoka 120a6e
void TStringParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::wstring def, value;
Shinya Kitaoka 120a6e
  is >> def >> value;
Shinya Kitaoka 120a6e
  setDefaultValue(def);
Shinya Kitaoka 120a6e
  setValue(value, false);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void TStringParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << getDefaultValue();
Shinya Kitaoka 120a6e
  os << getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//=========================================================
Shinya Kitaoka 120a6e
void TNADoubleParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  double def, value;
Shinya Kitaoka 120a6e
  is >> def >> value;
Shinya Kitaoka 120a6e
  setDefaultValue(def);
Shinya Kitaoka 120a6e
  setValue(value, false);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void TNADoubleParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << getDefaultValue();
Shinya Kitaoka 120a6e
  os << getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Shinya Kitaoka 120a6e
class matchesValue {
Shinya Kitaoka 120a6e
  T m_v;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  matchesValue(T v) : m_v(v) {}
Shinya Kitaoka 120a6e
  bool operator()(const std::pair<t, std::string=""> &p) { return m_v == p.first; }</t,>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TEnumParamImp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  std::vector<std::pair<int, std::string="">> m_items;</std::pair<int,>
Shinya Kitaoka 120a6e
  void copy(std::unique_ptr<tenumparamimp> &src) {</tenumparamimp>
Shinya Kitaoka 120a6e
    m_items.clear();
Shinya Kitaoka 120a6e
    std::back_insert_iterator<std::vector<std::pair<int, std::string="">>> bii(</std::vector<std::pair<int,>
Shinya Kitaoka 120a6e
        m_items);
Shinya Kitaoka 120a6e
    std::copy(src->m_items.begin(), src->m_items.end(), bii);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  bool checkValue(int v) {
Shinya Kitaoka 120a6e
    std::vector<std::pair<int, std::string="">>::iterator it =</std::pair<int,>
Shinya Kitaoka 120a6e
        std::find_if(m_items.begin(), m_items.end(), matchesValue<int>(v));</int>
Shinya Kitaoka 120a6e
    return it != m_items.end();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TEnumParam::TEnumParam(const int &v, const std::string &caption)
Shinya Kitaoka 120a6e
    : TNotAnimatableParam<int>(v), m_imp(new TEnumParamImp()) {</int>
Shinya Kitaoka 120a6e
  addItem(v, caption);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::copy(TParam *src) {
Shinya Kitaoka 120a6e
  TNotAnimatableParam<int>::copy(src);</int>
Shinya Kitaoka 120a6e
  TEnumParam *p = dynamic_cast<tenumparam *="">(src);</tenumparam>
Shinya Kitaoka 120a6e
  if (!p) throw TException("invalid source for copy");
Shinya Kitaoka 120a6e
  TEnumParam::setName(src->getName());
Shinya Kitaoka 120a6e
  m_imp->copy(p->m_imp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TEnumParam::~TEnumParam() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnumParam::TEnumParam(const TEnumParam &src)
Shinya Kitaoka 120a6e
    : TNotAnimatableParam<int>(src), m_imp(new TEnumParamImp(*src.m_imp)) {}</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnumParam::TEnumParam()
Shinya Kitaoka 120a6e
    : TNotAnimatableParam<int>()</int>
Shinya Kitaoka 120a6e
    , m_imp(new TEnumParamImp())
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
{}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::setValue(int v, bool undoing) {
Shinya Kitaoka 120a6e
  bool valid = false;
Shinya Kitaoka 120a6e
  std::vector<std::pair<int, std::string="">>::iterator it =</std::pair<int,>
Shinya Kitaoka 120a6e
      m_imp->m_items.begin();
Shinya Kitaoka 120a6e
  for (; it != m_imp->m_items.end(); ++it) {
Shinya Kitaoka 120a6e
    if (it->first == v) {
Shinya Kitaoka 120a6e
      valid = true;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!valid) throw TException("out of range parameter value");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TNotAnimatableParam<int>::setValue(v, undoing);</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::setValue(const std::string &caption, bool undoing) {
Shinya Kitaoka 120a6e
  bool valid = false;
Shinya Kitaoka 120a6e
  int v      = 0;
Shinya Kitaoka 120a6e
  std::vector<std::pair<int, std::string="">>::iterator it =</std::pair<int,>
Shinya Kitaoka 120a6e
      m_imp->m_items.begin();
Shinya Kitaoka 120a6e
  for (; it != m_imp->m_items.end(); ++it) {
Shinya Kitaoka 120a6e
    if (it->second == caption) {
Shinya Kitaoka 120a6e
      v     = it->first;
Shinya Kitaoka 120a6e
      valid = true;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!valid) throw TException("out of range parameter value");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TNotAnimatableParam<int>::setValue(v, undoing);</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::addItem(const int &item, const std::string &caption) {
Shinya Kitaoka 120a6e
  m_imp->m_items.push_back(std::make_pair(item, caption));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TEnumParam::getItemCount() const { return m_imp->m_items.size(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::getItem(int i, int &item, std::string &caption) const {
Shinya Kitaoka 120a6e
  assert(i >= 0 && i < m_imp->m_items.size());
Shinya Kitaoka 120a6e
  item    = m_imp->m_items[i].first;
Shinya Kitaoka 120a6e
  caption = m_imp->m_items[i].second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  int value;
Shinya Kitaoka 120a6e
  is >> value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    setValue(value, false);
Shinya Kitaoka 120a6e
  } catch (TException &) {
Shinya Kitaoka 120a6e
    TNotAnimatableParam<int>::reset();</int>
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TEnumParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << TNotAnimatableParam<int>::getValue();</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TIntParam::setValueRange(int min, int max) {
Shinya Kitaoka 120a6e
  assert(min < max);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  minValue = min;
Shinya Kitaoka 120a6e
  maxValue = max;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TIntParam::getValueRange(int &min, int &max) const {
Shinya Kitaoka 120a6e
  min = minValue;
Shinya Kitaoka 120a6e
  max = maxValue;
Shinya Kitaoka 120a6e
  return min < max;
Toshihiro Shimizu 890ddd
}