Ejemplo n.º 1
0
bool TParam::addChild(const TParam &n)
{
  if (n.name.empty()) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Empty names are not allowed\n";
    return false;
  }
  if (n.name.find(" ") != std::string::npos) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": White spaces in names are not allowed. Got '" << n.name << "'.\n";
    return false;
  }
  if (n.name.find("/") != std::string::npos) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Slashes '/' in names are not allowed. Got '" << n.name << "'.\n";
    return false;
  }
  if (getTypeByName(n.name) != Invalid) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Names of Variant Types are not allowed. Got '" << n.name << "'.\n";
    return false;
  }
  if (getType() != Invalid) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Trying to add a child to leaf node.\n";
    return false;
  }
  if (children.count(n.name) > 0) {
    if (children[n.name]->getType() != n.getType()) {
      std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Trying to replace Param " << n.name << " of type " << children[n.name]->getTypeName() << " by type " << n.getTypeName() << "\n";
      return false;
    }

    delete children[n.name];
  }

  children[n.name] = new TParam(n);
  children[n.name]->parent = this;
  return true;
}
Ejemplo n.º 2
0
bool TParam::update(const TParam &other)
{
  if (name != other.name) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Trying to update Param " << name << " with " << other.name << ".\n";
    return false;
  }
  if (getType() != other.getType()) {
    std::cerr << "Error in " << __PRETTY_FUNCTION__ << ": Trying to update Param " << name << " of type " << getTypeName() << " with type " << other.getTypeName() << ".\n";
    return false;
  }
  Variant::operator=(other);
  for (std::map<std::string, TParam*>::const_iterator it = other.children.begin();
      it != other.children.end(); it++) {
    if (children.count(it->first) > 0) {
      if (!children[it->first]->update(*it->second))
        return false;
    } else {
      if (!addChild(*it->second))
        return false;
    }
  }
  return true;
}