예제 #1
0
	void EmmaParser::parseContainer(EmmaDoc &doc, pugi::xml_node containerNode)
	{
		std::string containerName = containerNode.name();

		if(containerName == "emma:interpretation")
		{
			doc.setContainerType("interpretation");
			parseInterpretation(doc, containerNode);
		}
		else if(containerName == "emma:sequence")
		{
			doc.setContainerType("sequence");
			for (pugi::xml_node interpretation = containerNode.first_child(); interpretation; interpretation = interpretation.next_sibling())
			{
				parseInterpretation(doc, interpretation);
			}
		}
		else if(containerName == "emma:one-of")
		{
			doc.setContainerType("one-of");

			for (pugi::xml_node interpretation = containerNode.first_child(); interpretation; interpretation = interpretation.next_sibling())
			{
				parseInterpretation(doc, interpretation);
			}
		}
        doc.sortInputs();
	}
예제 #2
0
	void EmmaParser::parseInterpretation(EmmaDoc &doc, pugi::xml_node interpretationNode)
	{
		

		std::string id = interpretationNode.attribute("id").value();
		std::string medium = interpretationNode.attribute("emma:medium").value();
		std::string mode = interpretationNode.attribute("emma:mode").value();
        std::string start = interpretationNode.attribute("emma:start").value();
		std::string end = interpretationNode.attribute("emma:end").value();
		std::string confidence = interpretationNode.attribute("emma:confidence").value();

		double numericConfidence = 0;
        double numericStart = 0;
        double numericEnd = 0;
        
		if(confidence == "") //No confidence value was provided for input, assuming max confidence
			numericConfidence = 1;
		else
			numericConfidence = atof(confidence.c_str()); //CAREFUL: NOT CHECKING IF THIS STRING IS ACTUALLY A DOUBLE
        
		if(start != "") //Start value was provided for input
			numericStart = atof(start.c_str()); //CAREFUL: NOT CHECKING IF THIS STRING IS ACTUALLY A DOUBLE
        
		if(end != "") //End value was provided for input
			numericEnd = atof(end.c_str()); //CAREFUL: NOT CHECKING IF THIS STRING IS ACTUALLY A DOUBLE

		std::string inputEventTokens = "";

		std::string noInput = interpretationNode.attribute("emma:no-input").value();
		std::string uninterpretedInput = interpretationNode.attribute("emma:uninterpreted").value();

		
		if((noInput == "true") || (uninterpretedInput == "true"))
			numericConfidence = 0;
		else
		{
			//Fetching the tokens from the literal element (if it exists)
			//pugi::xml_node interpretationChild = interpretationNode.first_child();

			std::string interpretationChildName = interpretationNode.first_child().name();

			if(interpretationChildName == "emma:literal")
			{
				inputEventTokens = interpretationNode.first_child().child_value();
			}
            else if(interpretationChildName == "x" )//&& interpretationNode.first_child().next_sibling().name() == "y")
            {
                std::stringstream tokens;
                tokens << interpretationNode.first_child().child_value() << "," << interpretationNode.first_child().next_sibling().child_value();
                inputEventTokens = tokens.str();
            }
		}

		InputEvent input(id, medium, mode, numericStart, numericEnd, numericConfidence, inputEventTokens);
		doc.addInputEvent(input);
    
	}
예제 #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
 void buildTextures(ogl::CShape* const& pShape, const pugi::xml_node& _textures)
 {
   ogl::CTgaTextureBuilder* pTgaTextureBuilder = new ogl::CTgaTextureBuilder;
 
   for(pugi::xml_node _texture = _textures.first_child(); _texture; _texture = _texture.next_sibling())
   {
     pugi::xml_attribute _scope = _texture.attribute("scope");
     pugi::xml_attribute _src   = _texture.attribute("src");
     if(!_scope || !_src)
       throw EXCEPTION << "<texture scope=\"?\" src=\"?\"> attributes are mandatory!";
     
     pTgaTextureBuilder->setFile(_src.value());
     
     if(strncmp(_scope.value(), "diffuse", 7) == 0)
     {
       pShape->getMaterial()->setTexture(ogl::CTexture::EScope::DIFFUSE, pTgaTextureBuilder->build());
     }
     else if(strncmp(_scope.value(), "normals", 7) == 0)
     {
       pShape->getMaterial()->setTexture(ogl::CTexture::EScope::NORMALS, pTgaTextureBuilder->build());
     }
     else if(strncmp(_scope.value(), "height", 5) == 0)
     {
       pShape->getMaterial()->setTexture(ogl::CTexture::EScope::HEIGHT, pTgaTextureBuilder->build());
     }
     else
     {
       throw EXCEPTION << "<texture scope=\"" << _scope.value() << "\" > Not supported!";
     }
   }
   
   _DELETE(pTgaTextureBuilder);
 }
