home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 January / dppcpro0199a.iso / January / Fp98 / SDK / WebBot / votebot / server / votefile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-18  |  1.9 KB  |  56 lines

  1. //
  2. // Copyright (c) 1997 Kuanar Technologies, Inc., a wholly owned
  3. //               subsidiary of Microsoft Corp.  All Rights Reserved
  4.  
  5. // CCount class
  6. //
  7. // Encapsulates the locking, reading, incrementing, and unlocking of
  8. // the vote count data file
  9. #include "votecount.h"
  10.  
  11. class CVote
  12. {
  13.  
  14.     // Public Methods
  15. public:
  16.     // The constructor opens and locks the file, with a timeout of 10
  17.     // seconds if the file is already locked by another process.
  18.     // If the file doesn't exist, and "create" is true, then it 
  19.     // creates the count file with a count of 0.
  20.     CVote(const char *filename, BOOL create=FALSE);
  21.     
  22.     ~CVote();                        // closes and unlocks the file
  23.  
  24.     const char *votetype;
  25.  
  26.     void InitializeFile();           // Initializes File w/ votetype keys.
  27.  
  28.     void Increment(const char *votetype, long amount = 1);
  29.                                      // adds "amount" to the vote_count
  30.     void SetVoteCount(const char *votetype, long newCount);
  31.                                      // Sets the current vote_count
  32.     long GetVoteCount(const char *votetype); // Gets the current vote_count
  33.  
  34.     // Private Data Members
  35. private:
  36.     long m_vote1count;                    // holds tally for yes/agree/for
  37.     long m_vote2count;                    // holds tally for no/disagree/against
  38.     int fd;
  39.     BOOL error;
  40.  
  41.     BOOL OpenAndLock(const char *filename, int nTimeoutSec, BOOL create);
  42.  
  43.     void Close();                       // closes .vot file
  44.     void MakeWritable(const char *filename);   // .vot file prep
  45.     long ReadVoteCount(const char* votetype);  
  46.     void WriteVoteCount(const char* votetype, long count);
  47.     BOOL IsValid();                     // checks .vot file for validity
  48.  
  49. };
  50.  
  51. // Keys to identify a vote count file
  52. #define KEY1_STR "vote1type"
  53. #define KEY2_STR "vote2type"
  54. #define KEY_LEN 9
  55. #define MAX_NUM 12                      // maximum length of a long
  56.