Logo Search packages:      
Sourcecode: scummvm version File versions  Download package

bool Common::XMLParser::parseActiveKey ( bool  closed  )  [protected]

Called once a key has been parsed. It handles the closing/cleanup of the node stack and calls the keyCallback.

Definition at line 145 of file xmlparser.cpp.

References _activeKey, Common::XMLParser::XMLKeyLayout::children, closeKey(), Common::HashMap< Key, Val, HashFunc, EqualFunc >::contains(), getParentNode(), keyCallback(), Common::XMLParser::ParserNode::layout, parserError(), and Common::HashMap< Key, Val, HashFunc, EqualFunc >::size().

Referenced by parse().

                                          {
      bool ignore = false;
      assert(_activeKey.empty() == false);

      ParserNode *key = _activeKey.top();

      if (key->name == "xml" && key->header == true) {
            assert(closed);
            return parseXMLHeader(key) && closeKey();
      }

      XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;

      if (layout->children.contains(key->name)) {
            key->layout = layout->children[key->name];

            Common::StringMap localMap = key->values;
            int keyCount = localMap.size();

            for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
                  if (i->required && !localMap.contains(i->name))
                        return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str());
                  else if (localMap.contains(i->name))
                        keyCount--;
            }

            if (keyCount > 0)
                  return parserError("Unhandled property inside key '%s'.", key->name.c_str());

      } else {
            return parserError("Unexpected key in the active scope ('%s').", key->name.c_str());
      }

      // check if any of the parents must be ignored.
      // if a parent is ignored, all children are too.
      for (int i = _activeKey.size() - 1; i >= 0; --i) {
            if (_activeKey[i]->ignore)
                  ignore = true;
      }

      if (ignore == false && keyCallback(key) == false) {
            // HACK:  People may be stupid and overlook the fact that
            // when keyCallback() fails, a parserError() must be set.
            // We set it manually in that case.
            if (_state != kParserError)
                  parserError("Unhandled exception when parsing '%s' key.", key->name.c_str());

            return false;
      }

      if (closed)
            return closeKey();

      return true;
}


Generated by  Doxygen 1.6.0   Back to index