1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
////////////////////////////////////////////////////////////////////////////////
/*! @file Undo.h Механизм откатов для сети и вообще Undo-Redo.
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
- Copyright(C) 2006-2010, Viktor E. Bursian, St.Petersburg, Russia.
Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#ifndef Undo_H
#define Undo_H
#include <list>
#include <stack>
#include "General.h"
#include "Strings.h"
//#include "Storable.h"
namespace RA {
//------------------------------------------------------------------------------
ANNOUNCE_ABSTRACT_CLASS(sUndoItem)
ANNOUNCE_ABSTRACT_CLASS(sRedoItem)
ANNOUNCE_ABSTRACT_CLASS(sUndoRedoItem)
ANNOUNCE_CLASS(sUndoList)
ANNOUNCE_CLASS(sUndoGroupedList)
ANNOUNCE_CLASS(sUndoRedo)
ANNOUNCE_CLASS(sDummyUndoItem)
ANNOUNCE_CLASS(sDummyRedoItem)
using std::list;
using std::stack;
//---------------------------------------------------------------- sUndoItem ---
class RANet_EXPORT sUndoItem //: virtual public sStorable
{
public:
virtual ~sUndoItem ()
{};
sUndoItem ()
:TheOwner(NULL)
{};
virtual sString Hint ()
{ return sString(); };
virtual void UndoIt () =0;
psUndoRedo Owner () const
{ return TheOwner; };
private:
void SetOwner (psUndoRedo owner)
{ TheOwner=owner; };
//public: // fields
//TimeStamp
private: // fields
psUndoRedo TheOwner;
friend class sUndoRedo;
};
//------------------------------------------------------------ sUndoRedoItem ---
class RANet_EXPORT sRedoItem : public sUndoItem
{
public:
virtual void RedoIt () =0;
private:
virtual void UndoIt () {};
};
//------------------------------------------------------------ sUndoRedoItem ---
class RANet_EXPORT sUndoRedoItem : public sUndoItem
{
public:
virtual void RedoIt () =0;
};
//---------------------------------------------------------------- sUndoList ---
class RANet_EXPORT sUndoList : public sUndoRedoItem
{
public:
virtual ~sUndoList ();
sUndoList ()
:RedoSubstitution(NULL)
{};
sUndoList (rcsString hint)
:HintText(hint),RedoSubstitution(NULL)
{};
sUndoList (psRedoItem RS)
:RedoSubstitution(RS)
{};
sUndoList (rcsString hint ,psRedoItem RS)
:HintText(hint),RedoSubstitution(RS)
{};
virtual void UndoIt ();
virtual void RedoIt ();
virtual void Push (psUndoItem I);
virtual psUndoItem Pop ();
virtual psUndoItem Top ();
virtual void Clear ();
virtual bool Empty ()
{ return Items.empty(); };
virtual int Size ()
{ return Items.size(); };
virtual sString Hint ()
{ return HintText; };
virtual void SetHintText (rcsString hint)
{ HintText=hint; };
virtual void SetRedoSubstitution (psRedoItem RS)
{ RedoSubstitution=RS; };
protected:
private: // fields
list<psUndoItem> Items;
sString HintText;
psRedoItem RedoSubstitution;
friend class sUndoRedo;
};
//--------------------------------------------------------- sUndoGroupedList ---
class RANet_EXPORT sUndoGroupedList : public sUndoList
{
public:
virtual void Push (psUndoItem I);
virtual psUndoItem Pop ();
virtual psUndoItem Top ();
void GroupBegin (rcsString hint ,psRedoItem RS);
void GroupEnd ();
bool ThereIsUnclosedGroup () const
{ return ! OpenGroups.empty(); };
psUndoList GroupOnTop () const
{ return ( OpenGroups.empty()
? NULL
: OpenGroups.top() ); };
private: // fields
stack<psUndoList> OpenGroups;
};
//---------------------------------------------------------------- sUndoRedo ---
class RANet_EXPORT sUndoRedo : public sUndoGroupedList
{
public: //typedefs
typedef bool fSelected(psUndoItem);
typedef fSelected * pfSelected;
public:
virtual ~sUndoRedo ();
sUndoRedo (int limit = -1);
virtual void Push (psUndoItem I);
virtual void Clear ();
void SetLimit (int limit);
virtual void Undo ();
virtual void Redo ();
void GroupOpen ()
{ GroupBegin(sString(),NULL); };
void GroupOpen (rcsString hint)
{ GroupBegin(hint,NULL); };
void GroupOpen (psRedoItem RS)
{ GroupBegin(sString(),RS); };
void GroupOpen (rcsString hint ,psRedoItem RS)
{ GroupBegin(hint,RS); };
void GroupClose (rcsString hint);
void GroupClose (psRedoItem RS);
void GroupClose (rcsString hint ,psRedoItem RS);
void GroupClose ();
virtual void GroupFlush ();
virtual void RollBack ();
// virtual void RollBackSelective (rcsTag class_type);
virtual void RollBackSelective (pfSelected);
virtual bool RedoEmpty ()
{ return REDO.Empty(); };
virtual int RedoSize ()
{ return REDO.Size(); };
virtual bool CanUndo ();
virtual bool CanRedo ();
virtual sString Hint ();
virtual sString RedoHint ();
private:
void ExecuteUndoOn (psUndoItem I);
void ExecuteRedoOn (psUndoItem I); //psRedoItem
private: // fields
sUndoList REDO;
bool Undoing;
bool Redoing;
int UndoLimit;
friend class sUndoList;
};
//----------------------------------------------------------- sDummyUndoItem ---
class RANet_EXPORT sDummyUndoItem : public sUndoItem
{
public:
virtual void UndoIt () {};
};
//----------------------------------------------------------- sDummyRedoItem ---
class RANet_EXPORT sDummyRedoItem : public sRedoItem
{
public:
virtual void RedoIt () {};
};
//------------------------------------------------------------------------------
}; //namespace RA
#endif
|