HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_UndoWorkerFinder.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_UndoWorkerFinder.h
7  *
8  * COMMENTS:
9  * This class is contained within an object that does the work to
10  * execute an undo (the undo worker). When the worker is constructed,
11  * an object of this class is also constructed, and the object adds
12  * itself to the table of undo workers. When the worker is
13  * destructed, this object is also destructed, and this class removes
14  * itself from the table of undo worker finders.
15  *
16  * Use this class as follows:
17  *
18  * - If the class that executes the undo/redo's is called Worker, add a
19  * member variable of type UT_UndoWorkerFinder<Worker> and pass in
20  * a reference to the Worker class in the worker finder's constructor.
21  * - Create undos that are a subclass of UT_DelegatedUndo<Worker> and
22  * pass the a reference to the undo worker finder to the constructor
23  * of the delegated undo.
24  * - The delegated undo's undoWorker() method will return a pointer
25  * to the Worker object, or null if it has been deleted. The
26  * undo()/redo() method will not be called if the undo worker was
27  * deleted, so undoWorker() won't return null in these methods.
28  */
29 
30 #ifndef __UT_UndoWorkerFinder_h__
31 #define __UT_UndoWorkerFinder_h__
32 
33 #include "UT_API.h"
34 // This base class treats the undo worker as a void pointer.
36 {
37 public:
38  UT_UndoWorkerFinderBase(void *opaque_undo_worker);
40 
41  int undoWorkerId() const { return myUndoWorkerId; }
42 
43  // Normally, the destructor will invalidate itself, but you can invoke this
44  // earlier if you want.
45  void invalidate();
46 
47 private:
48  // The UT_UndoWorkerFinderTable class may set our undo worker id.
50 
51  void *myOpaqueUndoWorker;
52  int myUndoWorkerId;
53 };
54 
55 
56 // This templated class is a convenience class. Its methods are all inlined.
57 template <class UndoWorker>
59 {
60 public:
61  UT_UndoWorkerFinder(UndoWorker &undo_worker)
62  : UT_UndoWorkerFinderBase(&undo_worker) {}
63 
64 private:
65 };
66 
67 
68 #endif
UT_UndoWorkerFinder(UndoWorker &undo_worker)
#define UT_API
Definition: UT_API.h:12