PageRenderTime 24ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llundo.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 68 lines | 35 code | 8 blank | 25 comment | 2 complexity | 7bac9818b1d02361e204e4a069bc7fd6 MD5 | raw file
 1/** 
 2 * @file llundo.h
 3 * @brief Generic interface for undo/redo circular buffer.
 4 *
 5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_LLUNDO_H
28#define LL_LLUNDO_H
29
30
31class LLUndoBuffer
32{
33public:
34	class LLUndoAction
35	{
36		friend class LLUndoBuffer;
37	public:
38		virtual void undo() = 0;
39		virtual void redo() = 0;
40		virtual void cleanup() {};
41	protected:
42		LLUndoAction(): mClusterID(0) {};
43		virtual ~LLUndoAction(){};
44	private:
45		S32		mClusterID;
46	};
47
48	LLUndoBuffer( LLUndoAction (*create_func()), S32 initial_count );
49	virtual ~LLUndoBuffer();
50
51	LLUndoAction *getNextAction(BOOL setClusterBegin = TRUE);
52	BOOL undoAction();
53	BOOL redoAction();
54	BOOL canUndo() { return (mNextAction != mFirstAction); }
55	BOOL canRedo() { return (mNextAction != mLastAction); }
56
57	void flushActions();
58
59private:
60	LLUndoAction **mActions;	// array of pointers to undoactions
61	S32			mNumActions;	// total number of actions in ring buffer
62	S32			mNextAction;	// next action to perform undo/redo on
63	S32			mLastAction;	// last action actually added to undo buffer
64	S32			mFirstAction;	// beginning of ring buffer (don't undo any further)
65	S32			mOperationID;	// current operation id, for undoing and redoing in clusters
66};
67
68#endif //LL_LLUNDO_H