예제 #5
0
static pugi::xml_node findSimilarNode(pugi::xml_node searchNode, pugi::xml_node searchRoot, unsigned maxDistance)
{
  std::string searchNodeName = searchNode.name();
  pugi::xml_node match;

  // Examine children of searchRoot that have matching names to searchNode
  unsigned i = 0;
  pugi::xml_node child = searchRoot.first_child();
  for (; child && i < maxDistance && !match; child = child.next_sibling(), i++) {
    // Ignore nodes with non-matching names
    if (searchNodeName != child.name())
      continue;

    // Assume child is a match, until shown otherwise
    match = child;

    // Check that all attributes of searchNode match the child node's attributes
    for (pugi::xml_attribute attr : searchNode.attributes()) {
      std::string searchNodeAttr = attr.value();
      std::string matchAttr = child.attribute(attr.name()).value();
      if (searchNodeAttr != matchAttr) {
        match = pugi::xml_node();
        break;
      }
    }
  }

  return match;
}
예제 #6
0
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode)
{
  // Base case = both nodes are text nodes
  pugi::xml_text fromNodeText = fromNode.text();
  pugi::xml_text toNodeText = toNode.text();
  if (fromNodeText && toNodeText) {
    SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl;
    toNodeText.set(fromNodeText.get());
    return;
  }

  // Calculate number of children in toNode
  unsigned maxDistance = std::distance(toNode.begin(), toNode.end());

  // Merge children
  for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) {
    // Find appropriate merge point
    pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance);
    if (toNodeChild) {
      mergeNodes(toNodeChild, fromNodeChild);
    } else {
      toNode.append_copy(fromNodeChild);
    }
  }

  // Erase fromNode
  removeNode(fromNode);
}
void XCScheme::parseBuildAction(const pugi::xml_node& node, const ErrorReporter& reporter)
{
  // Get the BuildableReference node
  BuildRef br;
  const pugi::xml_node brNode = node.first_child();
  
  // Get the product name
  getXMLProperty(brNode, "BuildableName", br.productName, VALUE_REQUIRED, reporter);
  
  // Get the target name
  getXMLProperty(brNode, "BlueprintName", br.targetName, VALUE_REQUIRED, reporter);
  
  // Get the container (project) for the target
  getXMLProperty(brNode, "ReferencedContainer", br.container, VALUE_REQUIRED, reporter);
  br.container = br.container.substr(10);
  
  // Get target id
  getXMLProperty(brNode, "BlueprintIdentifier", br.id, VALUE_REQUIRED, reporter);
  
  // Check that all fields were read
  if (br.productName.empty() || br.targetName.empty() ||
      br.container.empty() || br.id.empty()) {
    reporter.reportError("BuildableReference is incomplete.");
    return;
  }

  // Get the value of buildForArchiving
  String shouldArchive;
  getXMLProperty(node, "buildForArchiving", shouldArchive, VALUE_REQUIRED, reporter);
  if (shouldArchive == "YES") {
    m_targets.push_back(br);
  } else {
    SBLog::info() << "Ignoring BuildableReference to \"" << br.targetName << "\" target because it is not archivable." << std::endl;
  }
}
예제 #8
0
파일: XMLFile.cpp 프로젝트: 03050903/Urho3D
void XMLFile::AddAttribute(const pugi::xml_node& patch, const pugi::xpath_node& original) const
{
    pugi::xml_attribute attribute = patch.attribute("type");

    if (!patch.first_child() && patch.first_child().type() != pugi::node_pcdata)
    {
        URHO3D_LOGERRORF("XML Patch failed calling Add due to attempting to add non text to an attribute for %s.", attribute.value());
        return;
    }

    String name(attribute.value());
    name = name.Substring(1);

    pugi::xml_attribute newAttribute = original.node().append_attribute(name.CString());
    newAttribute.set_value(patch.child_value());
}
예제 #9
0
void RainbowTable::print_entry(pugi::xml_node &entry) {
    //prints all data associated with node entry

    cout << endl;//redability

    //print attributes of entry node
    for (pugi::xml_attribute attr = entry.first_attribute();
            attr;
            attr = attr.next_attribute()) {

        if (strcmp("key" , attr.name()) != 0 ) { //ignore key
            cout << attr.name() << ": " << attr.value() << endl;
        }
    }

    //search through child nodes
    for (pugi::xml_node child = entry.first_child();
            child;
            child = child.next_sibling()) {

        cout  << child.name() << endl;

        //is there text outside of the attrubutes?
        if (child.text()) {
            cout << '\t'  << child.first_child().value() << endl;
        }

        //print attributes of child
        for (pugi::xml_attribute attr = child.first_attribute();
                attr;
                attr = attr.next_attribute()) {
            cout << '\t' << attr.name() << ": " << attr.value() << endl;
        }
    }
}
예제 #10
0
void CUserProfile::ParseBackpacks(pugi::xml_node& xmlItem)
{
	// enter into items list
	xmlItem = xmlItem.first_child();
	while(!xmlItem.empty())
	{
		uint32_t CharID  = xmlItem.attribute("CharID").as_uint();
		r3d_assert(CharID);
		
		bool found = true;
		for(int i=0; i<ProfileData.NumSlots; i++) 
		{
			if(ProfileData.ArmorySlots[i].LoadoutID == CharID) 
			{
				parseCharBackpack(xmlItem, ProfileData.ArmorySlots[i]);
				found = true;
				break;
			}
		}
		
		if(!found)
			r3dError("bad backpack data for charid %d", CharID);

		xmlItem = xmlItem.next_sibling();
	}
}
예제 #11
0
void TwXmlDocument::makeChildren(pugi::xml_node& elem, TwXmlElement* parent)
{
    pugi::xml_node childElem = elem.first_child();
    while (childElem)
    {
        if (childElem.type() == pugi::node_element)
        {
            TwXmlElement* child = new TwXmlElement(childElem.name());

            child->setText(childElem.text().get());

            pugi::xml_attribute attr = childElem.first_attribute();
            while (attr)
            {
                child->setAttribute(attr.name(), attr.value());
                attr = attr.next_attribute();
            }

            parent->addChild(child);
            makeChildren(childElem, child);
        }

        childElem = childElem.next_sibling();
    }
}
예제 #12
0
    void read_xml_node( pugi::xml_node node, Ptree &pt, int flags)
    {
        typedef typename Ptree::key_type::value_type Ch;

        switch ( node.type() )
        {
            case pugi::node_element:
                {
                    Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second;
                    for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() )
                        tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value());
                    for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling())
                        read_xml_node(child, tmp, flags);
                }
                break;
            case pugi::node_pcdata:
                {
                    if (flags & no_concat_text)
                        pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() )));
                    else
                        pt.data() += node.value();
                }
                break;
            case pugi::node_comment:
                {
                    if (!(flags & no_comments))
                        pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() )));
                }
                break;
            default:
                // skip other types
                break;
        }
    }
