Browse Source

Replace, don't emplace...

Michael Ragazzon 6 years ago
parent
commit
60682a09a3

+ 2 - 4
Include/Rocket/Core/Element.inl

@@ -39,10 +39,8 @@ T Element::GetProperty(const String& name)
 template< typename T >
 void Element::SetAttribute(const String& name, const T& value)
 {
-	attributes.emplace(name, Variant(value));
-	AttributeNameList changed_attributes;
-	changed_attributes.insert(name);
-
+	attributes[name] = Variant(value);
+	AttributeNameList changed_attributes = { name };
 	OnAttributeChange(changed_attributes);
 }
 

+ 1 - 1
Source/Controls/ElementDataGrid.cpp

@@ -138,7 +138,7 @@ void ElementDataGrid::AddColumn(const Rocket::Core::String& fields, const Rocket
 	columns.push_back(column);
 
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("index", (int)(columns.size() - 1)); 
+	parameters["index"] = (int)(columns.size() - 1);
 	DispatchEvent("columnadd", parameters);
 }
 

+ 6 - 6
Source/Controls/ElementDataGridRow.cpp

@@ -409,8 +409,8 @@ void ElementDataGridRow::AddChildren(int first_row_added, int num_rows_added)
 	DirtyRow();
 
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("first_row_added", GetChildTableRelativeIndex(first_row_added));
-	parameters.emplace("num_rows_added", num_rows_added);
+	parameters["first_row_added"] = GetChildTableRelativeIndex(first_row_added);
+	parameters["num_rows_added"] = num_rows_added;
 	parent_grid->DispatchEvent("rowadd", parameters);
 }
 
@@ -441,8 +441,8 @@ void ElementDataGridRow::RemoveChildren(int first_row_removed, int num_rows_remo
 	document->LockLayout(false);
 
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("first_row_removed", GetChildTableRelativeIndex(first_row_removed));
-	parameters.emplace("num_rows_removed", num_rows_removed);
+	parameters["first_row_removed"] = GetChildTableRelativeIndex(first_row_removed);
+	parameters["num_rows_removed"] = num_rows_removed;
 	parent_grid->DispatchEvent("rowremove", parameters);
 }
 
@@ -452,8 +452,8 @@ void ElementDataGridRow::ChangeChildren(int first_row_changed, int num_rows_chan
 		children[i]->DirtyCells();
 
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("first_row_changed", GetChildTableRelativeIndex(first_row_changed));
-	parameters.emplace("num_rows_changed", num_rows_changed);
+	parameters["first_row_changed"] = GetChildTableRelativeIndex(first_row_changed);
+	parameters["num_rows_changed"] = num_rows_changed;
 	parent_grid->DispatchEvent("rowchange", parameters);
 }
 

+ 3 - 3
Source/Controls/ElementForm.cpp

@@ -47,9 +47,9 @@ void ElementForm::Submit(const Rocket::Core::String& name, const Rocket::Core::S
 {
 	Rocket::Core::Dictionary values;
 	if (name.empty())
-		values.emplace("submit", submit_value);
+		values["submit"] = submit_value;
 	else
-		values.emplace(name, submit_value);
+		values[name] = submit_value;
 
 	Core::ElementList form_controls;
 	Core::ElementUtilities::GetElementsByTagName(form_controls, this, "input");
@@ -83,7 +83,7 @@ void ElementForm::Submit(const Rocket::Core::String& name, const Rocket::Core::S
 		if (value != NULL)
 			value->Reset(value->Get< Rocket::Core::String >() + ", " + control_value);
 		else
-			values.emplace(control_name, control_value);
+			values[control_name] = control_value;
 	}
 
 	DispatchEvent("submit", values);

+ 1 - 1
Source/Controls/ElementTabSet.cpp

@@ -131,7 +131,7 @@ void ElementTabSet::SetActiveTab(int tab_index)
 		active_tab = tab_index;
 
 		Rocket::Core::Dictionary parameters;
-		parameters.emplace("tab_index", active_tab);
+		parameters["tab_index"] = active_tab;
 		DispatchEvent("tabchange", parameters);
 	}
 }

+ 1 - 1
Source/Controls/InputTypeCheckbox.cpp

@@ -55,7 +55,7 @@ bool InputTypeCheckbox::OnAttributeChange(const Core::AttributeNameList& changed
 		element->SetPseudoClass("checked", checked);
 
 		Rocket::Core::Dictionary parameters;
-		parameters.emplace("value", Rocket::Core::String(checked ? GetValue() : ""));
+		parameters["value"] = Rocket::Core::String(checked ? GetValue() : "");
 		element->DispatchEvent("change", parameters);
 	}
 

+ 1 - 1
Source/Controls/InputTypeRadio.cpp

