Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Enum.hpp
1 #ifndef Rice__Enum__hpp_
2 #define Rice__Enum__hpp_
3 
4 #include "to_from_ruby_defn.hpp"
5 #include "Address_Registration_Guard.hpp"
6 #include "Array.hpp"
7 #include "Hash.hpp"
8 #include "String.hpp"
9 #include "Module.hpp"
10 #include "Data_Type.hpp"
11 
12 namespace Rice
13 {
14 
16 template<typename Enum_T>
18 {
20  static long as_long(Enum_T value);
21 };
22 
27 
45 template<typename Enum_T, typename Enum_Traits = Default_Enum_Traits<Enum_T> >
46 class Enum
47  : public Module_impl<Data_Type<Enum_T>, Enum<Enum_T, Enum_Traits> >
48 {
49 public:
51  Enum();
52 
54  Enum(
55  char const * name,
56  Module module = rb_cObject);
57 
59  Enum(Enum const & other);
60 
62  Enum & operator=(Enum const & other);
63 
65  virtual ~Enum();
66 
68 
73  char const * name,
74  Enum_T value);
75 
76  void swap(Enum & other);
77 
78 private:
80 
85  Enum<Enum_T, Enum_Traits> & initialize(
86  char const * name,
87  Module module = rb_cObject);
88 
89 private:
90  static Object each(Object self);
91  static Object to_s(Object self);
92  static Object to_i(Object self);
93  static Object inspect(Object self);
94  static Object compare(Object lhs, Object rhs);
95  static Object eql(Object lhs, Object rhs);
96  static Object hash(Object self);
97  static Object from_int(Class klass, Object i);
98 
99 private:
100  Array enums_;
101  Address_Registration_Guard enums_guard_;
102 
103  Hash names_;
104  Address_Registration_Guard names_guard_;
105 };
106 
107 template<typename T>
108 Enum<T> define_enum(
109  char const * name,
110  Module module = rb_cObject);
111 
112 } // namespace Rice
113 
114 #include "Enum.ipp"
115 
116 #endif // Rice__Enum__hpp_
117 
Default traits for the Enum class template.
Definition: Enum.hpp:17
Definition: Module_impl.hpp:47
Definition: Hash.hpp:24
static Module klass()
Explictly return the Ruby type.
virtual ~Enum()
Destructor.
Enum< Enum_T, Enum_Traits > & define_value(char const *name, Enum_T value)
Define a new enum value.
A wrapper for enumerated types.
Definition: Enum.hpp:46
static long as_long(Enum_T value)
Converts the enum value to a long.
A helper for defining a Module and its methods.
Definition: Module_defn.hpp:23
A helper for defining a Class and its methods.
Definition: Class_defn.hpp:21
A guard to register a given address with the GC.
Definition: Address_Registration_Guard_defn.hpp:29
The base class for all Objects.
Definition: Object_defn.hpp:23
Enum & operator=(Enum const &other)
Assignment operator.
Enum()
Default constructor.
A wrapper for the ruby Array class.
Definition: Array.hpp:22