2 Copyright (C) 2001 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_history_h__
22 #define __ardour_history_h__
25 #include <sigc++/signal.h>
28 //struct History : public SigC::Object
29 struct History : public sigc::trackable
31 typedef list<T *> StateList;
34 StateList::iterator current;
36 History() { current = states.end(); }
37 ~History() { states.erase (states.begin(), states.end()); }
39 sigc::signal<void> CurrentChanged;
42 for (StateList::iterator i = states.begin(); i != states.end(); i++) {
46 current = states.end();
50 void push (T *state) {
51 /* remove any "undone" history above the current location
52 in the history, before pushing new state.
54 if (current != states.begin() && current != states.end()) {
55 states.erase (states.begin(), current);
57 current = states.insert (states.begin(), state);
62 if (current != states.end()) {
69 T *pop (bool remove) {
70 if (current == states.end()) {
74 if (current == states.begin()) {
82 states.erase (current);
89 T *earlier (uint32_t n) {
90 StateList::iterator i;
92 if (current == states.end()) {
100 /* the list is in LIFO order, so move toward the end to go "earlier" */
102 for (i = current; n && i != states.end(); i++, n--);
104 if (i == states.end()) {
113 T *later (uint32_t n) {
114 StateList::iterator i;
116 if (current == states.end()) {
124 /* the list is in LIFO order, so move toward the beginning to go "later" */
126 for (i = current; n && i != states.begin(); i--, n--);
134 T *nth (uint32_t n) {
135 StateList::iterator i;
137 for (i = states.begin(); n && i != states.end(); n--, i++);
139 if (i != states.end()) {
152 #endif /* __ardour_history_h__ */