int
Dictionary::get_document_index (ustring dictionaryname)
{
    DocMap::iterator dm = m_document_map.find(dictionaryname);
    int dindex;
    if (dm == m_document_map.end()) {
        dindex = m_documents.size();
        m_document_map[dictionaryname] = dindex;
        pugi::xml_document *doc = new pugi::xml_document;
        m_documents.push_back (doc);
        pugi::xml_parse_result parse_result;
        if (boost::ends_with (dictionaryname.string(), ".xml")) {
            // xml file -- read it
            parse_result = doc->load_file (dictionaryname.c_str());
        } else {
            // load xml directly from the string
            parse_result = doc->load_buffer (dictionaryname.c_str(),
                                             dictionaryname.length());
        }
        if (! parse_result) {
            m_context->error ("XML parsed with errors: %s, at offset %d",
                              parse_result.description(),
                              parse_result.offset);
            m_document_map[dictionaryname] = -1;
            return -1;
        }
    } else {
        dindex = dm->second;
    }

    DASSERT (dindex < (int)m_documents.size());
    return dindex;
}
Пример #2
0
 Document::UP read(DocumentIdT lid, const document::DocumentTypeRepo &) const override {
     DocMap::const_iterator itr = _docs.find(lid);
     if (itr != _docs.end()) {
         Document::UP retval(itr->second->clone());
         return retval;
     }
     return Document::UP();
 }
Doc* DocSet::findOrMakeDoc(const std::string& doc) {
  DocMap::iterator it = docMap_.find(doc);
  if (it != docMap_.end()) {
    return it->second;
  }

  Doc* newDoc = new Doc(NULL);
  docMap_[doc] = newDoc;
  return newDoc;
}