bool XMLElement::ShallowEqual(const XMLNode* compare) const
	{
		const XMLElement* other = compare->ToElement();
		if (other && XMLUtil::StringEqual(other->Value(), Value()))
		{

			const XMLAttribute* a = FirstAttribute();
			const XMLAttribute* b = other->FirstAttribute();

			while (a && b)
			{
				if (!XMLUtil::StringEqual(a->Value(), b->Value()))
				{
					return false;
				}
				a = a->Next();
				b = b->Next();
			}
			if (a || b)
			{
				// different count
				return false;
			}
			return true;
		}
		return false;
	}
Exemple #2
0
	XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const
	{
		if ( !doc ) {
			doc = _document;
		}
		XMLElement* element = doc->NewElement( Value() );					// fixme: this will always allocate memory. Intern?
		for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) {
			element->SetAttribute( a->Name(), a->Value() );					// fixme: this will always allocate memory. Intern?
		}
		return element;
	}
Exemple #3
0
void PhysicDataHill::initWithXmlNode( const XMLNode* hill )
{
	mHillModel.resize(0);
	for (const XMLNode* node=hill->FirstChild(); node; node = node->NextSibling())
	{
		Triangle tri; int count = 0;
		for (auto ele = node->FirstChildElement(); ele; ele = ele->NextSiblingElement())
		{
			float x=0; float y= 0;
			for (auto attr = ele->FirstAttribute(); attr; attr = attr->Next())
			{
				if (std::string(attr->Name()) == "x")
				{
					x = attr->FloatValue();
				}
				if (std::string(attr->Name()) == "y")
				{
					y = attr->FloatValue();
				}
			}
			tri.p[count].setPoint(x,y);
			if ( ++count == 3)
				break;
		}
		mHillModel.push_back(tri);
	}

	mStartPoint.x = 100000;
	mEndPoint.x = -100000;
	for (int i=0; i<mHillModel.size(); i++)
	{
		Triangle t = mHillModel[i];
		for (int i=0; i<3; i++)
		{
			if (t.p[i].x < mStartPoint.x)
				mStartPoint = t.p[i];
			if (t.p[i].x > mEndPoint.x)
				mEndPoint = t.p[i];
		}
	}
}
Exemple #4
0
		const bool _toTextImpl(TiXmlDocument* pInput, std::ofstream& pOutput) {
			if (!pInput) { return false; }

			auto spellsElement = pInput->FirstChildElement("spells");
			if (!spellsElement) { return false; }

			// Iterate <spell>
			auto spellElement = spellsElement->FirstChildElement("spell");
			while (spellElement) {
				// Iterate <spell> attributes.
				auto attribute = spellElement->FirstAttribute();
				while (attribute) {
					pOutput << attribute->Value();
					attribute = attribute->Next();
					if (attribute)
						pOutput << "^";
				}
				spellElement = spellElement->NextSiblingElement("spell");
				pOutput << std::endl;
			}

			return true;
		}
