HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_DelegatedUndo.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_DelegatedUndo.h
7  *
8  * COMMENTS:
9  * This class is the base class for undo objects that delegate their
10  * work to someone else (the undo worker). It uses UT_UndoWorkerFinder's
11  * to see if the undo worker has been deleted.
12  *
13  * See the comments in UT_UndoWorkerFinder.h for instructions on how
14  * to use this class.
15  */
16 
17 #ifndef __UT_DelegatedUndo_h__
18 #define __UT_DelegatedUndo_h__
19 
20 #include "UT_API.h"
21 #include "UT_Undo.h"
22 #include "UT_UndoWorkerFinder.h"
23 
24 // Undo classes do not need to work with UT_DelegatedUndoBase directly.
26 {
27 public:
28  UT_DelegatedUndoBase(int undo_worker_id);
29 
30  // We can't undo or redo anything if our undo worker has been deleted.
31  bool isValid() override { return opaqueUndoWorker() != 0; }
32 
33 protected:
34  void *opaqueUndoWorker();
35 
36 private:
37  int myUndoWorkerId;
38 };
39 
40 
41 // This templated class is a convenience class to avoid casting.
42 template <class UndoWorker>
44 {
45 public:
47  : UT_DelegatedUndoBase(undo_worker_finder.undoWorkerId()) {}
48 
49 protected:
50  // A null pointer is returned if the undo work has been deleted.
51  // The undo() and redo() methods will not be called when undoWorker()
52  // returns null.
53  UndoWorker *undoWorker() { return (UndoWorker *)opaqueUndoWorker(); }
54 };
55 
56 
57 #endif
#define UT_API
Definition: UT_API.h:14
UndoWorker * undoWorker()
bool isValid() override
UT_DelegatedUndo(const UT_UndoWorkerFinder< UndoWorker > &undo_worker_finder)