bool ETHCustomDataManager::ReadDataFromXMLFile(TiXmlElement *pRoot)
{
	TiXmlNode *pNode = pRoot->FirstChild(GS_L("CustomData"));
	if (pNode)
	{
		TiXmlElement *pEntities = pNode->ToElement();
		if (pEntities)
		{
			pNode = pEntities->FirstChild(GS_L("Variable"));
			if (pNode)
			{
				TiXmlElement *pVarIter = pNode->ToElement();
				if (pVarIter)
				{
					do
					{
						str_type::string type, name, value;
						TiXmlElement *pElement;

						// read the variable type (as a string)
						pNode = pVarIter->FirstChild(GS_L("Type"));
						if (pNode)
						{
							pElement = pNode->ToElement();
							if (pElement)
							{
								type = pElement->GetText();
							}
						}

						// read the variable name
						pNode = pVarIter->FirstChild(GS_L("Name"));
						if (pNode)
						{
							pElement = pNode->ToElement();
							if (pElement)
							{
								name = pElement->GetText();
							}
						}

						// read the variable value
						if (type != GS_L("") && name != GS_L(""))
						{
							pNode = pVarIter->FirstChild(GS_L("Value"));
							if (pNode)
							{
								pElement = pNode->ToElement();
								if (pElement)
								{
									if (type == DATA_NAME[ETHDT_VECTOR2])
									{
										Vector2 value(0,0);
										pElement->QueryFloatAttribute(GS_L("x"), &value.x);
										pElement->QueryFloatAttribute(GS_L("y"), &value.y);
										SetVector2(name, value);
									}
									else if (type == DATA_NAME[ETHDT_VECTOR3])
									{
										Vector3 value(0,0,0);
										pElement->QueryFloatAttribute(GS_L("x"), &value.x);
										pElement->QueryFloatAttribute(GS_L("y"), &value.y);
										pElement->QueryFloatAttribute(GS_L("z"), &value.z);
										SetVector3(name, value);
									}
									else
									{
										value = pElement->GetText();

										// passing the variable to the map
										if (type == DATA_NAME[ETHDT_FLOAT])
										{
											SetFloat(name, ETHGlobal::ParseFloat(value.c_str()));
										} else
										if (type == DATA_NAME[ETHDT_INT])
										{
											SetInt(name, ETHGlobal::ParseInt(value.c_str()));
										} else
										if (type == DATA_NAME[ETHDT_UINT])
										{
											SetUInt(name, ETHGlobal::ParseUInt(value.c_str()));
										} else
										if (type == DATA_NAME[ETHDT_STRING])
										{
											SetString(name, value);
										}
									}
								}
							}
						}

						pVarIter = pVarIter->NextSiblingElement();
					} while (pVarIter);
				}
			}
		}
	}
	return true;
}
Beispiel #2
0
bool NFCRecord::SetVector2(const int nRow, const std::string& strColTag, const NFVector2& value)
{
	int nCol = GetCol(strColTag);
	return SetVector2(nRow, nCol, value);
}