Exemple #5
0
XMLAttributePtr XMLNode::Attribute( const std::string& name )
{
    return FirstAttribute(name);
}
void ObjectLoader::LoadXMLFile(std::string loc)
{
	this->objects.clear();
	this->Lights.clear();

	tinyxml2::XMLDocument document;
	document.LoadFile(loc.c_str());
	if(document.Error() == true)
	{
		throw std::exception(("Failed at loading xml file " + loc + "\n" + document.GetErrorStr1() + "\n" + document.GetErrorStr2()).c_str());
	}
	for(auto objectNodeIter = document.FirstChildElement("Objects")->FirstChildElement("Light"); 
		objectNodeIter;
		objectNodeIter = objectNodeIter->NextSiblingElement("Light") )
	{
		std::map<std::string, std::string> info;

		for(auto childNodeIter = objectNodeIter->FirstChildElement();
			childNodeIter;
			childNodeIter = childNodeIter->NextSiblingElement())
		{
			std::string Name	= childNodeIter->Name();
			if (Name.compare(0, 3, "XYZ") == 0)
			{
				for(auto iterAttribute = childNodeIter->FirstAttribute();
					iterAttribute;
					iterAttribute = iterAttribute->Next())
				{
					std::string attributeName = iterAttribute->Name();

					info[Name+attributeName] = iterAttribute->Value();

				}
			}
			else
			{
				info[Name] = childNodeIter->GetText();
			}
		}
		
		this->Lights.push_back(info);
	}

	for(auto objectNodeIter = document.FirstChildElement("Objects")->FirstChildElement("PhysicsConstraint"); 
		objectNodeIter;
		objectNodeIter = objectNodeIter->NextSiblingElement("PhysicsConstraint") )
	{
		std::map<std::string, std::string> info;

		for(auto childNodeIter = objectNodeIter->FirstChildElement();
			childNodeIter;
			childNodeIter = childNodeIter->NextSiblingElement())
		{
			std::string Name = childNodeIter->Name();
			if (Name.compare(0, 3, "XYZ") == 0)
			{
				for(auto iterAttribute = childNodeIter->FirstAttribute();
					iterAttribute;
					iterAttribute = iterAttribute->Next())
				{
					std::string attributeName = iterAttribute->Name();

					info[Name+attributeName] = iterAttribute->Value();

				}
			}
			else
			{
				info[Name] = childNodeIter->GetText();
			}
		}
		
		this->PhysicsConstraints.push_back(info);
	}

	for(auto objectNodeIter = document.FirstChildElement("Objects")->FirstChildElement("Object"); 
		objectNodeIter;
		objectNodeIter = objectNodeIter->NextSiblingElement("Object") )
	{
		std::string ID;
		ObjectMaps newObject;

		for(auto childNodeIter = objectNodeIter->FirstChildElement();
			childNodeIter;
			childNodeIter = childNodeIter->NextSiblingElement())
		{
			std::string Name	= childNodeIter->Name();
			if(Name == "ID")
			{
				ID = childNodeIter->GetText();
			}
			else if (Name.compare(0, 3, "XYZ") == 0)
			{
				for(auto iterAttribute = childNodeIter->FirstAttribute();
					iterAttribute;
					iterAttribute = iterAttribute->Next())
				{
					std::string attributeName = iterAttribute->Name();

					newObject.Common[Name+attributeName] = iterAttribute->Value();

				}
			}
			else if(Name == "Draw")
			{
				for(auto drawNodeIter = childNodeIter->FirstChildElement();
					drawNodeIter;
					drawNodeIter = drawNodeIter->NextSiblingElement())
				{
					Name = drawNodeIter->Name();
					if (Name.compare(0, 3, "XYZ") == 0)
					{
						for(auto iterAttribute = drawNodeIter->FirstAttribute();
							iterAttribute;
							iterAttribute = iterAttribute->Next())
						{
							std::string attributeName = iterAttribute->Name();

							newObject.Drawing[Name+attributeName] = iterAttribute->Value();

						}
					}
					else if (Name.compare(0, 6, "Shader") == 0)
					{
						std::string X = drawNodeIter->Attribute("FileName");
						newObject.Drawing[Name+"FileName"] = X;
						std::string Y = drawNodeIter->Attribute("EntryPoint");
						newObject.Drawing[Name+"EntryPoint"] = Y;
						std::string Z = drawNodeIter->Attribute("Model");
						newObject.Drawing[Name+"Model"] = Z;
					}
					else
					{
						newObject.Drawing[Name] = drawNodeIter->GetText();
					}
				}
			}
			else if(Name == "Physics")
			{
				for(auto physicsIter = childNodeIter->FirstChildElement();
					physicsIter;
					physicsIter = physicsIter->NextSiblingElement())
				{
					Name = physicsIter->Name();
					if (Name.compare(0, 3, "XYZ") == 0)
					{
						for(auto iterAttribute = physicsIter->FirstAttribute();
							iterAttribute;
							iterAttribute = iterAttribute->Next())
						{
							std::string attributeName = iterAttribute->Name();

							newObject.Physics[Name+attributeName] = iterAttribute->Value();

						}
					}
					else
					{
						newObject.Physics[Name] = physicsIter->GetText();
					}
				}
			}
			else if(Name == "Input")
			{
				for(auto physicsIter = childNodeIter->FirstChildElement();
					physicsIter;
					physicsIter = physicsIter->NextSiblingElement())
				{
					Name = physicsIter->Name();
					if (Name.compare(0, 3, "XYZ") == 0)
					{
						for(auto iterAttribute = physicsIter->FirstAttribute();
							iterAttribute;
							iterAttribute = iterAttribute->Next())
						{
							std::string attributeName = iterAttribute->Name();

							newObject.Input[Name+attributeName] = iterAttribute->Value();

						}
					}
					else
					{
						newObject.Input[Name] = physicsIter->GetText();
					}
				}
			}
		}

		if(ID == "")
		{
			throw std::exception("Error loading one of the objects. It didn't have a class or an ID");
		}

		this->objects[ID] = newObject;
	}	
}