예제 #13
0
파일: patent.cpp 프로젝트: fhieber/cdec
/*
 * reads in sentences within the <s></s> tags and adds each sentence,
 * converted into a WordID vector.
 */
void Patent::loadText(const pugi::xml_node& node) {
	for (pugi::xml_node s = node.first_child(); s; s = s.next_sibling()) {
		std::vector<WordID> ids;
		TD::ConvertSentence(s.text().as_string(), &ids);
		text.push_back(ids);
	}
}
예제 #14
0
void Monsters::loadLootContainer(const pugi::xml_node& node, LootBlock& lBlock)
{
	for (pugi::xml_node subNode = node.first_child(); subNode; subNode = subNode.next_sibling()) {
		LootBlock lootBlock;
		if (loadLootItem(subNode, lootBlock)) {
			lBlock.childLoot.push_back(lootBlock);
		}
	}
}
예제 #15
0
파일: SMenu.cpp 프로젝트: 3rdexp/soui
void SMenu::BuildMenu( HMENU menuPopup,pugi::xml_node xmlNode )
{
    pugi::xml_node xmlItem=xmlNode.first_child();

    while(xmlItem)
    {
        if(wcscmp(L"item",xmlItem.name())==0)
        {
            SMenuItemData *pdmmi=new SMenuItemData;
            pdmmi->hMenu=menuPopup;
            pdmmi->itemInfo.iIcon=xmlItem.attribute(L"icon").as_int(-1);
            SStringW strText = xmlItem.text().get();
            strText.TrimBlank();
            InitMenuItemData(pdmmi->itemInfo,strText);

            int nID=xmlItem.attribute(L"id").as_int(0);
            BOOL bCheck=xmlItem.attribute(L"check").as_bool(false);
            BOOL bRadio=xmlItem.attribute(L"radio").as_bool(false);
            BOOL bDisable=xmlItem.attribute(L"disable").as_bool(false);


            pugi::xml_writer_buff writer;
            xmlItem.print(writer,L"\t",pugi::format_default,pugi::encoding_utf16);
            SStringW str(writer.buffer(),writer.size());

            pugi::xml_node xmlChild=xmlItem.first_child();
            while(xmlChild && xmlChild.type()==pugi::node_pcdata) xmlChild=xmlChild.next_sibling();


            if(!xmlChild)
            {
                pdmmi->nID=nID;
                UINT uFlag=MF_OWNERDRAW;
                if(bCheck) uFlag|=MF_CHECKED;
                if(bDisable) uFlag |= MF_GRAYED;
                if(bRadio) uFlag |= MFT_RADIOCHECK|MF_CHECKED;
                AppendMenu(menuPopup,uFlag,(UINT_PTR)pdmmi->nID,(LPCTSTR)pdmmi);
            }
            else
            {
                HMENU hSubMenu=::CreatePopupMenu();
                pdmmi->nID=(UINT_PTR)hSubMenu;
                UINT uFlag=MF_OWNERDRAW|MF_POPUP;
                if(bDisable) uFlag |= MF_GRAYED;
                AppendMenu(menuPopup,uFlag,(UINT_PTR)hSubMenu,(LPCTSTR)pdmmi);
                BuildMenu(hSubMenu,xmlItem);//build sub menu
            }
            m_arrDmmi.Add(pdmmi);
        }
        else if(wcscmp(L"sep",xmlItem.name())==0)
        {
            AppendMenu(menuPopup,MF_SEPARATOR|MF_OWNERDRAW,(UINT_PTR)0,(LPCTSTR)NULL);
        }
        xmlItem=xmlItem.next_sibling();
    }
}
예제 #16
0
bool EntityManager::awake(pugi::xml_node& config)
{
	LOG("EntityManager: Awake.");
	bool ret = true;

	animationName.assign("animation/");
	animationName.append(config.first_child().first_attribute().as_string());

	return ret;
}
예제 #17
0
파일: Response.cpp 프로젝트: Vanuan/iviLink
void Response::GetError(pugi::xml_node errorNode, ErrorCode & errorCode, const char *& errorString)
{
	const char* errorCodeString = errorNode.attribute("code").value();
	char *ptr;
	if (errorCodeString != NULL && errorCodeString[0] != '\0')
	{
		errorCode = (ErrorCode)strtol(errorCodeString, &ptr, 10);
		errorString = errorNode.first_child().value();
	}
}
예제 #18
0
bool RomCommon::KeyboardControlComponent::Initialise(pugi::xml_node data)
{

	Logger::getInstance()->Log("RomCommon::KeyboardControlComponent :: Initialising");
	

	this->_active = data.attribute("active").as_bool(false);

	//this->_script = data.

	for(pugi::xml_node item = data.first_child(); item; item = item.next_sibling())
	{
		std::string name = item.name();

		if(name == "script")
		{
			this->_script = item.child_value();
		}

		if(name == "object")
		{
			this->_object = item.attribute("name").as_string();
			
			for(pugi::xml_node subItem = item.first_child(); subItem; subItem = subItem.next_sibling())
			{
				std::string subName = subItem.name();

				if(subName == "function")
				{
					this->_function = subItem.attribute("name").as_string();
				}
			}
		}		
	}

#ifdef _DEBUG
	
	assert(!this->_object.empty());
	assert(!this->_script.empty());
	assert(!this->_function.empty());

#endif

	if(this->_script.empty() ||
		this->_object.empty() ||
		this->_function.empty())
	{
		Logger::getInstance()->Log("RomCommon::KeyboardControlComponent :: There is either no script, object or function defined", LOG_ERROR);
		return false;
	}

	Logger::getInstance()->Log("RomCommon::KeyboardControlComponent :: SUCCESS!");

	return true;
}
예제 #19
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;
    }
}
예제 #20
0
		void loadValue(pugi::xml_node attrib, const BoundSetter<std::vector<Ref<T> > >& setValue)
		{
			std::vector<Ref<T> > value;
			for(pugi::xml_node ref = attrib.first_child(); ref; ref = ref.next_sibling())
			{
				Ref<T> obj = context.getObject<T>(ref.attribute("ref").as_int());
				if(obj)
					value.push_back(obj);
			}
			setValue(value);
		}
