Example #1
0
int em::EmXml::ReadRootChildAttrList( EmVecMapStr &rVecMapStr )
{
	int iResult = 0;
	rVecMapStr.clear();

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	EmMapStr MapStr;
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		MapStr.clear();
		
		pAttrChild = pElemChild->FirstAttribute();
		while(true)
		{
			if(pAttrChild == NULL)
			{
				break;
			}
			
			MapStr[ pAttrChild->Name() ] = pAttrChild->Value();
			
			pAttrChild = pAttrChild->Next();
		}
		
		rVecMapStr.push_back(MapStr);
		pElemChild = pElemChild->NextSiblingElement();
	}
	
	iResult = rVecMapStr.size();
	
	return iResult;
}
Example #2
0
int em::EmXml::ReadRootChildAttrMap( const char* szKeyName, const char* szKeyValue, EmMapStr &rMapStr )
{
	int iResult = 0;
	rMapStr.clear();

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		if(EmSz::Equal( pElemChild->Attribute( szKeyName) , szKeyValue))
		{
			pAttrChild = pElemChild->FirstAttribute();
			while(true)
			{
				if(pAttrChild == NULL)
				{
					break;
				}
				
				rMapStr[  pAttrChild->Name() ] = pAttrChild->Value();
				pAttrChild = pAttrChild->Next();
			}
			break;
		}
		
		pElemChild = pElemChild->NextSiblingElement();
	}
	iResult = rMapStr.size();
	
	return iResult;
}
Example #3
0
int em::EmXml::RemoveRootChild( const char* szChildName, const char* szKeyName, const char* szKeyValue )
{
	bool bUpdated = false;
	int iResult = 0;

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		pAttrChild = pElemChild->FirstAttribute();
		
		if(EmSz::Equal( pElemChild->Attribute( szKeyName ), szKeyValue))
		{
			if(EmSz::Equal(pElemChild->Value(),szChildName))
			{
				pElemRoot->RemoveChild(pElemChild);
				bUpdated = true;
				break;
			}
			
		}
		
		pElemChild = pElemChild->NextSiblingElement();
	}

	m_bUpdated = bUpdated;

	return iResult;
}
Example #4
0
int em::EmXml::WriteRootChildAttrMap( const char* szKeyName, const char* szKeyValue, EmMapStr &rMapStr )
{
	std::string strResult;
	bool bUpdated = false;
	int iResult = 0;

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		pAttrChild = pElemChild->FirstAttribute();
		
		if(EmSz::Equal( pElemChild->Attribute( szKeyName), szKeyValue))
		{
			EmMapStr::const_iterator iterMap;
			for(iterMap = rMapStr.begin(); iterMap != rMapStr.end(); iterMap++)
			{
				pElemChild->SetAttribute(iterMap->first , iterMap->second);
			}
			bUpdated = true;
			break;
		}
		
		pElemChild = pElemChild->NextSiblingElement();
	}

	m_bUpdated = bUpdated;
	return iResult;
}
Example #5
0
std::string em::EmXml::ReadRootChildAttr( const char* szKeyName, const char* szKeyValue, const char* szAttrName )
{
	std::string strResult;
	int iResult = 0;

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return "";
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		pAttrChild = pElemChild->FirstAttribute();
		
		if( EmSz::Equal(pElemChild->Attribute( szKeyName ), szKeyValue) )
		{
			strResult = pElemChild->Attribute( szAttrName);
			break;
		}
		
		pElemChild = pElemChild->NextSiblingElement();
	}
	return strResult;
}
Example #6
0
void VersionInfoFactory::ParseOffsets(TiXmlElement * parent, VersionInfo* target, bool initial)
{
    // we parse the groups iteratively instead of recursively
    // breadcrubs acts like a makeshift stack
    // first pair entry stores the current element of that level
    // second pair entry the group object from OffsetGroup
    typedef triple< TiXmlElement *, OffsetGroup *, INVAL_TYPE> groupTriple;
    vector< groupTriple > breadcrumbs;
    {
        TiXmlElement* pEntry;
        // we get the <Offsets>, look at the children
        pEntry = parent->FirstChildElement();
        const char *cstr_invalid = parent->Attribute("valid");
        INVAL_TYPE parent_inval = NOT_SET;
        if(cstr_invalid)
        {
            if(strcmp(cstr_invalid,"false") == 0)
                parent_inval = IS_INVALID;
            else if(strcmp(cstr_invalid,"true") == 0)
                parent_inval = IS_VALID;
        }
        OffsetGroup * currentGroup = reinterpret_cast<OffsetGroup *> (target);
        currentGroup->setInvalid(parent_inval);

        // we end here if there are no child tags.
        if(!pEntry)
            return;

        breadcrumbs.push_back(groupTriple(pEntry,currentGroup, parent_inval));
    }

    // work variables
    OffsetGroup * currentGroup = 0;
    TiXmlElement * currentElem = 0;
    INVAL_TYPE parent_inval = NOT_SET;
    //cerr << "<Offsets>"<< endl;
    while(1)
    {
        // get current work variables
        currentElem = breadcrumbs.back().first;
        currentGroup = breadcrumbs.back().second;
        parent_inval = breadcrumbs.back().third;

        // we reached the end of the current group?
        if(!currentElem)
        {
            // go one level up
            breadcrumbs.pop_back();
            // exit if no more work
            if(breadcrumbs.empty())
            {
                break;
            }
            else
            {
                //cerr << "</group>" << endl;
                continue;
            }
        }

        if(!currentGroup)
        {
            groupTriple & gp = breadcrumbs.back();
            gp.first = gp.first->NextSiblingElement();
            continue;
        }

        // skip non-elements
        if (currentElem->Type() != TiXmlNode::ELEMENT)
        {
            groupTriple & gp = breadcrumbs.back();
            gp.first = gp.first->NextSiblingElement();
            continue;
        }

        // we have a valid current element and current group
        // get properties
        string type = currentElem->Value();
        std::transform(type.begin(), type.end(), type.begin(), ::tolower);
        const char *cstr_name = currentElem->Attribute("name");
        if(!cstr_name)
        {
            // ERROR, missing attribute
        }

        // evaluate elements
        const char *cstr_value = currentElem->Attribute("value");
        const char *cstr_invalid = currentElem->Attribute("valid");

        INVAL_TYPE child_inval = parent_inval;
        if(cstr_invalid)
        {
            if(strcmp(cstr_invalid,"false") == 0)
                child_inval = IS_INVALID;
            else if(strcmp(cstr_invalid,"true") == 0)
                child_inval = IS_VALID;
        }
        if(type == "group")
        {
            // create or get group
            OffsetGroup * og;
            if(initial)
                og = currentGroup->createGroup(cstr_name);
            else
                og = currentGroup->getGroup(cstr_name);

            // advance this level to the next element
            groupTriple & gp = breadcrumbs.back();
            gp.first = currentElem->NextSiblingElement();

            if(!og)
            {
                string fullname = currentGroup->getFullName() + cstr_name;
                throw Error::MissingMemoryDefinition("group", fullname);
            }

            // add a new level that will be processed in the next step
            breadcrumbs.push_back(groupTriple(currentElem->FirstChildElement(), og, child_inval));
            og->setInvalid(child_inval);
            continue;
        }
        else if(type == "address")
        {
            if(child_inval == NOT_SET)
                child_inval = IS_VALID;
            if(initial)
            {
                currentGroup->createAddress(cstr_name);
            }
            else if(cstr_value)
            {
                currentGroup->setAddress(cstr_name, cstr_value, child_inval);
            }
            else
            {
                currentGroup->setAddressValidity(cstr_name, child_inval);
            }
        }
        else if(type == "offset")
        {
            if(child_inval == NOT_SET)
                child_inval = IS_VALID;
            if(initial)
            {
                currentGroup->createOffset(cstr_name);
            }
            else if(cstr_value)
            {
                currentGroup->setOffset(cstr_name, cstr_value, child_inval);
            }
            else
            {
                currentGroup->setOffsetValidity(cstr_name, child_inval);
            }
        }
        else if(type == "string")
        {
            if(child_inval == NOT_SET)
                child_inval = IS_VALID;
            if(initial)
            {
                currentGroup->createString(cstr_name);
            }
            else if(cstr_value)
            {
                currentGroup->setString(cstr_name, cstr_value, child_inval);
            }
            else
            {
                currentGroup->setStringValidity(cstr_name, child_inval);
            }
        }
        else if(type == "hexvalue")
        {
            if(child_inval == NOT_SET)
                child_inval = IS_VALID;
            if(initial)
            {
                currentGroup->createHexValue(cstr_name);
            }
            else if(cstr_value)
            {
                currentGroup->setHexValue(cstr_name, cstr_value, child_inval);
            }
            else
            {
                currentGroup->setHexValueValidity(cstr_name, child_inval);
            }
        }

        // advance to next element
        groupTriple & gp = breadcrumbs.back();
        gp.first = currentElem->NextSiblingElement();
        continue;
    }
    //cerr << "</Offsets>"<< endl;
}