Пример #1
0
void touphScript::kernel2::encode(std::string const& kernel2,
  std::string const& textPath)
{

  std::ifstream xml_file{(fs::path{textPath}/"kernel2.bin.xml").string(), xml_file.binary};
  std::string xml{
    std::istreambuf_iterator<char>{xml_file}, 
    std::istreambuf_iterator<char>{}
  };

  rxml::xml_document<> doc;
  doc.parse<rxml::parse_default>(&xml[0]);

  auto root = doc.first_node("kernel2");
  if (!root)
    throw error{"Root node kernel2 not found"};

  auto section = root->first_node("section");

  ff7::kernel2::Strings sections;

  for (auto i = 0u; i < sections.size();
    section = section->next_sibling("section"), ++i) {
    if (!section)
      throw error{"Insufficient section tags in kernel2"};

    for (auto string = section->first_node("string"); string;
      string = string->next_sibling("string"))
      sections[i].push_back(from_xml(string->first_node()));
  }

  auto data = ff7::kernel2::join(sections);

  std::ofstream{kernel2, std::ios::binary}.write(data.data(), data.size());
}
Пример #2
0
void FrameNetBuilder::read_relations(FrameNet &fn){

    rapidxml::file<> fdoc(this->relation_file_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());

    rapidxml::xml_node<>* root = doc.first_node();
    for(auto fr_type = root->first_node("frameRelationType");fr_type!= nullptr;fr_type = fr_type->next_sibling("frameRelationType")){
        std::string fr_type_name = fr_type->first_attribute("name")->value();
        for(auto fr = fr_type->first_node("frameRelation");fr!= nullptr;fr = fr->next_sibling("frameRelation")){
            std::string subFrame = fr->first_attribute("subFrameName")->value();
            std::string superFrame = fr->first_attribute("superFrameName")->value();
            Frame *current_frame = fn.get_frame(subFrame);
            if(fr_type_name == "Causative_of"||fr_type_name == "Inchoative_of"||fr_type_name == "Precedes"){
                current_frame = fn.get_frame(superFrame);
            }

            for(auto fe_r =fr->first_node("FERelation");fe_r!= nullptr;fe_r = fe_r->next_sibling("FERelation")){
                std::string parent = fe_r->first_attribute("superFEName")->value();
                std::string child = fe_r->first_attribute("subFEName")->value();
                FrameElementRelation *fr = new FrameElementRelation(parent,child,fr_type_name,superFrame,subFrame);
                current_frame->add_fe_relation(fr);

            }

        }
    }
}
Пример #3
0
boost::shared_ptr<Action> Root::loadAction(const pugi::xml_node &node) {
    // XXX: This needs to be kept synchronized with the editor
    enum NodeType {
        Empty,
        Speech,
        Emote,
        Sequence,
        Concurrent,
        Conditional,
        Jump,
        EndConversation
    };

    NodeType type = (NodeType)node.attribute("type").as_int();

    switch(type) {
    case Empty:
        Message3(Game, Debug, "Empty action found!");
        return boost::shared_ptr<Action>();
    case Speech:
        /*Message3(Game, Debug, "Speech action found! ["
            << node.attribute("speaker").as_string() << "]: "
            << node.attribute("speech").as_string());*/
        return boost::shared_ptr<Action>();
    case Emote:
        return boost::shared_ptr<Action>();
    case Sequence: {
        auto ret = boost::make_shared<SequenceAction>();

        for(auto n = node.first_child(); n; n = n.next_sibling()) {
            ret->addAction(loadAction(n));
        }
        return ret;
    }
    case Concurrent: {
        auto ret = boost::make_shared<ConcurrentAction>();

        for(auto n = node.first_child(); n; n = n.next_sibling()) {
            ret->addAction(loadAction(n));
        }
        return ret;
    }
    case Conditional:
    case Jump:
    case EndConversation:
        break;
    }

    return boost::shared_ptr<Action>();
}
Пример #4
0
bool Root::loadFrom(std::string name) {
    auto xml =
        Kriti::ResourceRegistry::get<Kriti::XMLResource>("conv/" + name);

    if(!xml) return false;

    auto objects = xml->doc().first_element_by_path("/conversation/objects");

    // First pass to create objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            m_nodeMap[id] = boost::make_shared<Node>();
        }
        else if(!std::strcmp(c.name(), "context")) {
            m_contextMap[id] = boost::make_shared<Context>();
        }
        else if(!std::strcmp(c.name(), "link")) {
            m_linkMap[id] = boost::make_shared<Link>();
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    // Second pass to parse objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            loadNode(id, c);
        }
        else if(!std::strcmp(c.name(), "context")) {
            loadContext(id, c);
        }
        else if(!std::strcmp(c.name(), "link")) {
            loadLink(id, c);
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    if(!m_rootNode) {
        Message3(Game, Error, "Couldn't load conversation \"" << name
            << "\": no root node");
        return false;
    }

    return true;
}
Пример #5
0
LexicalUnit*  FrameNetBuilder::parse_lu_xml(std::string xml_path,LexicalUnit* original){
    rapidxml::file<> fdoc(xml_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());

    rapidxml::xml_node<>* root = doc.first_node();

    std::string name = original->get_name(); //带有词性
    std::string POS = original->get_pos();
    std::string frame_name = original->get_frame_name();
    int ID = original->get_ID();
    std::string status = original->get_status();

    //std::string lexeme = root->first_node("lexeme")->first_attribute("name")->value();
    std::string definition = root->first_node("definition")->value();
    rapidxml::xml_node<>* valence = root->first_node("valences");
    std::vector<FERealization*>fe_realizations;
    for(auto p = valence->first_node("FERealization");p !=  nullptr;p = p->next_sibling("FERealization")){
        fe_realizations.push_back(build_realization(p,frame_name,name));
    }

    std::vector<Annotation*> annotations;
    for(auto subCorpus = root->first_node("subCorpus");subCorpus != nullptr;subCorpus = subCorpus->next_sibling("subCorpus")){
        for(auto senten = subCorpus->first_node("sentence");senten != nullptr; senten = senten->next_sibling("sentence")){
            annotations.push_back(build_annotation(senten));
        }
    }

    original->set_definition(definition);
    original->set_fe_realizations(fe_realizations);
    original->set_annotations(annotations);
    return original;

}
Пример #6
0
std::vector<char> touphScript::flevel::tutorial::encode(std::string const& file)
{
  std::ifstream str{file, str.binary};
  std::string data{
    std::istreambuf_iterator<char>{str}, 
    std::istreambuf_iterator<char>{}
  };

  if (data.empty())
    return {};

  std::vector<std::vector<char>> out;

  rxml::xml_document<> doc;
  doc.parse<rxml::parse_default>(&data[0]);

  auto root = doc.first_node("field");
  if (!root)
    throw error{"Root node field not found"};

  for (auto n = root->first_node("tutorial"); n;
    n = n->next_sibling("tutorial")) {

    auto id = util::xml::ul(util::xml::att(n, "id"));

    if (out.size() < id + 1)
      out.resize(id + 1);

    out[id] = from_xml(n);
  }

  return ff7::flevel::script::tutorial::join(out);
}
Пример #7
0
bool FixPair::readFromRestart() {
    pugi::xml_node restData = getRestartNode();
    //params must be already initialized at this point (in constructor)
    if (restData) {
        auto curr_param = restData.first_child();
        while (curr_param) {
            std::string tag = curr_param.name();
            if (tag == "parameter") {
                std::string paramHandle = curr_param.attribute("handle").value();
                auto it = find(paramOrder.begin(), paramOrder.end(), paramHandle);
                if (it == paramOrder.end()) {
                    std::cout << "Tried to read bad restart data for fix " << handle << ".  Data type " << paramHandle << std::endl;
                }
                mdAssert(it != paramOrder.end(), "Invalid restart data for fix");
                std::vector<float> *params = paramMap[paramHandle];
                ensureParamSize(*params);
                std::vector<float> src = xml_readNums<float>(curr_param);
                assert(params->size() >= src.size());
                for (int i=0; i<src.size(); i++) {
                    (*params)[i] = src[i];
                }
            }
            curr_param = curr_param.next_sibling();
        }

    }
    return true;
    
}
Пример #8
0
void COptions::LoadGlobalDefaultOptions(std::map<std::string, unsigned int> const& nameOptionMap)
{
	CLocalPath const defaultsDir = wxGetApp().GetDefaultsDir();
	if (defaultsDir.empty()) {
		return;
	}
	CXmlFile file(defaultsDir.GetPath() + _T("fzdefaults.xml"));
	if (!file.Load()) {
		return;
	}

	auto element = file.GetElement();
	if (!element) {
		return;
	}

	element = element.child("Settings");
	if (!element) {
		return;
	}

	for (auto setting = element.child("Setting"); setting; setting = setting.next_sibling("Setting")) {
		LoadOptionFromElement(setting, nameOptionMap, true);
	}
}
Пример #9
0
void the::material::deserialize(const pugi::xml_node &node)
{
    unbind();
    setTag(node.attribute("name").value());
    std::istringstream defs(node.attribute("define").value());
    std::string def;
    while(std::getline(defs,def, ';')) defines.push_back(def);

    vertexFile      = node.attribute("vertex").value(); 
    fragmentFile    = node.attribute("fragment").value(); 
    vertexShader    = the::filesystem::load_as_string(aux::dataPath + vertexFile);
    fragmentShader  = the::filesystem::load_as_string(aux::dataPath + fragmentFile);
    if(!node.attribute("texture0").empty()) defTextures[0] = node.attribute("texture0").value();
    if(!node.attribute("texture1").empty()) defTextures[1] = node.attribute("texture1").value();
    if(!node.attribute("texture2").empty()) defTextures[2] = node.attribute("texture2").value();
    if(!node.attribute("texture3").empty()) defTextures[3] = node.attribute("texture3").value();
   
    if(!node.attribute("cubemap0").empty()) defCubemaps[0] = node.attribute("cubemap0").value();
    if(!node.attribute("cubemap1").empty()) defCubemaps[1] = node.attribute("cubemap1").value();
    if(!node.attribute("cubemap2").empty()) defCubemaps[2] = node.attribute("cubemap2").value();
    if(!node.attribute("cubemap3").empty()) defCubemaps[3] = node.attribute("cubemap3").value();
   
    for(auto param = node.child("parameter"); param; param = param.next_sibling("parameter"))
    {    
        const std::string paramName = param.attribute("name").value();
        const std::string paramType = param.attribute("type").value();
        userParameters[paramName] = -1;
        if(paramType=="float") 
            float_param_def[paramName] = param.attribute("val").as_float(); 
        else if(paramType=="vec4")
            vec4_param_def[paramName] = aux::deserialize<vec4>(param);
        else 
            logger::error("Can't parse material parameter type '%s'",paramType.c_str());}       
}
// Build the vector of tiled_object_property's
void tiled_object::build_property_vec( xml_node<>* properties_node )
{
	for ( auto inner_node = properties_node->first_node();
		inner_node;
		inner_node = inner_node->next_sibling() )
	{
		tiled_object_property to_push;
		
		for ( auto attr=inner_node->first_attribute();
			attr;
			attr=attr->next_attribute() )
		{
			if ( attr->name() == string("name") )
			{
				to_push.name = attr->value();
			}
			else if ( attr->name() == string("value") )
			{
				to_push.value = attr->value();
			}
		}
		
		property_vec.push_back(to_push);
	}
	
}
Пример #11
0
	bool XMLFileParser::Read(XMLContainer & container, DirectoryMode mode)
	{
		pugi::xml_document XMLDocument;
		pugi::xml_parse_result result;
		
		SerializedData data;
		data.data = ReadBinaryFile(m_File.GetLocalPath(), data.size, mode);
		result = XMLDocument.load_buffer_inplace_own(data.data, data.size);

		Logger::GetInstance()->Log(result,
			star::string_cast<tstring>(result.description()), STARENGINE_LOG_TAG);
		if (result)
		{
			auto root = XMLDocument.first_child();
			if(root != NULL)
			{
				container.SetName(star::string_cast<tstring>(root.name()));
				AddAttributes(container, root);

				auto child = root.first_child();
				if(child != NULL)
				{
					do 
					{
						AddChild(container, child);
						child = child.next_sibling();
					} while (child != NULL);
				}
			}
		}
		return result;
	}