예제 #21
0
void CDuiMenu::BuildMenu( HMENU menuPopup,pugi::xml_node xmlNode )
{
	pugi::xml_node xmlItem=xmlNode.first_child();

    while(xmlItem)
    {
        if(strcmp("item",xmlItem.name())==0)
        {
            DuiMenuItemData *pdmmi=new DuiMenuItemData;
            pdmmi->hMenu=menuPopup;
			pdmmi->itemInfo.iIcon=xmlItem.attribute("icon").as_int(-1);
			pdmmi->itemInfo.strText=DUI_CA2T(xmlItem.text().get(),CP_UTF8);

            int nID=xmlItem.attribute("id").as_int(0);
            BOOL bCheck=xmlItem.attribute("check").as_bool(false);
			BOOL bRadio=xmlItem.attribute("radio").as_bool(false);
			BOOL bDisable=xmlItem.attribute("disable").as_bool(false);


			pugi::xml_writer_buff writer;
			xmlItem.print(writer);
			CDuiStringW str=DUI_CA2W(CDuiStringA(writer.buffer(),writer.size()),CP_UTF8);

			pugi::xml_node xmlChild=xmlItem.first_child();
			while(xmlChild && xmlChild.type()==pugi::node_pcdata) xmlChild=xmlChild.next_sibling();


			if(!xmlChild)
            {
                pdmmi->nID=nID;
                UINT uFlag=MF_OWNERDRAW;
                if(bCheck) uFlag|=MF_CHECKED;
                if(bDisable) uFlag |= MF_GRAYED;
                if(bRadio) uFlag |= MFT_RADIOCHECK|MF_CHECKED;
                AppendMenu(menuPopup,uFlag,(UINT_PTR)pdmmi->nID,(LPCTSTR)pdmmi);
            }
            else
            {
                HMENU hSubMenu=::CreatePopupMenu();
                pdmmi->nID=(UINT_PTR)hSubMenu;
                UINT uFlag=MF_OWNERDRAW|MF_POPUP;
                if(bDisable) uFlag |= MF_GRAYED;
                AppendMenu(menuPopup,uFlag,(UINT_PTR)hSubMenu,(LPCTSTR)pdmmi);
                BuildMenu(hSubMenu,xmlItem);//build sub menu
            }
            m_arrDmmi.Add(pdmmi);
        }
        else if(strcmp("sep",xmlItem.name())==0)
        {
            AppendMenu(menuPopup,MF_SEPARATOR|MF_OWNERDRAW,(UINT_PTR)0,(LPCTSTR)NULL);
        }
		xmlItem=xmlItem.next_sibling();
    }
}
예제 #22
0
파일: Actor.cpp 프로젝트: karmalis/Romuva
void RomCommon::Actor::SetProperties(pugi::xml_node propertyNode)
{
	for(pugi::xml_node prop = propertyNode.first_child(); prop; prop = prop.next_sibling())
	{
		std::string name = prop.name();
		std::transform(name.begin(), name.end(), name.begin(), ::tolower);

		bool pResult = (name.find("position") != std::string::npos);
		bool sResult = (name.find("scale") != std::string::npos);
		bool tResult = (name.find("target") != std::string::npos);
		bool uResult = (name.find("up") != std::string::npos);
		bool rResult = (name.find("rotation") != std::string::npos);
		bool initScriptResult = (name.find("init_script") != std::string::npos);
		bool updateScriptResult = (name.find("update_script") != std::string::npos);

		if(pResult)
		{
			
			this->_position.X = prop.attribute("x").as_float();
			this->_position.Y = prop.attribute("y").as_float();
			this->_position.Z = prop.attribute("z").as_float();

		} else if(uResult) {

			
			this->_up.X = prop.attribute("x").as_float();
			this->_up.Y = prop.attribute("y").as_float();
			this->_up.Z = prop.attribute("z").as_float();
			this->_up.Normalise();

		} else if(rResult) {
			this->_rotX = prop.attribute("x").as_float();
			this->_rotY = prop.attribute("y").as_float();
			this->_rotZ = prop.attribute("z").as_float();
		} else if(tResult) {

			this->_target.X = prop.attribute("x").as_float();
			this->_target.Y = prop.attribute("y").as_float();
			this->_target.Z = prop.attribute("z").as_float();
			//this->_target.Normalise();

		} else if(sResult) {
			this->_scale.X = prop.attribute("x").as_float();
			this->_scale.Y = prop.attribute("y").as_float();
			this->_scale.Z = prop.attribute("z").as_float();
		}

		if(name == "name")
		{
			this->_name = prop.child_value();
		}
	}
}
예제 #23
0
파일: Response.cpp 프로젝트: Vanuan/iviLink
int Response::ExtractIntegerNode(pugi::xml_node node)
{
	int value = 0;

	const char* valueStr = node.first_child().value();
	if (valueStr != NULL && valueStr[0] != '\0')
	{
		char *ptr;
		value = strtol(valueStr, &ptr, 10);
	}
	return value;
}
예제 #24
0
	void SettingsManager::mergeNodes(pugi::xml_node _nodeTarget, pugi::xml_node _nodeSource)
	{
		bool listElement = MyGUI::utility::endWith(_nodeTarget.name(), ".List");

		// затираем текст у цели потому что любое значение текста источника является конечным
		pugi::xml_node targetTextNode = _nodeTarget.first_child();
		if (!targetTextNode.empty() && targetTextNode.type() == pugi::node_pcdata)
			targetTextNode.set_value("");

		pugi::xml_node sourceTextNode = _nodeSource.first_child();
		if (!sourceTextNode.empty() && sourceTextNode.type() == pugi::node_pcdata)
		{
			targetTextNode = _nodeTarget.first_child();
			if (targetTextNode.empty())
				targetTextNode = _nodeTarget.append_child(pugi::node_pcdata);
			targetTextNode.set_value(sourceTextNode.value());
		}

		for (pugi::xml_node::iterator child = _nodeSource.begin(); child != _nodeSource.end(); child ++)
		{
			if ((*child).type() != pugi::node_element)
				continue;

			pugi::xml_node targetChildNode;

			if (listElement)
			{
				targetChildNode = _nodeTarget.append_child((*child).name());
			}
			else
			{
				targetChildNode = _nodeTarget.child((*child).name());
				if (targetChildNode.empty())
					targetChildNode = _nodeTarget.append_child((*child).name());
			}

			mergeAttributes(targetChildNode, (*child));
			mergeNodes(targetChildNode, (*child));
		}
	}
