Ivan Mahonin ae9154
Ivan Mahonin ae9154
Ivan Mahonin ae9154
#include <tmetaimage.h>
Ivan Mahonin ae9154
Ivan Mahonin ae9154
Ivan Mahonin ae9154
//---------------------------------------------------------
Ivan Mahonin ae9154
Ivan Mahonin 4da757
TMetaObjectType::TMetaObjectType(const TStringId &name): name(name)
Ivan Mahonin 4da757
  { registerAlias(name); }
Ivan Mahonin 4da757
Ivan Mahonin 4da757
TMetaObjectType::~TMetaObjectType() {
Ivan Mahonin 4da757
  // TMetaObject::unregisterType(*this);
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObjectType::registerAlias(const TStringId &alias)
Ivan Mahonin 4da757
  { TMetaObject::registerType(alias, *this); }
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObjectType::unregisterAlias(const TStringId &alias) {
Ivan Mahonin 4da757
  TMetaObject::Registry::const_iterator i = TMetaObject::getRegistry().find(alias);
Ivan Mahonin 4da757
  if (i == TMetaObject::getRegistry().end() || i->second != this) {
Ivan Mahonin 4da757
    std::cerr << "warning: trying to unregister not-registered alias (" << alias.str()
Ivan Mahonin 4da757
              << ") of type of TMetaObject (" << name.str() << ") " << name.str() << std::endl;
Ivan Mahonin 4da757
  } else {
Ivan Mahonin 4da757
    TMetaObject::unregisterType(alias);
Ivan Mahonin 4da757
  }
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
//---------------------------------------------------------
Ivan Mahonin 4da757
Ivan Mahonin 57d357
TMetaObject::TMetaObject(const TMetaObject &other):
Ivan Mahonin 4da757
  m_typeLink(linkedMap().end()),
Ivan Mahonin 4da757
  m_previous(),
Ivan Mahonin 4da757
  m_next(),
Ivan Mahonin 4da757
  m_typeDesc(),
Ivan Mahonin ae9154
  m_handler(),
Ivan Mahonin 57d357
  m_data(*this, other.data())
Ivan Mahonin 4da757
    { linkToType(TStringId()); setType(other.getType()); }
Ivan Mahonin 57d357
Ivan Mahonin 57d357
TMetaObject::TMetaObject(const TStringId &typeName, const TVariant &data):
Ivan Mahonin 4da757
  m_typeLink(linkedMap().end()),
Ivan Mahonin 4da757
  m_previous(),
Ivan Mahonin 4da757
  m_next(),
Ivan Mahonin 4da757
  m_typeDesc(),
Ivan Mahonin 57d357
  m_handler(),
Ivan Mahonin 57d357
  m_data(*this, data)
Ivan Mahonin 4da757
    { linkToType(TStringId()); setType(typeName); }
Ivan Mahonin ae9154
Ivan Mahonin 57d357
TMetaObject::TMetaObject(const std::string &typeName, const TVariant &data):
Ivan Mahonin 4da757
  m_typeLink(linkedMap().end()),
Ivan Mahonin 4da757
  m_previous(),
Ivan Mahonin 4da757
  m_next(),
Ivan Mahonin 4da757
  m_typeDesc(),
Ivan Mahonin ae9154
  m_handler(),
Ivan Mahonin 57d357
  m_data(*this, data)
Ivan Mahonin 4da757
    { linkToType(TStringId()); setType(typeName); }
Ivan Mahonin ae9154
Ivan Mahonin ae9154
TMetaObject::~TMetaObject()
Ivan Mahonin 4da757
  { resetType(); unlinkFromType(); }
Ivan Mahonin ae9154
Ivan Mahonin 4da757
TMetaObject::LinkedMap&
Ivan Mahonin 4da757
TMetaObject::linkedMap()
Ivan Mahonin 4da757
  { static LinkedMap linkedMap; return linkedMap; }
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObject::linkToType(const TStringId &type) {
Ivan Mahonin 4da757
  m_typeLink = linkedMap().insert( LinkedMap::value_type(type, LinkedList()) ).first;
Ivan Mahonin 4da757
  m_previous = m_typeLink->second.last;
Ivan Mahonin 4da757
  m_next = 0;
Ivan Mahonin 4da757
  (m_previous ? m_previous->m_next : m_typeLink->second.first) = this;
Ivan Mahonin 4da757
  m_typeLink->second.last = this;
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObject::unlinkFromType() {
Ivan Mahonin 4da757
  (m_previous ? m_previous->m_next : m_typeLink->second.first) = m_next;
Ivan Mahonin 4da757
  (m_next     ? m_next->m_previous : m_typeLink->second.last ) = m_previous;
Ivan Mahonin 4da757
  m_typeLink = linkedMap().end();
Ivan Mahonin 4da757
  m_previous = m_next = 0;
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObject::rewrap(const TStringId &type) {
Ivan Mahonin 4da757
  const TMetaObjectType *typeDesc = findType(type);
Ivan Mahonin 4da757
  if (typeDesc == m_typeDesc) return;
Ivan Mahonin 4da757
  if (m_handler) delete m_handler;
Ivan Mahonin 4da757
  m_typeDesc = typeDesc;
Ivan Mahonin 4da757
  m_handler  = m_typeDesc ? m_typeDesc->createHandler(*this) : 0;
Ivan Mahonin 4da757
  onVariantChanged(m_data);
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObject::rewrapAll(const TStringId &type) {
Ivan Mahonin 4da757
  LinkedMap::const_iterator it = linkedMap().find(type);
Ivan Mahonin 4da757
  if (it != linkedMap().end())
Ivan Mahonin 4da757
    for(TMetaObject *i = it->second.first; i; i = i->m_next)
Ivan Mahonin 4da757
      i->rewrap(it->first);
Ivan Mahonin 4da757
}
Ivan Mahonin ae9154
Ivan Mahonin ae9154
void
Ivan Mahonin ae9154
TMetaObject::setType(const TStringId &name) {
Ivan Mahonin 4da757
  if (m_typeLink->first != name) {
Ivan Mahonin 4da757
    unlinkFromType();
Ivan Mahonin 4da757
    linkToType(name);
Ivan Mahonin 4da757
    rewrap(name);
Ivan Mahonin ae9154
  }
Ivan Mahonin ae9154
}
Ivan Mahonin ae9154
Ivan Mahonin ae9154
void
Ivan Mahonin ae9154
TMetaObject::onVariantChanged(const TVariant &value)
Ivan Mahonin 9cf8be
  { if (m_handler) m_handler->dataChanged(value); }
Ivan Mahonin ae9154
Ivan Mahonin 57d357
void
Ivan Mahonin 57d357
TMetaObject::setDefaults()
Ivan Mahonin 57d357
  { m_data.reset(); if (m_handler) m_handler->setDefaults(); }
Ivan Mahonin 57d357
Ivan Mahonin 57d357
TMetaObject*
Ivan Mahonin 57d357
TMetaObject::clone() const
Ivan Mahonin 57d357
  { return new TMetaObject(*this); }
Ivan Mahonin 57d357
Ivan Mahonin ae9154
TMetaObject::Registry&
Ivan Mahonin 4da757
TMetaObject::registry()
Ivan Mahonin 4da757
  { static Registry registry; return registry; }
Ivan Mahonin ae9154
Ivan Mahonin ae9154
void
Ivan Mahonin 4da757
TMetaObject::registerType(const TStringId &name, const TMetaObjectType &type) {
Ivan Mahonin 4da757
  if (registry().count(name))
Ivan Mahonin 4da757
    std::cerr << "warning: type of TMetaObject are already registered: " << name.str() << std::endl;
Ivan Mahonin 4da757
  registry()[name] = &type;
Ivan Mahonin 4da757
Ivan Mahonin 4da757
  LinkedMap::const_iterator it = linkedMap().find(name);
Ivan Mahonin 4da757
  if (it != linkedMap().end())
Ivan Mahonin 4da757
    for(TMetaObject *i = it->second.first; i; i = i->m_next)
Ivan Mahonin 4da757
      i->rewrap(name);
Ivan Mahonin 4da757
  rewrapAll(name);
Ivan Mahonin ae9154
}
Ivan Mahonin ae9154
Ivan Mahonin 4da757
void
Ivan Mahonin 4da757
TMetaObject::unregisterType(const TStringId &name) {
Ivan Mahonin 4da757
  if (!registry().count(name))
Ivan Mahonin 4da757
    std::cerr << "warning: trying to unregister non-registered alias of type of TMetaObject: " << name.str() << std::endl;
Ivan Mahonin 4da757
  registry().erase(name);
Ivan Mahonin 4da757
  rewrapAll(name);
Ivan Mahonin 4da757
}
Ivan Mahonin ae9154
Ivan Mahonin ae9154
void
Ivan Mahonin 4da757
TMetaObject::unregisterType(const TMetaObjectType &type) {
Ivan Mahonin 4da757
  Registry &r = registry();
Ivan Mahonin 4da757
  size_t s = r.size();
Ivan Mahonin 4da757
  for(Registry::iterator i = r.begin(); i != r.end();)
Ivan Mahonin 4da757
    if (i->second == &type)
Ivan Mahonin 4da757
      { r.erase(i++); rewrapAll(i->first); } else ++i;
Ivan Mahonin 4da757
  if (s == r.size())
Ivan Mahonin 4da757
    std::cerr << "warning: trying to unregister non-registered type of TMetaObject: " << type.name.str() << std::endl;
Ivan Mahonin 4da757
}
Ivan Mahonin 4da757
Ivan Mahonin 4da757
const TMetaObjectType*
Ivan Mahonin 4da757
TMetaObject::findType(const TStringId &name) {
Ivan Mahonin 4da757
  const Registry &r = getRegistry();
Ivan Mahonin 4da757
  Registry::const_iterator i = r.find(name);
Ivan Mahonin 4da757
  return i == r.end() ? 0 : i->second;
Ivan Mahonin ae9154
}
Ivan Mahonin ae9154
Ivan Mahonin ae9154
//---------------------------------------------------------
Ivan Mahonin ae9154
Ivan Mahonin ae9154
TMetaImage::TMetaImage()
Ivan Mahonin ae9154
  { }
Ivan Mahonin ae9154
Ivan Mahonin 57d357
TMetaImage::TMetaImage(const TMetaImage &other) {
Ivan Mahonin 57d357
  Reader reader(other);
Ivan Mahonin 57d357
  m_objects.reserve(reader->size());
Ivan Mahonin 57d357
  for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i)
Ivan Mahonin 57d357
    if (*i)
Ivan Mahonin 57d357
      m_objects.push_back( TMetaObjectP((*i)->clone()) );
Ivan Mahonin 57d357
}
Ivan Mahonin ae9154
Ivan Mahonin ae9154
TMetaImage::~TMetaImage()
Ivan Mahonin ae9154
  { }
Ivan Mahonin ae9154
Ivan Mahonin ae9154
TImage*
Ivan Mahonin ae9154
TMetaImage::cloneImage() const
Ivan Mahonin ae9154
  { return new TMetaImage(*this); }
Ivan Mahonin ae9154
Ivan Mahonin ae9154
TRectD
Ivan Mahonin ae9154
TMetaImage::getBBox() const
Ivan Mahonin ae9154
  { return TRectD(); }
Ivan Mahonin ae9154
Ivan Mahonin ae9154
//---------------------------------------------------------