home *** CD-ROM | disk | FTP | other *** search
- //
- // Copyright (c) 1997 Kuanar Technologies, Inc., a wholly owned
- // subsidiary of Microsoft Corp. All Rights Reserved
-
- // CCount class
- //
- // Encapsulates the locking, reading, incrementing, and unlocking of
- // the vote count data file
- #include "votecount.h"
-
- class CVote
- {
-
- // Public Methods
- public:
- // The constructor opens and locks the file, with a timeout of 10
- // seconds if the file is already locked by another process.
- // If the file doesn't exist, and "create" is true, then it
- // creates the count file with a count of 0.
- CVote(const char *filename, BOOL create=FALSE);
-
- ~CVote(); // closes and unlocks the file
-
- const char *votetype;
-
- void InitializeFile(); // Initializes File w/ votetype keys.
-
- void Increment(const char *votetype, long amount = 1);
- // adds "amount" to the vote_count
- void SetVoteCount(const char *votetype, long newCount);
- // Sets the current vote_count
- long GetVoteCount(const char *votetype); // Gets the current vote_count
-
- // Private Data Members
- private:
- long m_vote1count; // holds tally for yes/agree/for
- long m_vote2count; // holds tally for no/disagree/against
- int fd;
- BOOL error;
-
- BOOL OpenAndLock(const char *filename, int nTimeoutSec, BOOL create);
-
- void Close(); // closes .vot file
- void MakeWritable(const char *filename); // .vot file prep
- long ReadVoteCount(const char* votetype);
- void WriteVoteCount(const char* votetype, long count);
- BOOL IsValid(); // checks .vot file for validity
-
- };
-
- // Keys to identify a vote count file
- #define KEY1_STR "vote1type"
- #define KEY2_STR "vote2type"
- #define KEY_LEN 9
- #define MAX_NUM 12 // maximum length of a long
-