예제 #25
0
pugi::xml_node FindElementWithAttribute(pugi::xml_node node, const char* element, const char* attribute, const char* value)
{
	pugi::xml_node child = element ? node.child(element) : node.first_child();
	while (child) {
		const char* nodeVal = child.attribute(attribute).value();
		if (nodeVal && !strcmp(value, nodeVal))
			return child;

		child = element ? child.next_sibling(element) : child.next_sibling();
	}

	return child;
}
예제 #26
0
std::vector<pugi::xml_node> GetChildNodes(pugi::xml_node& node)
{
    std::vector<pugi::xml_node> childNodes;
    node = node.first_child();

    while (node != NULL)
    {
        childNodes.push_back(node);
        node = node.next_sibling();
    }

    return childNodes;
}
예제 #27
0
파일: token_reader.cpp 프로젝트: juteel/arc
arc::instruction_container arc::token_reader::read ( pugi::xml_node & node )
{
	pugi::xml_node walker = node.first_child ( ) ;
	
	arc::instruction_container instructions ;
	
	if ( walker )
	{
		do
		{	
			bool print = true ;
			
			for ( auto iterator : this->tokens ( ) )
			{
				arc::instruction_container new_instructions = iterator->read ( walker ) ;
				
				if ( ! new_instructions.empty ( ) )
				{
					print = false ;
					instructions.insert ( instructions.end ( ) , new_instructions.begin ( ) , new_instructions.end ( ) ) ;
				}
			}
			
			if ( print )
			{
				std::stringstream stream ;
				walker.print ( stream , "" , pugi::format_raw , pugi::encoding_auto , 1 ) ;
				
				instructions.push_back ( std::make_shared <arc::print_instruction> ( stream.str ( ) ) ) ;
			}
				
			// pugi::xml_node::traverse
			if ( walker.first_child ( ) )
				walker = walker.first_child ( ) ;
			else if ( walker.next_sibling ( ) )
				walker = walker.next_sibling ( ) ;
			else
			{
				while ( ! walker.next_sibling ( ) && walker != node && ! walker.parent ( ).empty ( ) )
				{
					walker = walker.parent ( ) ;
				}
				
				if ( walker != node )
					walker = walker.next_sibling ( ) ;
			}
		} while ( walker && walker != node ) ;
	}
	
	return instructions ;
}
예제 #28
0
 void buildShapes(ogl::CObject*& pObject, const pugi::xml_node& _shapes)
 {
   size_t i = 0;
   for(pugi::xml_node _shape = _shapes.first_child(); _shape; _shape = _shape.next_sibling())
   {
     ogl::CShape* pShape = pObject->getShape(i);
     
     pugi::xml_node _textures = _shape.child("textures");
     if(_textures)
       buildTextures(pShape, _textures);
       
     ++i;
   }
 }
