Classes | Defines
Enum.h File Reference
#include <string>
#include <vector>
#include <string.h>
#include <bwi_tools/common/Params.h>
Include dependency graph for Enum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  EnumName

Defines

#define ENUM(Enum,...)

Define Documentation

#define ENUM (   Enum,
  ... 
)
Value:
namespace Enum { \
    enum type {__VA_ARGS__, NUM}; \
  } \
  typedef Enum::type Enum##_t; \
  inline static const char* getName(Enum::type e) {static EnumName en(#__VA_ARGS__, (size_t) Enum::NUM); return en.getName((size_t) e);} \
  namespace Enum { \
    inline type fromName(const char* name, bool ignoreUnknown = false) { \
      for (size_t i = 0; i < NUM; i++) { \
        if (strcmp(getName((type)i),name) == 0) \
          return (type)i; \
      } \
      if (ignoreUnknown) \
        return NUM; \
      std::cerr << "Problem converting " << name << " to type " << #Enum << std::endl; \
      exit(13); \
    } \
    inline type fromName(const std::string &name, bool ignoreUnknown = false) {return fromName(name.c_str(),ignoreUnknown);} \
  } \
  SET_FROM_JSON_ENUM(Enum)

Defining an enum and a function getName(<Enum>) that can return the name of each enum element. The enum will automatically contain an element NUM that reflects the number of elements defined.

Definition at line 65 of file Enum.h.



bwi_tools
Author(s): Piyush Khandelwal
autogenerated on Fri Aug 28 2015 10:14:30