@@ -62,7 +62,7 @@ bool InputTypeRadio::OnAttributeChange(const Core::AttributeNameList& changed_at
 			PopRadioSet();
 
 		Rocket::Core::Dictionary parameters;
-		parameters.emplace("value", Rocket::Core::String(checked ? GetValue() : ""));
+		parameters["value"] = Rocket::Core::String(checked ? GetValue() : "");
 		element->DispatchEvent("change", parameters);
 	}
 

+ 1 - 1
Source/Controls/WidgetDropDown.cpp

@@ -204,7 +204,7 @@ void WidgetDropDown::SetSelection(int selection, bool force)
 		value_layout_dirty = true;
 
 		Rocket::Core::Dictionary parameters;
-		parameters.emplace("value", value);
+		parameters["value"] = value;
 		parent_element->DispatchEvent("change", parameters);
 	}
 }

+ 1 - 1
Source/Controls/WidgetSlider.cpp

@@ -184,7 +184,7 @@ void WidgetSlider::SetBarPosition(float _bar_position)
 	PositionBar();
 
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("value", bar_position);
+	parameters["value"] = bar_position;
 	parent->DispatchEvent("change", parameters);
 }
 

+ 2 - 2
Source/Controls/WidgetTextInput.cpp

@@ -240,8 +240,8 @@ Core::Element* WidgetTextInput::GetElement()
 void WidgetTextInput::DispatchChangeEvent(bool linebreak)
 {
 	Rocket::Core::Dictionary parameters;
-	parameters.emplace("value", GetElement()->GetAttribute< Rocket::Core::String >("value", ""));
-	parameters.emplace("linebreak", linebreak);
+	parameters["value"] = GetElement()->GetAttribute< Rocket::Core::String >("value", "");
+	parameters["linebreak"] = Core::Variant(linebreak);
 	GetElement()->DispatchEvent("change", parameters);
 }
 

+ 0 - 1
Source/Controls/XMLNodeHandlerDataGrid.cpp

@@ -29,7 +29,6 @@
 #include "../../Include/Rocket/Core/StreamMemory.h"
 #include "../../Include/Rocket/Core/Log.h"
 #include "../../Include/Rocket/Core/Factory.h"
-#include "../../Include/Rocket/Core/String.h"
 #include "../../Include/Rocket/Core/XMLParser.h"
 #include "../../Include/Rocket/Controls/ElementDataGrid.h"
 

+ 1 - 1
Source/Core/BaseXMLParser.cpp

@@ -299,7 +299,7 @@ bool BaseXMLParser::ReadAttributes(XMLAttributes& attributes)
 			}
 		}
 
