home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Src / FormatLog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  4.0 KB  |  153 lines  |  [TEXT/MPS ]

  1. #ifndef __FORMATLOG__
  2. #define __FORMATLOG__    1
  3.  
  4. #ifndef __DATAAREA__
  5. #include "DataArea.h"
  6. #endif    
  7.  
  8. #ifndef __FORMATSTRINGS__
  9. #include "FormatStrings.h"
  10. #endif    
  11.  
  12. #ifndef __STDFILE__
  13. #include "StdFile.h"
  14. #endif    
  15.  
  16.  
  17. // Define some classes
  18. class Formatting;
  19. struct FContext;
  20. class StdFile;
  21. class Syntactic;
  22.  
  23. #pragma segment FormatLog
  24.  
  25. /*µ class FormatLog
  26. **    This class provides a checkpoint log service for the Formatting class.
  27. ** The Checkpoint() method flushes previously logged actions, saves some
  28. ** state from the Formatting instance, and prepares the FormatLog to accept
  29. ** new actions.  The Record() method logs the action.  The Rollback() method
  30. ** restores state into the Formatting instance and enables the Redo() action.
  31. ** Calling Redo() will playback the actions that were Recorded.  Redo() returns
  32. ** true if an action was executed, false if all actions have been performed.
  33. **    The behavior of Record() after Rollback() without any intervening
  34. ** Checkpoint() or EnableRecord() is that Record() will not take place.  It is
  35. ** mandatory that IFormatLog(), Checkpoint(), or EnableRecord() be called for
  36. ** Record() to have any effect.
  37. */
  38. class FormatLog : public SingleObject {
  39. public:
  40.     FormatLog();
  41.     ~FormatLog();
  42.  
  43.     short IFormatLog();
  44.     short IFormatLog(const FormatLog *aFormatLog);
  45.     /*
  46.     ** Initialize the line FormatLog object.  Return noErr if the
  47.     ** initialization succeeded, an error code otherwise
  48.     */
  49.  
  50.     void Record(void(Formatting::*aMethod)());
  51.     void Record(void(Formatting::*aMethod)(FormatString), FormatString aGlue);
  52.     void Record(void(Formatting::*aMethod)(Syntactic *), Syntactic *aToken);
  53.     void Record(void(Formatting::*aMethod)(Boolean), Boolean isGroup);
  54.     /*
  55.     ** Add actions to the queue.  The actions are performed by invoking
  56.     ** the "Redo" method and passing it a Formatting* to execute the
  57.     ** action
  58.     */
  59.  
  60.     void RecordDepth(int aDepth);
  61.     int MinDepth() const;
  62.     int MaxDepth() const;
  63.     /*
  64.     ** Record depth information and return it.  RecordDepth updates the
  65.     ** minimum and maximum depths.  MinDepth() and MaxDepth return the
  66.     ** depths.  "Depth" is the number of contexts that are saved on
  67.     ** the context stack by the Formatting class.
  68.     */
  69.  
  70.     void EnableRecord();
  71.     void Checkpoint(const FContext *aContext, const DataArea *savedContexts, int aDepth);
  72.     void Rollback(FContext *aContext, DataArea *savedContexts);
  73.     Boolean Redo(Formatting *aFormat);
  74.     /*
  75.     ** Checkpoint sets the mark for a future call to Rollback(), preserving
  76.     ** the state information passed in the arguments.  Rollback() restores
  77.     ** the state to the last Checkpoint() and enables Redo.  Redo() executes
  78.     ** the next checkpointed action.  It returns true if an action was
  79.     ** executed, false otherwise.
  80.     */
  81.  
  82.  
  83. private:
  84.     size_t Next();
  85.     // Return the offset within fLog of where the next Record() will save
  86.     // an action
  87.  
  88.  
  89. private:
  90.     // The values fState can assume
  91.     enum {
  92.         kRecording,                                // Checkpoint was done, Record() is allowed
  93.         kRedoing                                // Rollback was done, Record() ignored
  94.     };
  95.  
  96.  
  97. private:
  98.     friend class CheckpointItem;                // It knows how to allocate space
  99.     DataArea fLog;                                // Queue of checkpointed commands
  100.     size_t fNextRedo;                            // Next item for Redo()
  101.     size_t fCheckpoint;                            // Checkpoint: restart point
  102.     DataArea fSavedContexts;                    // Checkpoint: saved contexts
  103.     Handle fContext;                            // Checkpoint: saved context
  104.     int fMinDepth;                                // The depths of the context stack
  105.     int fMaxDepth;
  106.     short fState;                                // What is being done
  107. };
  108.  
  109.  
  110. //µ   FormatLog::FormatLog
  111. #pragma segment FormatLog
  112. inline FormatLog::FormatLog()
  113.     : fContext(0)
  114.     {
  115.     }
  116.  
  117.  
  118. //µ   FormatLog::MinDepth
  119. #pragma segment FormatLog
  120. inline int FormatLog::MinDepth() const
  121. {
  122.     return (fMinDepth);
  123. }
  124.  
  125.  
  126. //µ   FormatLog::MaxDepth
  127. #pragma segment FormatLog
  128. inline int FormatLog::MaxDepth() const
  129. {
  130.     return (fMaxDepth);
  131. }
  132.  
  133.  
  134. //µ   FormatLog::EnableRecord
  135. #pragma segment FormatLog
  136. inline void FormatLog::EnableRecord()
  137. {
  138.     fState = kRecording;
  139. }
  140.  
  141.  
  142. //µ   FormatLog::Next
  143. #pragma segment FormatLog
  144. inline size_t FormatLog::Next()
  145. {
  146.     return (fLog.GetCursor());
  147. }
  148.  
  149.  
  150. #endif    
  151.  
  152.  
  153.