| |
 | Posted by Matthew in reply to Lionello Lunesu | Permalink Reply |
|
Matthew 
Posted in reply to Lionello Lunesu
|
"Lionello Lunesu" <lio@lunesu.removethis.com> wrote in message news:d0h8ck$21rg$1@digitaldaemon.com...
>
> "Matthew" <admin.hat@stlsoft.dot.org> wrote in message news:d0gu1a$1n8b$1@digitaldaemon.com...
>>I have no fixed idea about how to do this as yet - a template solution is brimming slowly - but I'm thinking it'd be
>> perhaps better to have something built-in, e.g.
>>
>> public enum ORJ_FLAG
>> {
>> ORDERFIELDS = 0x0001 /*!< Arranges the fields in alphabetical order */
>> , ELIDEBLANKRECORDS = 0x0002 /*!< Causes blank records to be ignored */
>> };
>>
>> would become:
>>
>> public enum ORJ_FLAG
>> {
>> ORDERFIELDS = 0x0001 "Arranges the fields in alphabetical order"
>> , ELIDEBLANKRECORDS = 0x0002 "Causes blank records to be ignored"
>> };
>>
>
> This could be easily done by using a statically initialised AA.. Which isn't yet possible, unfortunately. Anyway, enum.toString() would be the right method to get this string (and the literal enum value's name if no custom is given?)
This is where I'm at so far:
/* /////////////////////////////////////////////////////////////////////////////
* Structs
*/
private struct EnumString
{
int value;
char[] str;
};
private template enum_to_string(T)
{
char[] enum_to_string(EnumString[] strings, T t)
{
// First version is simple - just a linear search
foreach(EnumString s; strings)
{
if(cast(int)(t) == s.value)
{
return s.str;
}
}
return "<unknown>";
}
}
/* /////////////////////////////////////////////////////////////////////////////
* Enumerations
*/
/** Flags that moderate the creation of Databases */
public enum ORJ_FLAG
{
ORDER_FIELDS = 0x0001 /*!< Arranges the fields in alphabetical order
*/
, ELIDE_BLANK_RECORDS = 0x0002 /*!< Causes blank records to be ignored
*/
}
public char[] toString(ORJ_FLAG f)
{
const EnumString strings[] =
[
{ ORJ_FLAG.ORDER_FIELDS, "Arranges the fields in alphabetical order" }
, { ORJ_FLAG.ELIDE_BLANK_RECORDS, "Causes blank records to be ignored" }
];
return enum_to_string!(ORJ_FLAG)(strings, f);
}
|