void ReadServerErrCodeFile(std::map<uint32_t, std::map<ELanguageType, TString> >& languageServerErrCodeMap)
{
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language);
    filePath.append(_T("\\")).append("networkError.xml");
    if (CFilePathTool::GetInstance()->Exists(filePath.c_str()))
    {
        rapidxml::file<> fdoc(filePath.c_str());
        rapidxml::xml_document<> errCodeXML;
        try
        {
            errCodeXML.parse<rapidxml::parse_default>(fdoc.data());
        }
        catch (rapidxml::parse_error err)
        {
            BEATS_ASSERT(false, _T("Load config file %s faled!/n%s/n"), "errno.xml", err.what());
        }
        rapidxml::xml_node<>* pRootElement = errCodeXML.first_node("config");
        if (pRootElement)
        {
            for (auto element = pRootElement->first_node(); element; element = element->next_sibling())
            {
                std::map<ELanguageType, TString> curMap;
                curMap[eLT_Chinese] = element->first_attribute("lang_zhCN")->value();
                curMap[eLT_English] = element->first_attribute("lang_enUS")->value();
                languageServerErrCodeMap[_tstoi(element->first_attribute("code")->value())] = curMap;
            }
        }
    }
}
Пример #13
0
Core ParseCore(const pugi::xml_node &input,
               const std::map<int, UP_Assembly_t> &assemblies)
{
    Core core;
    int n_core_enabled = 0;
    for (auto core_xml = input.child("core"); core_xml;
         core_xml      = core_xml.next_sibling("core")) {
        bool core_enabled = true;
        if (!core_xml.attribute("enabled").empty()) {
            core_enabled = core_xml.attribute("enabled").as_bool();
        }
        if (core_enabled) {
            core = Core(core_xml, assemblies);
            n_core_enabled++;
        }
    }

    if (n_core_enabled == 0) {
        throw EXCEPT("No enabled core specifications.");
    }

    if (n_core_enabled > 1) {
        throw EXCEPT("More than one enabled core specification found. Tell "
                     "me which one to use");
    }

    return core;
}
Пример #14
0
Файл: bp.cpp Проект: rkonow/topk
i64 naive_child(bp *b, i64 s, i64 d)
{
    i64 t,i;
    t = first_child(b,s);
    for (i = 1; i < d; i++) {
        if (t == -1) break;
        t = next_sibling(b,t);
    }
    return t;
}
Пример #15
0
Frame* FrameBuilder::build_frame(std::string xml_path){

    std::vector<FrameElement*>elements;
    std::vector<LexicalUnit*>lexemes;
    std::vector<FrameRelation*>relations;
    std::vector<std::string>parents;
    std::vector<std::string>children;

    //read the frame.xml and analysis
    rapidxml::file<> fdoc(xml_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());
    rapidxml::xml_node<>* root = doc.first_node();
    std::string name = root->first_attribute("name")->value();
    int ID = atoi(root->first_attribute("ID")->value());

    //build FE
    for(auto node = root->first_node("FE");node!= nullptr;node = node->next_sibling("FE")){
        elements.push_back(build_FE(node,name));
    }

    //build LU
    for(auto node = root->first_node("lexUnit");node!= nullptr;node = node->next_sibling("lexUnit")){
        lexemes.push_back(build_LU(node,name));
    }

    //build frameRelation
    for(auto node = root->first_node("frameRelation");node!= nullptr;node = node->next_sibling("frameRelation")){
        relations.push_back(build_FR(node,parents,children));
    }

    //build definition,use regex to filter the html tag
    rapidxml::xml_node<>* def_node = root->first_node("definition");
    std::string xml_text = def_node->value();
    boost::regex expr{"<[^>]*>"};
    std::string fmt{""};
    std::string def_text = boost::regex_replace(xml_text, expr, fmt);

    Frame *frame = new Frame(parents,children,name,elements,lexemes,relations,xml_text,def_text,ID);
    return frame;

}
Пример #16
0
void Root::loadNode(int id, const pugi::xml_node &node) {
    auto n = m_nodeMap[id];

    if(!std::strcmp(node.attribute("entry").as_string(), "true"))
        m_rootNode = n;

    for(auto a = node.first_child(); ; a = a.next_sibling()) {
        auto action = loadAction(a);
        if(a == node.last_child()) break;
    }
}
Пример #17
0
Файл: bp.cpp Проект: rkonow/topk
i64 naive_degree(bp *b, i64 s)
{
    i64 t,d;
    d = 0;
    t = first_child(b,s);
    while (t >= 0) {
        d++;
        t = next_sibling(b,t);
    }
    return d;
}
tiled_objectgroup::tiled_objectgroup( xml_node<>* node )
{
	// find the name attribute
	for ( auto attr=node->first_attribute();
		attr;
		attr=attr->next_attribute() )
	{
		if ( attr->name() == string("name") )
		{
			name = attr->value();
			
			// I don't know why I don't include a break statement after
			// finding the name attribute.
		}
	}
	
	// Loop through all the internal nodes within the current objectgroup
	// for the purpose of building object_vec.
	for ( auto object_node=node->first_node();
		object_node;
		object_node=object_node->next_sibling() )
	{
		tiled_object to_push;
		
		// Build to_push using the attributes of object_node.
		for ( auto attr=object_node->first_attribute();
			attr;
			attr=attr->next_attribute() )
		{
			stringstream attr_sstm;
			
			attr_sstm << attr->value();
			
			if ( attr->name() == string("id") )
			{
				attr_sstm >> to_push.id;
			}
			else if ( attr->name() == string("gid") )
			{
				attr_sstm >> to_push.gid_raw;
				
				// Tiled stores hflip and vflip within an object's gid
				// parameter.
				to_push.gid = to_push.gid_raw & 0x3fffffff;
				to_push.vflip = to_push.gid_raw & 0x40000000;
				to_push.hflip = to_push.gid_raw & 0x80000000;
				
				// subtract the gid by 1
				if ( to_push.gid > 0 )
				{
					--to_push.gid;
				}
			}
Пример #19
0
   std::map<std::string, std::string> Tilemap::get_attributes(xml_node parent, const std::string& child) const
   {
      std::map<std::string, std::string> attrs;

      for (auto node = parent.child(child.c_str()); node; node = node.next_sibling(child.c_str()))
      {
         const char *name = node.attribute("name").value();
         const char *value = node.attribute("value").value();
         attrs.insert({name, value});
      }

      return attrs;
   }
Пример #20
0
   Tilemap::Tilemap(const std::string& path) : dir(Utils::basedir(path))
   {
      xml_document doc;
      if (!doc.load_file(path.c_str()))
         throw std::runtime_error(Utils::join("Failed to load XML map: ", path, "."));

      xml_node map   = doc.child("map");
      width      = map.attribute("width").as_int();
      height     = map.attribute("height").as_int();
      tilewidth  = map.attribute("tilewidth").as_int();
      tileheight = map.attribute("tileheight").as_int();

      if (!width || !height || !tilewidth || !tileheight)
         throw std::logic_error("Tilemap is malformed.");

      std::map<unsigned, Surface> tiles;
      for (auto set = map.child("tileset"); set; set = set.next_sibling("tileset"))
         add_tileset(tiles, set);

      for (auto layer = map.child("layer"); layer; layer = layer.next_sibling("layer"))
         add_layer(tiles, layer, tilewidth, tileheight);
   }
Пример #21
0
void COptions::LoadOptions(std::map<std::string, unsigned int> const& nameOptionMap, pugi::xml_node settings)
{
	if (!settings) {
		settings = CreateSettingsXmlElement();
		if (!settings) {
			return;
		}
	}

	for (auto setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) {
		LoadOptionFromElement(setting, nameOptionMap, false);
	}
}
Пример #22
0
void XMLSettingsMap::remove(const std::string &key)
{
    for (auto cur = node->first_child(); cur; cur = cur->next_sibling())
    {
        if (!cur->is_element())
            continue;

        if (cur->attribute("key") == key)
        {
            node->remove_child(cur);
            break;
        }
    }
}
Пример #23
0
FrameRelation* FrameBuilder::build_FR(rapidxml::xml_node<>*node,std::vector<std::string>&parents,std::vector<std::string>&children){
    std::string relation_type = node->first_attribute("type")->value();
    std::vector<std::string> related_frames;
    for(auto child = node->first_node("relatedFrame");child!= nullptr;child = child->next_sibling("relatedFrame")){
        std::string r_frame_name = child->value();
        related_frames.push_back(r_frame_name);
        if(relation_type=="Inherits from"){
            parents.push_back(r_frame_name);
        }
        if(relation_type=="Is Inherited by"){
            children.push_back(r_frame_name);
        }
    }
    return new FrameRelation(relation_type,related_frames);
}
Пример #24
0
FrameElement* FrameBuilder::build_FE(rapidxml::xml_node<>*node,std::string frame_name){
    std::string name = node->first_attribute("name")->value();
    std::string abbrev = node->first_attribute("abbrev")->value();
    std::string coreType = node->first_attribute("coreType")->value();
    int ID = atoi(node->first_attribute("ID")->value());
    std::string xml_definition = node->first_node("definition")->value();
    boost::regex expr{"<[^>]*>"};
    std::string fmt{""};
    std::string def_text = boost::regex_replace(xml_definition, expr, fmt);

    FrameElement *element = new FrameElement(name,abbrev,coreType,frame_name,ID,def_text);

    //set semType
    auto p=node->first_node("semType");
    if(p!= nullptr){
        std::string name = p->first_attribute("name")->value();
        int ID = atoi(p->first_attribute("ID")->value());
        SemType *s = new SemType(name,ID);
        element->set_semtype(s);
    }

    //set excludesFEs
    for(auto p=node->first_node("excludesFE");p!= nullptr;p = p->next_sibling("excludesFEs")){
        std::string name = p->first_attribute("name")->value();
        element->add_excludes(name);
    }

    //set requiresFEs
    for(auto p=node->first_node("requiresFE");p!= nullptr;p = p->next_sibling("requiresFEs")){
        std::string name = p->first_attribute("name")->value();
        element->add_requires(name);
    }


    return  element;
}
Пример #25
0
XMLSettings XMLSettingsMap::get(const std::string &key)
{
    for (auto cur = node->first_child(); cur; cur = cur->next_sibling())
    {
        if (!cur->is_element())
            continue;

        if (cur->attribute("key") == key)
            return XMLSettings(document, cur);
    }

    auto cur = node->owner_document()->create_element("item");
    cur->set_attribute("key", key);
    node->append_child(cur);
    return XMLSettings(document, cur);
}
Пример #26
0
    bool BilibiliParser::ParseXml(const char* data, bool inplace) {
        if (mDanmakus.get() == nullptr)
            return false;

        char* buffer = nullptr;
        std::unique_ptr<char[]> raii_buffer;

        if (inplace) {
            buffer = const_cast<char*>(data);
        } else {
            size_t buffer_size = strlen(data) + 1;
            buffer = new char[buffer_size];
            raii_buffer = std::move(std::unique_ptr<char[]>(buffer));
            memset(buffer, 0, buffer_size);
            strcpy_s(buffer, buffer_size, data);
        }

        xml_document<> doc;
        doc.parse<0>(buffer);

        xml_node<char>* root = doc.first_node("i");
        if (root == nullptr)
            return false;

        for (auto node = root->first_node("d"); node != nullptr; node = node->next_sibling()) {
            const char* attr = node->first_attribute("p")->value();
            std::vector<std::string> attributes;
            attributes.reserve(8);
            SplitString(attr, ',', attributes);

            if (attributes.size() >= 8) {
                time_t time = static_cast<time_t>(std::stod(attributes[0]) * 1000);
                DanmakuType type = static_cast<DanmakuType>(std::stoi(attributes[1]));
                int textSize = static_cast<int>(std::stof(attributes[2]));
                int textColor = std::stoi(attributes[3]) | 0xFF000000;
                time_t timestamp = std::stoull(attributes[4]);
                int danmakuId = std::stoi(attributes[7]);
                std::wstring comment = UTF8ToWideString(node->value());

                DanmakuRef danmaku = DanmakuFactory::CreateDanmaku(type, time, comment, textSize, textColor, timestamp, danmakuId);
                if (danmaku != nullptr) {
                    mDanmakus->push_back(danmaku);
                }
            }
        }
        return true;
    }
Пример #27
0
void
usf_reader_c::parse_subtitles(mtx::xml::document_cptr &doc) {
  for (auto subtitles = doc->document_element().child("subtitles"); subtitles; subtitles = subtitles.next_sibling("subtitles")) {
    auto track = std::make_shared<usf_track_t>();
    m_tracks.push_back(track);

    auto attribute = subtitles.child("language").attribute("code");
    if (attribute && !std::string{attribute.value()}.empty()) {
      int index = map_to_iso639_2_code(attribute.value());
      if (-1 != index)
        track->m_language = iso639_languages[index].iso639_2_code;
      else if (!g_identifying)
        mxwarn_tid(m_ti.m_fname, m_tracks.size() - 1, boost::format(Y("The language code '%1%' is not a valid ISO639-2 language code and will be ignored.\n")) % attribute.value());
    }

    for (auto subtitle = subtitles.child("subtitle"); subtitle; subtitle = subtitle.next_sibling("subtitle")) {
      usf_entry_t entry;
      int64_t duration = -1;

      attribute = subtitle.attribute("start");
      if (attribute)
        entry.m_start = try_to_parse_timecode(attribute.value());

      attribute = subtitle.attribute("stop");
      if (attribute)
        entry.m_end = try_to_parse_timecode(attribute.value());

      attribute = subtitle.attribute("duration");
      if (attribute)
        duration = try_to_parse_timecode(attribute.value());

      if ((-1 == entry.m_end) && (-1 != entry.m_start) && (-1 != duration))
        entry.m_end = entry.m_start + duration;

      std::stringstream out;
      for (auto node : subtitle)
        node.print(out, "", pugi::format_default | pugi::format_raw);
      entry.m_text = out.str();

      track->m_entries.push_back(entry);
    }
  }
}
	void TiledMapLoader::loadTilesets(Map &map, rapidxml::xml_node<> &rootNode) {
		auto tilesetNode = rootNode.first_node("tileset");
		char *tilesetSource = nullptr;
		auto tilesetId = 0;
		if (!tilesetNode) {
			throw std::logic_error("Invalid tiled map: no tileset tag");
		}
		while (tilesetNode) {
			XMLElement tilesetElement(*tilesetNode);
			tilesetSource = tilesetElement.getString("source", nullptr);

			if (tilesetSource) {
				loadExternalTileset(map, tilesetId, tilesetSource, tilesetElement.getInt("firstgid"));
			} else {
				addTileset(map, tilesetId, *tilesetNode);
			}
			tilesetNode = tilesetNode->next_sibling("tileset");
			++tilesetId;
		}
	}
Пример #29
0
	void XMLFileParser::AddChild(XMLContainer & parent, const pugi::xml_node & node)
	{
		std::shared_ptr<XMLContainer> child(new XMLContainer());
		AddAttributes(*(child.get()), node);
		child->SetName(star::string_cast<tstring>(node.name()));
		child->SetValue(star::string_cast<tstring>(node.child_value()));
		auto sibling = node.first_child();
		if(sibling != NULL)
		{
			do 
			{
				AddChild(*(child.get()), sibling);
				sibling = sibling.next_sibling();
			} while (sibling != NULL);
		}
		if(child->GetName() != EMPTY_STRING)
		{
			parent.insert(std::make_pair(star::string_cast<tstring>(node.name()), child));
		}
	}
Пример #30
0
Annotation* FrameNetBuilder::build_annotation(rapidxml::xml_node<>* senten){

    std::string text = senten->first_node("text")->value();
    for(auto annoset = senten->first_node("annotationSet");annoset != nullptr;annoset = annoset->next_sibling("annotationSet")){
        std::string status = annoset->first_attribute("status")->value();
        if(status == "MANUAL"||status == "AUTO_EDITED"){
            int ID = atoi(annoset->first_attribute("ID")->value());
            std::vector<Label> labels;

            for(auto layer = annoset->first_node("layer");layer != nullptr;layer = layer->next_sibling("layer")){
                std::string ly_name = layer->first_attribute("name")->value();

                if(ly_name == "FE"){
                    for(auto label = layer->first_node("label");label != nullptr;label = label->next_sibling("label")){
                        auto attr = label->first_attribute("start");
                        if(attr!= nullptr){
                            int start = std::stoi(label->first_attribute("start")->value());
                            int end = std::stoi(label->first_attribute("end")->value());
                            std::string fe_name = label->first_attribute("name")->value();
                            int fe_ID = std::stoi(label->first_attribute("feID")->value());
                            labels.push_back({start,end,fe_name,fe_ID});
                        }
                    }
                }
                if(ly_name == "Target"){
                    for(auto label = layer->first_node("label");label != nullptr;label = label->next_sibling("label")){
                        int start = std::stoi(label->first_attribute("start")->value());
                        int end = std::stoi(label->first_attribute("end")->value());
                        std::string fe_name =text.substr(start,end-start+1);
                        int fe_ID = -1;
                        labels.push_back({start,end,fe_name,fe_ID});
                    }
                }
            }
            Annotation *annotation = new Annotation(text,ID,status,labels);
            return annotation;
        }
    }
}