- 		attributes.emplace(attribute, value);
+ 		attributes[attribute] = value;
 
 		// Check for the end of the tag.
 		if (PeekString((const unsigned char*) "/", false) ||

+ 11 - 11
Source/Core/Context.cpp

@@ -499,7 +499,7 @@ bool Context::ProcessTextInput(word character)
 {
 	// Generate the parameters for the key event.
 	Dictionary parameters;
-	parameters.emplace("data", character);
+	parameters["data"] = character;
 
 	if (focus)
 		return focus->DispatchEvent(TEXTINPUT, parameters, true);
@@ -516,7 +516,7 @@ bool Context::ProcessTextInput(const String& string)
 	{
 		// Generate the parameters for the key event.
 		Dictionary parameters;
-		parameters.emplace("data", string[i]);
+		parameters["data"] = string[i];
 
 		if (focus)
 			consumed = focus->DispatchEvent(TEXTINPUT, parameters, true) && consumed;
@@ -733,7 +733,7 @@ bool Context::ProcessMouseWheel(int wheel_delta, int key_modifier_state)
 	{
 		Dictionary scroll_parameters;
 		GenerateKeyModifierEventParameters(scroll_parameters, key_modifier_state);
-		scroll_parameters.emplace("wheel_delta", wheel_delta);
+		scroll_parameters["wheel_delta"] = wheel_delta;
 
 		return hover->DispatchEvent(MOUSESCROLL, scroll_parameters, true);
 	}
@@ -909,8 +909,8 @@ void Context::UpdateHoverChain(const Dictionary& parameters, const Dictionary& d
 			if (!drag_started)
 			{
 				Dictionary drag_start_parameters = drag_parameters;
-				drag_start_parameters.emplace("mouse_x", old_mouse_position.x);
-				drag_start_parameters.emplace("mouse_y", old_mouse_position.y);
+				drag_start_parameters["mouse_x"] = old_mouse_position.x;
+				drag_start_parameters["mouse_y"] = old_mouse_position.y;
 				drag->DispatchEvent(DRAGSTART, drag_start_parameters);
 				drag_started = true;
 
@@ -1118,16 +1118,16 @@ void Context::ReleaseDragClone()
 // Builds the parameters for a generic key event.
 void Context::GenerateKeyEventParameters(Dictionary& parameters, Input::KeyIdentifier key_identifier)
 {
-	parameters.emplace("key_identifier", (int) key_identifier);
+	parameters["key_identifier"] = (int)key_identifier;
 }
 
 // Builds the parameters for a generic mouse event.
 void Context::GenerateMouseEventParameters(Dictionary& parameters, int button_index)
 {
-	parameters.emplace("mouse_x", mouse_position.x);
-	parameters.emplace("mouse_y", mouse_position.y);
+	parameters["mouse_x"] = mouse_position.x;
+	parameters["mouse_y"] = mouse_position.y;
 	if (button_index >= 0)
-		parameters.emplace("button", button_index);
+		parameters["button"] = button_index;
 }
 
 // Builds the parameters for the key modifier state.
@@ -1144,13 +1144,13 @@ void Context::GenerateKeyModifierEventParameters(Dictionary& parameters, int key
 	};
 
 	for (int i = 0; i < 7; i++)
-		parameters.emplace(property_names[i], (int) ((key_modifier_state & (1 << i)) > 0));
+		parameters[property_names[i]] = (int)((key_modifier_state & (1 << i)) > 0);
 }
 
 // Builds the parameters for a drag event.
 void Context::GenerateDragEventParameters(Dictionary& parameters)
 {	
-	parameters.emplace("drag_element", (void*) *drag);
+	parameters["drag_element"] = (void*) *drag;
 }
 
 // Releases all unloaded documents pending destruction.

+ 7 - 9
Source/Core/Element.cpp

@@ -1000,16 +1000,14 @@ Context* Element::GetContext()
 // Set a group of attributes
 void Element::SetAttributes(const ElementAttributes* _attributes)
 {
+	attributes.reserve(attributes.size() + _attributes->size());
+	for (auto& [key, value] : *_attributes)
+		attributes[key] = value;
+
 	AttributeNameList changed_attributes;
 	changed_attributes.reserve(_attributes->size());
-
 	for (auto& [key, value] : *_attributes)
-	{
 		changed_attributes.insert(key);
-		attributes.emplace(key, value);
-
-	}
-
 	OnAttributeChange(changed_attributes);
 }
 
@@ -2133,9 +2131,9 @@ void Element::GetRML(String& content)
 	content += "<";
 	content += tag;
 
-	String value;
-	for( auto& [name, variant] : attributes) // IterateAttributes(index, name, value))	
+	for( auto& [name, variant] : attributes)
 	{
+		String value;
 		if (variant.GetInto(value))
 			content += " " + name + "=\"" + value + "\"";
 	}
@@ -2588,7 +2586,7 @@ void Element::AdvanceAnimations()
 
 		for (auto it = it_completed; it != animations.end(); ++it)
 		{
-			dictionary_list.emplace_back().emplace("property", it->GetPropertyName());
+			dictionary_list.emplace_back(Dictionary({ { "property", it->GetPropertyName()} }));
 			is_transition.push_back(it->IsTransition());
 		}
 

+ 2 - 2
Source/Core/ElementHandle.cpp

@@ -134,8 +134,8 @@ void ElementHandle::ProcessEvent(Event& event)
 			}
 
 			Dictionary parameters;
-			parameters.emplace("handle_x", x);
-			parameters.emplace("handle_y", y);
+			parameters["handle_x"] = x;
+			parameters["handle_y"] = y;
 			DispatchEvent("handledrag", parameters);
 		}
 	}

+ 2 - 3
Source/Core/ElementUtilities.cpp

@@ -187,14 +187,13 @@ int ElementUtilities::GetStringWidth(Element* element, const WString& string)
 void ElementUtilities::BindEventAttributes(Element* element)
 {
 	// Check for and instance the on* events
-	//while(element->IterateAttributes(index, name, value))
-	for (auto& [name, variant] : element->GetAttributes())
+	for (const auto& [name, variant] : element->GetAttributes())
 	{
 		if (name.substr(0, 2) == "on")
 		{
 			EventListener* listener = Factory::InstanceEventListener(variant.Get<String>(), element);
 			if (listener)
-				element->AddEventListener(&name[2], listener, false);
+				element->AddEventListener(name.substr(2), listener, false);
 		}
 	}
 }

+ 1 - 1
Source/Core/XMLParser.cpp

@@ -141,7 +141,7 @@ void XMLParser::HandleElementStart(const String& _name, const XMLAttributes& _at
 	
 	for (auto& [key, variant] : _attributes)
 	{
-		attributes.emplace(key, variant.Get<String>());
+		attributes[key] = variant.Get<String>();
 	}
 
 	// Check for a specific handler that will override the child handler.

+ 1 - 1
Source/Debugger/ElementInfo.cpp

@@ -285,7 +285,7 @@ void ElementInfo::UpdateSourceElement()
 				}
 			}
 
-			for(auto& [name, variant] : source_element->GetAttributes())
+			for(const auto& [name, variant] : source_element->GetAttributes())
 			{
 				Core::String value = variant.Get<Core::String>();
 				if(name != "class" && name != "style" && name != "id")