URL:
  <http://gna.org/patch/?1309>

                 Summary: specenum.h
                 Project: Freeciv
            Submitted by: pepeto
            Submitted on: jeudi 17.09.2009 à 15:42
                Category: general
                Priority: 2
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: 2.3.0

    _______________________________________________________

Details:

Includes tools to use enumerators very easily.

Example:
  #define SPECENUM_NAME test
  #define SPECENUM_BITWISE
  #define SPECENUM_VALUE0 TEST0
  #define SPECENUM_VALUE1 TEST1
  #define SPECENUM_VALUE3 TEST3
  #include "specenum.h"

  {
    static const char *strings[] = {
      "TEST1", "test3", "fghdf", NULL
    };
    enum test e;
    int i;

    freelog(LOG_VERBOSE, "enum test [%d; %d]%s",
            test_min(), test_max(),
            test_bitwise ? " bitwise" : "");

    for (e = test_begin(); e != test_end(); e = test_next(e)) {
      freelog(LOG_VERBOSE, "Value %d is %s", e, test_name(e));
    }

    for (i = 0; strings[i]; i++) {
      e = test_by_name(strings[i], strcasecmp);
      if (test_valid(e)) {
        freelog(LOG_VERBOSE, "Value is %d for %s",
                e, strings[i]);
      } else {
        freelog(LOG_VERBOSE, "%s is not a valid name",
                strings[i]);
      }
    }
  }

Will output:
  enum test [1, 8] bitwise
  Value 1 is TEST0
  Value 2 is TEST1
  Value 8 is TEST3
  Value is 2 for TEST1
  Value is 8 for test3
  fghdf is not a valid name




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: jeudi 17.09.2009 à 15:42  Name: trunk_specenum.diff.gz  Size: 3 ko  
By: pepeto

<http://gna.org/patch/download.php?file_id=6745>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?1309>

_______________________________________________
  Message posté via/par Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to