Wow. I first have to say that your solution is amazing.
But I'm unfortunately here in order to report what could likely be a bug.
When building Enum subclass it seems that you cannot add more than 16 EnumItem, otherwise they are no longer generated. Here is the piece of code that I cannot make compile because of this. Is that intended? Explainable? Why?
Thank you very much for your comments . There shouldn't be a limitation, the code is a precompiled generation of a class with all the items... the only explanation I can imagine is that maybe there is a limitation on the compiler you are using. I have tested that code under Windows XP, Vista and 7, in 32 and 64-bit versions, with MS Visual Studio 2005 (but should work also with higher versions). May I ask which compiler/precompiler are you using?
Another details you may check are:
- After the backslash of each precompiled line you cannot put any comments (eg: //16) because the compiler may fail.
- The last ENUMITEM shouldn't end with backslash.
Those things are related to the precompiler, but do not explain why it is failing for you after the item 16. You may activate the /EP /P compiler options (for MS compiler) to generate and see the preprocessed file with the real code that the macros generate.
Another problem that could appear is if any of your items has the same name of a reserver word or conflicts with another global variable/constant/define... in that case, you may check the first failing item. Regards,
Thank you very much for your improvements of the code you sent me .
It is very useful to support both, string and wstring. I will add the support of wstring in version 6.0, but I need the code to be multiplatform so I cannot include "windows.h" to use the TEXT macro. I will solve that with:
//! Some stuff to get the string of the IMPROVED_ENUM_NAME///////////////////////////////////////////////////////////
#define GET_MACRO_STRING_EXPANDED(Macro) #Macro
#define GET_MACRO_STRING(Macro) TXT(GET_MACRO_STRING_EXPANDED(Macro))
#define ENUM_SEPARATOR TXT("::")
My code can generate a class with static methods to encapsulate an enum type with some improvements. That's OOP. I'm also working in a version with non-static methods to generate something better than a .net enum class, but in a multiplatform environment.
If you have any constructive ideas, I mean a better way to do those things, I'd like to know them.
I have evolved this a lot since I published this article, but my code now is property of my company, so I cannot publish it.
I have planned to remake this from scratch in a different and better way, but this time the code will be mine and I will publish it. It will take me a few months, but I will publish here the news
Hi. That's the neverending problem with the MACRO definitions: there cannot be more that one definition at the same block of code. As I call #undef after using ENUMITEM() and after using ENUMITEM_VALUE(), I do not leave my macros defined below my block of code.
But if you leave a macro -with the same name of mine- defined after your block of code... that cannot work even if I check the existence of your macros.
Anyway, if you want to make that check, just add (at the beginning of "DefineImprovedEnum.h"):
#error ENUMITEM macro cannot be already defined
#error ENUMITEM_VALUE macro cannot be already defined