Re: Extensible enums
On 13 Dec, 00:50, Raikanta Sahu <raikanta.s...@gmail.com> wrote:
I thought this might be of interest readers of this group.
I don't want to comment on your basic idea, but just make a couple of
comments on style:
enum UptodateStatus
{
UPTODATE = 0,
PARAMETERS_MODIFIED = 00001,
TAGS_MODIFIED = 00002
};
You do realise that in C++ (and C) integer constants beginning with a
zero are assumed to be octal numbers? So if you add to your enum:
enum UptodateStatus
{
UPTODATE = 0,
PARAMETERS_MODIFIED = 00001,
TAGS_MODIFIED = 00002,
...
ANOTHER = 00011
};
Then ANOTHER actualy has the decimal value of 9. If the numbers are
really intended to be octal, I'd make sure there was a comment
explaining exactly why?
Secondly:
template <typename T, typename ValueGenerator>
class J_MSC_UpToDateStatus
{
public:
static int getNextValue()
{
static int value = 1;
int returnValue = value;
value *= 2;
return returnValue;
}
J_MSC_UpToDateStatus() : value_(0){}
bool isSet(int val) { return (( value_ & val ) == val); }
void operator|=(int rhs) { value_ |= rhs; }
void operator&=(int rhs) { value_ &= rhs; }
void operator^=(int rhs) { value_ &= rhs; }
private:
int value_;
};
It's normal for assignment operators (including composites as above)
to return the result of the assignment. Users of your class will
probably expect this, so if you don't want to return the value, I'd
make these operators named functions.
Neil Butterworth
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]