home *** CD-ROM | disk | FTP | other *** search
- #ifndef __FORMATLOG__
- #define __FORMATLOG__ 1
-
- #ifndef __DATAAREA__
- #include "DataArea.h"
- #endif
-
- #ifndef __FORMATSTRINGS__
- #include "FormatStrings.h"
- #endif
-
- #ifndef __STDFILE__
- #include "StdFile.h"
- #endif
-
-
- // Define some classes
- class Formatting;
- struct FContext;
- class StdFile;
- class Syntactic;
-
- #pragma segment FormatLog
-
- /*µ class FormatLog
- ** This class provides a checkpoint log service for the Formatting class.
- ** The Checkpoint() method flushes previously logged actions, saves some
- ** state from the Formatting instance, and prepares the FormatLog to accept
- ** new actions. The Record() method logs the action. The Rollback() method
- ** restores state into the Formatting instance and enables the Redo() action.
- ** Calling Redo() will playback the actions that were Recorded. Redo() returns
- ** true if an action was executed, false if all actions have been performed.
- ** The behavior of Record() after Rollback() without any intervening
- ** Checkpoint() or EnableRecord() is that Record() will not take place. It is
- ** mandatory that IFormatLog(), Checkpoint(), or EnableRecord() be called for
- ** Record() to have any effect.
- */
- class FormatLog : public SingleObject {
- public:
- FormatLog();
- ~FormatLog();
-
- short IFormatLog();
- short IFormatLog(const FormatLog *aFormatLog);
- /*
- ** Initialize the line FormatLog object. Return noErr if the
- ** initialization succeeded, an error code otherwise
- */
-
- void Record(void(Formatting::*aMethod)());
- void Record(void(Formatting::*aMethod)(FormatString), FormatString aGlue);
- void Record(void(Formatting::*aMethod)(Syntactic *), Syntactic *aToken);
- void Record(void(Formatting::*aMethod)(Boolean), Boolean isGroup);
- /*
- ** Add actions to the queue. The actions are performed by invoking
- ** the "Redo" method and passing it a Formatting* to execute the
- ** action
- */
-
- void RecordDepth(int aDepth);
- int MinDepth() const;
- int MaxDepth() const;
- /*
- ** Record depth information and return it. RecordDepth updates the
- ** minimum and maximum depths. MinDepth() and MaxDepth return the
- ** depths. "Depth" is the number of contexts that are saved on
- ** the context stack by the Formatting class.
- */
-
- void EnableRecord();
- void Checkpoint(const FContext *aContext, const DataArea *savedContexts, int aDepth);
- void Rollback(FContext *aContext, DataArea *savedContexts);
- Boolean Redo(Formatting *aFormat);
- /*
- ** Checkpoint sets the mark for a future call to Rollback(), preserving
- ** the state information passed in the arguments. Rollback() restores
- ** the state to the last Checkpoint() and enables Redo. Redo() executes
- ** the next checkpointed action. It returns true if an action was
- ** executed, false otherwise.
- */
-
-
- private:
- size_t Next();
- // Return the offset within fLog of where the next Record() will save
- // an action
-
-
- private:
- // The values fState can assume
- enum {
- kRecording, // Checkpoint was done, Record() is allowed
- kRedoing // Rollback was done, Record() ignored
- };
-
-
- private:
- friend class CheckpointItem; // It knows how to allocate space
- DataArea fLog; // Queue of checkpointed commands
- size_t fNextRedo; // Next item for Redo()
- size_t fCheckpoint; // Checkpoint: restart point
- DataArea fSavedContexts; // Checkpoint: saved contexts
- Handle fContext; // Checkpoint: saved context
- int fMinDepth; // The depths of the context stack
- int fMaxDepth;
- short fState; // What is being done
- };
-
-
- //µ FormatLog::FormatLog
- #pragma segment FormatLog
- inline FormatLog::FormatLog()
- : fContext(0)
- {
- }
-
-
- //µ FormatLog::MinDepth
- #pragma segment FormatLog
- inline int FormatLog::MinDepth() const
- {
- return (fMinDepth);
- }
-
-
- //µ FormatLog::MaxDepth
- #pragma segment FormatLog
- inline int FormatLog::MaxDepth() const
- {
- return (fMaxDepth);
- }
-
-
- //µ FormatLog::EnableRecord
- #pragma segment FormatLog
- inline void FormatLog::EnableRecord()
- {
- fState = kRecording;
- }
-
-
- //µ FormatLog::Next
- #pragma segment FormatLog
- inline size_t FormatLog::Next()
- {
- return (fLog.GetCursor());
- }
-
-
- #endif
-
-
-