예제 #29
0
void AlignedSentenceSyntax::XMLParse(Phrase &output,
                                     SyntaxTree &tree,
                                     const pugi::xml_node &parentNode,
                                     const Parameter &params)
{
  int childNum = 0;
  for (pugi::xml_node childNode = parentNode.first_child(); childNode; childNode = childNode.next_sibling()) {
    string nodeName = childNode.name();

    // span label
    string label;
    int startPos = output.size();

    if (!nodeName.empty()) {
      pugi::xml_attribute attribute = childNode.attribute("label");
      label = attribute.as_string();

      // recursively call this function. For proper recursive trees
      XMLParse(output, tree, childNode, params);
    }



    // fill phrase vector
    string text = childNode.value();
    Escape(text);
    //cerr << childNum << " " << label << "=" << text << endl;

    std::vector<string> toks;
    Moses::Tokenize(toks, text);

    for (size_t i = 0; i < toks.size(); ++i) {
      const string &tok = toks[i];
      Word *word = new Word(output.size(), tok);
      output.push_back(word);
    }

    // is it a labelled span?
    int endPos = output.size() - 1;

    // fill syntax labels
    if (!label.empty()) {
      label = "[" + label + "]";
      tree.Add(startPos, endPos, label, params);
    }

    ++childNum;
  }

}
예제 #30
0
파일: XMLFile.cpp 프로젝트: 03050903/Urho3D
void XMLFile::PatchReplace(const pugi::xml_node& patch, pugi::xpath_node& original) const
{
    // If no attribute but node then its a node, otherwise its an attribute or null
    if (!original.attribute() && original.node())
    {
        pugi::xml_node parent = original.node().parent();

        parent.insert_copy_before(patch.first_child(), original.node());
        parent.remove_child(original.node());
    }
    else if (original.attribute())
    {
        original.attribute().set_value(patch.child_value());
    }
}