e6791d0a27d65441a6d3073272f047b22fb15a63
[goodguy/history.git] / cinelerra-5.1 / cinelerra / undostack.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef UNDOSTACK_H
23 #define UNDOSTACK_H
24
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include "linklist.h"
29 #include "stringfile.inc"
30
31 #define UNDOLEVELS 500
32 #define UNDO_KEY_INTERVAL 100
33
34
35 #define hash_sz2 8
36 #define hash_sz  (1<<hash_sz2)
37 #define hash_sz1 (hash_sz-1)
38 #define va 0
39 #define vb 1
40
41 class UndoHash
42 {
43 public:
44         UndoHash(char *txt, int len, UndoHash *nxt);
45         ~UndoHash();
46
47         UndoHash *nxt;
48         char *txt;  int len;
49         int line[2], occurs[2];
50 };
51
52 class UndoHashTable
53 {
54 public:
55         UndoHashTable();
56         ~UndoHashTable();
57         UndoHash *add(char *txt, int len);
58
59         UndoHash *table[hash_sz];
60         UndoHash *bof, *eof;
61 };
62
63 class UndoLine
64 {
65 public:
66         UndoLine(UndoHash *hash);
67         UndoLine(UndoHashTable *hash, char *txt, int len);
68         ~UndoLine();
69         int eq(UndoLine *ln);
70
71         char *txt;  int len;
72         UndoHash *hash;
73 };
74
75 class UndoVersion : public ArrayList<UndoLine *>
76 {
77 public:
78         UndoVersion(int v) { ver = v; }
79         ~UndoVersion() { remove_all_objects(); }
80         int ver;
81
82         void scan_lines(UndoHashTable *hash, char *sp, char *ep);
83 };
84
85
86 class UndoStackItem : public ListItem<UndoStackItem>
87 {
88 public:
89         UndoStackItem();
90         ~UndoStackItem();
91
92 // Must be inserted into the list before calling this, so it can get the
93 // previous key buffer.
94         void set_data(char *data);
95         void set_description(char *description);
96         void set_filename(char *filename);
97         const char* get_description();
98         void set_flags(uint64_t flags);
99
100 // Decompress the buffers and return them in a newly allocated string.
101 // The string must be deleted by the user.
102         char* get_data();
103         char* get_filename();
104         int get_size();
105         int is_key();
106         uint64_t get_flags();
107
108         void set_creator(void *creator);
109         void* get_creator();
110
111 private:
112 // command description for the menu item
113         char *description;
114
115 // key undo buffer or incremental undo buffer
116         int key;
117
118 // type of modification
119         uint64_t load_flags;
120
121 // data after the modification for redos
122         char *data;
123         int data_size;
124
125 // pointer to the object which set this undo buffer
126         void *creator;
127
128         char *session_filename;
129 };
130
131 class UndoStack : public List<UndoStackItem>
132 {
133 public:
134         UndoStack();
135         ~UndoStack();
136
137 // get current undo/redo stack item
138         UndoStackItem *get_current_undo();
139         UndoStackItem *get_current_redo();
140
141 // Create a new undo entry and put on the stack.
142 // The current pointer points to the new entry.
143 // delete future undos if in the middle
144 // delete undos older than UNDOLEVELS if last
145         UndoStackItem* push();
146
147 // move to the next undo entry for a redo
148         UndoStackItem* pull_next();
149
150         void dump(FILE *fp=stdout);
151
152         UndoStackItem* current;
153 };
154
155 #endif