コード例 #1
0
	bool ParseHelperFoo::StartElementHandler(XmlParseMaster::SharedData* data, std::string name, Hashmap<std::string, std::string>& attributes)
	{
		if (!data)
		{
			throw std::exception("Shared data is null");
		}

		if (data->Is("SharedDataFoo"))
		{
			SharedDataFoo* reinterpereted = reinterpret_cast<SharedDataFoo*>(data);

			//Handle initializing the element itself
			reinterpereted->IncrementDepth();
			reinterpereted->mMap.Insert(std::pair<std::string, std::uint32_t>(name, 0xffffffff)); //Initialize to the max value of an unsigned int, indicating that the value hasn't been assigned yet			
			mElementStack.PushFront(name);//Put the current element into our stack


			//Handle attributes
			if (attributes.ContainsKey("name"))
			{
				reinterpereted->mName = (*(attributes.Find("name"))).second;
			}

			if (attributes.ContainsKey("style"))
			{
				reinterpereted->mStyle = (*(attributes.Find("style"))).second;
			}

			return true;
		}
		return false;
	}
コード例 #2
0
	//Handle start elements
	bool XMLParseHelperExpression::StartElementHandler(XmlParseMaster::SharedData* data, std::string name, Hashmap<std::string, std::string>& attributes)
	{
		/**
		Requirements for starting a new expression action:
		1. Shared data must be SharedDataWorld
		2. Name of element must be 'action'
		3. Must contain a 'class' attribute
		4. Must contain a 'target' attribute
		5. Must contain a 'name' attribute
		6. Class type must be 'ActionExpression'
		*/

		SharedDataWorld* reinterpereted = data->As<SharedDataWorld>();
		if (reinterpereted != nullptr && name == actionString && attributes.ContainsKey(classString) && attributes.ContainsKey(nameString))
		{
			if (attributes.Find(classString)->second == "ActionExpression")
			{
				//Ensure that we have either an actionList or an entity that is going to contain this new actionExpression
				Scope* actionList = reinterpereted->GetAction();
				Scope* entity = reinterpereted->GetEntity();
				if (actionList != nullptr && actionList->Is("ActionList"))
				{
					//Create a new actionExpression with the factory from the actionlist
					ActionExpression* newAction = actionList->As<ActionList>()->CreateAction("ActionExpression", attributes.Find(nameString)->second)->As<ActionExpression>();
					reinterpereted->SetAction(newAction);
				}
				else if (entity != nullptr)
				{
					//Create a new actionExpression with the factory from the entity
					ActionExpression* newAction = entity->As<Entity>()->CreateAction("ActionExpression", attributes.Find(nameString)->second)->As<ActionExpression>();
					reinterpereted->SetAction(newAction);
				}
				else
				{
					return false;
				}
				reinterpereted->IncrementDepth();
				return true;
			}
		}
		return false;
	}