Exemplo n.º 1
0
bool TParam::parseTree(std::istream &is, std::stack<int> &indentation)
{
  // read newline separated parameter file
  if (is.eof())
    return true;
  std::string line;
  getline(is, line);
  std::size_t pos = line.find_first_not_of(' ');
  if (pos == std::string::npos || line[pos] == '#')
    return parseTree(is, indentation);
  assert(line[pos] != '\t');
  std::istringstream linestream(line);
  std::string pName;
  linestream >> pName;
  assert(!linestream.fail());

  // find parent depending on indentation and adapt indentation
  TParam *pParent = this;
  while ((int)pos <= indentation.top()) {
    pParent = pParent->parent;
    indentation.pop();
  }

  // read parameter
  Variant pValue;
  std::string t = pValue.tryRead(linestream);
  if (pValue.getType() == Invalid) {
    if (!t.empty() && t[0] != '#')
      std::cerr << "Warning: Unknown type '" << t << "' of parameter '" << pName << "'. Parsing as category.\n";
    indentation.push(pos); // no leaf node
  }
  TParam p(pName, pValue);
  pParent->addChild(p);
  if (p.getType() == Invalid)
    return pParent->children.find(p.name)->second->parseTree(is, indentation);
  return pParent->parseTree(is, indentation);
}