[Alephmodular-devel] Enum versus class?
Status: Pre-Alpha
Brought to you by:
brefin
From: Br'fin <br...@ma...> - 2003-03-01 19:27:23
|
As part of dealing with abstracting the display stuff I found myself wanting to back off a little and implement a BitDepth enum. Or similar. So I've been dabbling with it, and in wanting some class related foo I ended up developing the following: class BitDepth { public: typedef enum { _8bit, _16bit, _32bit } Depth; private: Depth depth; public: BitDepth(BitDepth::Depth _depth = _8bit) : depth(_depth) {} BitDepth(const BitDepth& _depth) : depth(_depth.depth) {} BitDepth(uint16); operator Depth() { return depth; } bool operator==(const BitDepth::Depth _depth) const { return depth == _depth; } bool operator==(const BitDepth& _depth) const { return this->operator==(_depth.depth); } bool operator!=(const BitDepth::Depth _depth) const { return depth != _depth; } bool operator!=(const BitDepth& _depth) const { return this->operator!=(_depth.depth); } BitDepth& operator=(const BitDepth& _depth) { depth = _depth.depth; return *this; } BitDepth& operator=(const BitDepth::Depth _depth) { depth = _depth; return *this; } }; inline BitDepth::BitDepth(uint16 val) { switch(val) { case 8: depth= _8bit; break; case 16: depth= _16bit; break; case 32: depth= _32bit; break; default: assert(0); } } And I'm trying to figure out if this is appropriate or overblown. If it's overblown then I should just fall back to using the enum by its lonesome. -Jeremy Parsons |