コード例 #1
0
// Converts a SyntaxNode tree to a Moses::GHKM::ParseTree.
std::auto_ptr<ParseTree> XmlTreeParser::ConvertTree(
    const SyntaxNode &tree,
    const std::vector<std::string> &words)
{
  std::auto_ptr<ParseTree> root(new ParseTree(tree.GetLabel()));
  const std::vector<SyntaxNode*> &children = tree.GetChildren();
  if (children.empty()) {
    if (tree.GetStart() != tree.GetEnd()) {
      std::ostringstream msg;
      msg << "leaf node covers multiple words (" << tree.GetStart()
          << "-" << tree.GetEnd() << "): this is currently unsupported";
      throw Exception(msg.str());
    }
    std::auto_ptr<ParseTree> leaf(new ParseTree(words[tree.GetStart()]));
    leaf->SetParent(root.get());
    root->AddChild(leaf.release());
  } else {
    for (std::vector<SyntaxNode*>::const_iterator p = children.begin();
         p != children.end(); ++p) {
      assert(*p);
      std::auto_ptr<ParseTree> child = ConvertTree(**p, words);
      child->SetParent(root.get());
      root->AddChild(child.release());
    }
  }
  return root;
}
コード例 #2
0
std::auto_ptr<ParseTree> XmlTreeParser::Parse(const std::string &line)
{
  m_line = line;
  m_tree.Clear();
  try {
    if (!ProcessAndStripXMLTags(m_line, m_tree, m_labelSet, m_topLabelSet)) {
      throw Exception("");
    }
  } catch (const XmlException &e) {
    throw Exception(e.getMsg());
  }
  m_tree.ConnectNodes();
  SyntaxNode *root = m_tree.GetTop();
  assert(root);
  m_words = tokenize(m_line.c_str());
  return ConvertTree(*root, m_words);
}
コード例 #3
0
bool cQuake3BSPFile::LoadMap(std::string filename)
/////////////////////////////////////////////////////////////////////////////////////
{
	m_file = cFileManager::Singleton()->OpenFile(filename);
	sHeader header;
	
	cPlane *planes;
	sNode *nodes;
	int numNodes;

	sLeaf *leaves;
	int numLeaves;

	// Check if the file was loaded correctly
	if (!m_file)
	{
		LOG()->Print ("Couldn't open Q3 Map file %s.", filename.c_str());	
		return false;
	}

	// Read in the header
	m_file->Read (&header, sizeof(sHeader));

	// Check the type of file
	if (header.magic != MAGIC_NUMBER || header.version != Q3BSP_VERSION)
	{
		LOG()->Print ("Invalid Q3 Map file %s.", filename.c_str());
		cFileManager::Singleton()->CloseFile (m_file);

		return false;
	}

	// Load in the vertex lump
	m_numVertex = GetNumber(sizeof(cVertex), header.directory[q3VERTECIES]);
	m_vertex = (cVertex*)(LoadLump (header.directory[q3VERTECIES]));

	// Load in the face lump
	m_numFace = GetNumber (sizeof(sFace), header.directory[q3FACES]);
	m_face = (sFace*)(LoadLump (header.directory[q3FACES]));
	
	m_drawn = new bool[m_numFace];

	// Load in the model lump
	m_numModel = GetNumber (sizeof(sModel), header.directory[q3MODELS]);
	m_model = (sModel*)(LoadLump (header.directory[q3MODELS]));

	// Load mesh vert lump
	m_numMeshVert = GetNumber (sizeof(sMeshVert), header.directory[q3MESHVERTS]);
	m_meshVert = (sMeshVert*)(LoadLump (header.directory[q3MESHVERTS]));

	// Load plane lump
	planes = (cPlane *)(LoadLump (header.directory[q3PLANES]));

	// Load node lump
	numNodes = GetNumber (sizeof(sNode), header.directory[q3NODES]);
	nodes = (sNode *)(LoadLump(header.directory[q3NODES]));

	// Load leaf lump
	numLeaves = GetNumber (sizeof(sLeaf), header.directory[q3LEAVES]);
	leaves = (sLeaf *)(LoadLump(header.directory[q3LEAVES]));

	// Load leafface
	m_numLeafFace = GetNumber (sizeof(int), header.directory[q3LEAFFACES]);
	m_leafFace = (int *)(LoadLump(header.directory[q3LEAFFACES]));
    
	// Convert the tree to our format
	ConvertTree (nodes, numNodes, planes, leaves, numLeaves);

	cFileManager::Singleton()->CloseFile (m_file);

	delete[] (void*)nodes;
	delete[] (void*)planes;
	delete[] (void*)leaves;
	return true;
}