Author: ilor
Date: Tue Sep 9 22:47:31 2008
New Revision: 29364
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29364&view=rev
Log:
more complete interface for editor2's action_chain
Modified:
trunk/src/editor2/action.cpp
trunk/src/editor2/action.hpp
Modified: trunk/src/editor2/action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=29364&r1=29363&r2=29364&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Tue Sep 9 22:47:31 2008
@@ -84,6 +84,9 @@
void editor_action_chain::append_action(editor_action* a) {
actions_.push_back(a);
}
+void editor_action_chain::prepend_action(editor_action* a) {
+ actions_.push_front(a);
+}
bool editor_action_chain::empty() const {
return actions_.empty();
}
@@ -91,6 +94,12 @@
if (empty()) throw editor_action_exception("pop_last_action requested
on an empty action_chain");
editor_action* last = actions_.back();
actions_.pop_back();
+ return last;
+}
+editor_action* editor_action_chain::pop_first_action() {
+ if (empty()) throw editor_action_exception("pop_first_action requested
on an empty action_chain");
+ editor_action* last = actions_.front();
+ actions_.pop_front();
return last;
}
editor_action_chain* editor_action_chain::perform(map_context& mc) const {
Modified: trunk/src/editor2/action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=29364&r1=29363&r2=29364&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Tue Sep 9 22:47:31 2008
@@ -67,7 +67,8 @@
/**
* Container action wrapping several actions into one.
- * The actions are performed in the order they are added.
+ * The actions are performed in the order they are added,
+ * i.e. in the usual iteration order through the container.
*/
class editor_action_chain : public editor_action
{
@@ -81,10 +82,10 @@
}
/**
- * Create an action chain from a vector of action pointers.
+ * Create an action chain from a deque of action pointers.
* Note: the action chain assumes ownership of the pointers.
*/
- explicit editor_action_chain(std::vector<editor_action*>
actions)
+ explicit editor_action_chain(std::deque<editor_action*> actions)
: actions_(actions)
{
}
@@ -113,6 +114,11 @@
*/
void append_action(editor_action* a);
+ /**
+ * Add an action at the beginning of the chain
+ */
+ void prepend_action(editor_action* a);
+
/**
* @return true when there are no actions in the chain. Empty
* action chains should usually be discarded as to not keep
@@ -127,6 +133,12 @@
editor_action* pop_last_action();
/**
+ * Remove the first added action and return it, transfering
+ * ownership to the caller
+ */
+ editor_action* pop_first_action();
+
+ /**
* Perform all the actions in order and create a undo action
chain
*/
editor_action_chain* perform(map_context& m) const;
@@ -140,7 +152,7 @@
/**
* The action pointers owned by this action chain
*/
- std::vector<editor_action*> actions_;
+ std::deque<editor_action*> actions_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits