|
|
/*************************************************************************** dpoints.h - description ------------------- begin : Fri Feb 4 2000 copyright : (C) 2000 by Daniel Roberge email : droberge@uvic.ca ***************************************************************************/ #ifndef _DPOINTS_H #define _DPOINTS_H /**Keeps track of a variable value with a maximum possible value. Archetypical example is hit points. *@author Daniel Roberge */ class DepletablePoints { private: int current, maximum; /**Keeps the current value less than the maximum value*/ void MakeValid(void) {if (current > maximum) current = maximum;}; public: /*---------------Constructors-----------------------*/ /**Creates a DepletablePoints with maximum 0*/ DepletablePoints(void); /**Creates a DepletablePoints with maximum val*/ DepletablePoints(int val); /**Creates a DepletablePoints with maximum max but a current value curr*/ DepletablePoints(int curr,int max); /*-------------Modification Methods----------------*/ /**Increases the current value by delta and enforces the maximum. Returns the new current value*/ int Change(int delta); /**Changes the current value to val and enforces the maximum. Returns the new current value*/ int SetCurrent(int val); /**Sets the maximum value to val and enforces it. Returns the new current value*/ int SetMax(int val); /**Increases the maximum value by delta and enforces it. Returns the new current value*/ int ChangeMax(int delta); /**Makes the current and maximum values equal to the corresponding values in the argument. */ void become(DepletablePoints arg); /*-----------------Information Methods-----------*/ /**Returns the current value of the object*/ int GetCurrent(void) const { return current; }; /**Returns the maximum value*/ int GetMax(void) const { return maximum; }; /**What do you think?*/ bool IsPositive(void) const { return (current > 0); }; /*------------------Operators------------------------------*/ /**Increments the current value of the DepletablePoints.*/ DepletablePoints operator++ () {current++; MakeValid(); return *this;}; /**Decrements the current value of the DepletablePoints.*/ DepletablePoints operator-- () {current--; return *this;}; /**Adds the argument to the current value and returns it. Non-destructive. */ int operator+ (int arg) const {return current + arg;}; /**Subtracts the argument from the current value and returns it.*/ int operator- (int arg) const {return current - arg;}; /**Assigns the argument to the current value. */ DepletablePoints operator= (int arg) {current = arg; MakeValid(); return *this;}; /**Assigns the current value of the argument to the current value.*/ DepletablePoints operator= (DepletablePoints arg) {current = arg.current; MakeValid(); return *this; }; /**Increases the current value by the argument. */ DepletablePoints operator+= (int arg) {current += arg; MakeValid(); return *this;}; /**Decreases the current value by the argument. */ DepletablePoints operator-= (int arg) {current -= arg; return *this;}; }; typedef DepletablePoints& RDepletablePoints; typedef DepletablePoints* PDepletablePoints; #endif
Generated by: droberge@magebook.localdomain on Mon Jul 3 13:20:08 200. |