home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / TV_CONFG.H < prev    next >
C/C++ Source or Header  |  1993-12-20  |  5KB  |  159 lines

  1. /************************************************************************
  2. **
  3. ** @(#)tv_confg.h    12/20/93    Chris Ahlstrom
  4. **
  5. **    C++ version
  6. **
  7. **    Very similar to winconfg.cpp, but designed for TurboVision.
  8. **
  9. *************************************************************************/
  10.  
  11.  
  12. #if !defined(TV_CONFG_h)                // { TV_CONFG_h
  13. #define TV_CONFG_h
  14.  
  15.  
  16. #if defined(__BORLANDC__)
  17. #pragma warn -amp        // ignore superfluous "&" warning
  18. #endif
  19.  
  20. #define Uses_TChDirDialog
  21. #define Uses_TDeskTop
  22. #define Uses_TFileDialog
  23. #include <tv.h>
  24.  
  25. #if defined(__BORLANDC__)
  26. #pragma warn .amp        // reset initial status of "&" warning
  27. #endif
  28.  
  29.  
  30. #include "filedlg.h"        // FilePicker class for DOS (TurboVision)
  31.  
  32.  
  33. /************************************************************************
  34. ** CFG_MAGIC_STRING_LENGTH
  35. **
  36. **    This is the length of the magic string used for verifying
  37. ** that a file is indeed the right kind of file for reading in a list
  38. ** of BasicConfigurations.  The length will be the same for all classes.
  39. ** [The only such class is SimpleConfiguration at present.]
  40. **
  41. **    It is tied to the class.  All classes will use this string
  42. ** in their reads/writes.  All classes will define their own strings
  43. ** and lengths.
  44. **
  45. ** CFG_MAGIC
  46. **
  47. **    This is the part common to all configurations.
  48. **
  49. ** CFG_PERSONAL_MAGIC
  50. **
  51. **    This is the part of the string peculiar to the program.
  52. ** The string can be null, in which case it is ignored.
  53. **
  54. *************************************************************************/
  55.  
  56. #define CFG_MAGIC            23
  57. #define CFG_PERSONAL_MAGIC         8
  58. #define CFG_OFFSET            CFG_MAGIC
  59. #define CFG_MAGIC_STRING_LENGTH (CFG_MAGIC+CFG_PERSONAL_MAGIC+1)
  60.  
  61.  
  62. /************************************************************************
  63. ** ForceNameFlag
  64. **
  65. **    A glorified set of #defines.
  66. **
  67. *************************************************************************/
  68.  
  69. typedef enum
  70. {
  71.     PREVIOUS_NAME_UNLESS_INACTIVE    = 0,    // usually passed as default
  72.     FORCE_NEW_NAME
  73.  
  74. } ForceNameFlag;
  75.  
  76.  
  77. /************************************************************************
  78. ** BasicConfiguration structure
  79. **
  80. **    We are going to support configurations in a very simple and
  81. ** inelegant way, until there's time to really learn about streaming
  82. ** and container classes.
  83. **
  84. **    For our purpose, a BasicConfiguration is simply a location
  85. ** in memory of a given size.  This location will be read into and
  86. ** written from, in order to set memory to a known state.
  87. ** 
  88. *************************************************************************/
  89.  
  90. typedef struct
  91. {
  92.     void *configuration;
  93.     int configurationSize;
  94.  
  95. } BasicConfiguration;
  96.  
  97.  
  98. /************************************************************************
  99. ** SimpleConfiguration class
  100. **
  101. **    This class maintains an array of BasicConfigurations by
  102. ** specifying a file-name for the configurations, and providing
  103. ** ways of reading and writing them.
  104. **
  105. **    The programmer simply creates a null-terminated array of
  106. ** BasicConfigurations in a header file.
  107. **
  108. **    This easy scheme supports expansion (adding more configurations)
  109. ** as long as the new configurations are tacked on at the end of the
  110. ** array, and as long as the old configurations do not change in
  111. ** size.
  112. **
  113. **    No checks are made as to correctness of the configurations.
  114. ** The bad dialog boxes should tell all!
  115. **
  116. *************************************************************************/
  117.  
  118. class SimpleConfiguration
  119. {
  120.  
  121. public:
  122.  
  123.     SimpleConfiguration            // constructor
  124.     (
  125.     TDeskTop *aparent,        // the parent window of object
  126.     char *filename,            // default filename for config file
  127.     BasicConfiguration *cfglist,    // a list of data areas
  128.     char *magic = 0            // magic string, if applicable
  129.     );
  130.  
  131.     virtual ~SimpleConfiguration();    // destructor
  132.  
  133.     virtual int read            // reads in the configuration
  134.     (
  135.     ForceNameFlag newname = PREVIOUS_NAME_UNLESS_INACTIVE
  136.     );
  137.     virtual int write            // writes the configuration
  138.     (
  139.     ForceNameFlag newname = PREVIOUS_NAME_UNLESS_INACTIVE
  140.     );
  141.     const char * errorMsg();        // quick and dirty error messages
  142.  
  143. protected:
  144.  
  145.     BasicConfiguration *configList;    // points to the list
  146.  
  147. private:
  148.  
  149.     FilePicker *configFile;        // it "has-a" file associated with it
  150.     int errorCode;            // holds latest error
  151.  
  152.     char *magic;            // magic area for class, modifiable
  153.  
  154.     static const char * const MAGIC;    // the constant portion
  155.  
  156. };
  157.  
  158. #endif                            // } TV_CONFG_h
  159.