On Mon, May 02, 2011 at 01:01:46PM -0700, Jeff Johnson wrote:
> To handle the #if statements below, I decided to explore a different route.
> If I pass the enum's as strings as Robert suggests, I can avoid the issue.
> It provides a higher level of backwards compatibility and is slightly easier
> to maintain.
> 
> I've created some Macros to wrap the enums and generate standard enums and a
> string map.  The enums will look like this:
> 
> DECLARE_ENUM (myenum)
> {
>     ENUM_CONST(enum_1)
>     ENUM_CONST_NUM(enum_2, 200)
>     ENUM_CONST(enum_three)
>     ENUM_END
> };
> 
> 
> The standard enum macros will look like this:
>   #define DECLARE_ENUM(x) enum x
>   #define ENUM_CONST_NUM(x,n) x = n,
>   #define ENUM_CONST(x) x,
>   #define ENUM_END
> 
> 
> And the string map macros will look like this:
> #define DECLARE_ENUM(x) struct enum_strings_##x : std::map<unsigned int,
> std::string> { enum_strings_##x ()
> #define ENUM_CONST_NUM(x,n) this->operator[]( x ) = # x;
> #define ENUM_CONST(x) this->operator[]( x ) = # x;
> #define ENUM_END }
> 
> 
> Are there are significant objections to this approach?  Is there anyway to
> improve it?
> If not, I'll continue my slow pace towards Online Tiles in this direction.

I afraid that it would decrease code readability quite a bit.  You'd need
hacks with including a file twice, and the body of enums would look like:

DECLARE_ENUM(monster_type)
  ENUM_CONST(MONS_SPRIGGAN)
  ENUM_CONST(MONS_SPRIGGAN_DRUID)
  ENUM_CONST_NUM(MONS_SPRIGGAN_ASSKICKER, 123)
  ENUM_CONST(MONS_SPRIGGAN_ASSASSIN)
ENUM_END

Also, the javascript code would have to carry its own redundant copy, that
wouldn't get automatic updates and thus be likely to get out of sync.

Thus, I really think generating the enum data with a script would be much
better.  The source could be either current enum.h, or from a plain list.
We already auto-generate a good part of enums: all tile enums, MST_,
unrands, command names, ...

-- 
1KB             // Microsoft corollary to Hanlon's razor:
                //      Never attribute to stupidity what can be
                //      adequately explained by malice.

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Crawl-ref-discuss mailing list
Crawl-ref-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/crawl-ref-discuss

Reply via email to