1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Modification History
*
* 2003-April-28 Jason Rohrer
* Created.
*
* 2003-April-29 Jason Rohrer
* Added missing destructor.
*/
#ifndef VARIABLE_INCLUDED
#define VARIABLE_INCLUDED
#include "minorGems/util/stringUtils.h"
/**
* Wrapper for a variable value.
*
* @author Jason Rohrer
*/
class Variable {
public:
/**
* Constructs a variable, setting its value.
*
* @param inName the name of the variable.
* Must be destroyed by caller if non-const.
* @param inValue the initial value of the variable.
*/
Variable( char *inName, double inValue );
virtual ~Variable();
/**
* Gets the value of this variable.
*
* @return the variable's value.
*/
virtual double getValue();
/**
* Sets the value for this variable.
*
* @param inValue the value.
*/
virtual void setValue( double inValue );
/**
* Gets the name of this variable.
*
* @return the name.
* Must be destroyed by caller.
*/
virtual char *getName();
protected:
char *mName;
double mValue;
};
inline Variable::Variable( char *inName, double inValue )
: mName( stringDuplicate( inName ) ), mValue( inValue ) {
}
inline Variable::~Variable() {
delete [] mName;
}
inline double Variable::getValue() {
return mValue;
}
inline void Variable::setValue( double inValue ) {
mValue = inValue;
}
inline char *Variable::getName() {
return stringDuplicate( mName );
}
#endif
|