rice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +736 -0
  5. data/README +881 -0
  6. data/README.mingw +8 -0
  7. data/bootstrap +8 -0
  8. data/config.guess +1535 -0
  9. data/config.sub +1644 -0
  10. data/configure +7310 -0
  11. data/configure.ac +48 -0
  12. data/depcomp +584 -0
  13. data/doxygen.ac +314 -0
  14. data/doxygen.am +186 -0
  15. data/install-sh +507 -0
  16. data/missing +367 -0
  17. data/post-autoconf.rb +22 -0
  18. data/post-automake.rb +28 -0
  19. data/rice/Address_Registration_Guard.hpp +7 -0
  20. data/rice/Address_Registration_Guard.ipp +34 -0
  21. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  22. data/rice/Allocation_Strategies.hpp +37 -0
  23. data/rice/Array.hpp +220 -0
  24. data/rice/Array.ipp +262 -0
  25. data/rice/Builtin_Object.hpp +8 -0
  26. data/rice/Builtin_Object.ipp +50 -0
  27. data/rice/Builtin_Object_defn.hpp +51 -0
  28. data/rice/Class.cpp +57 -0
  29. data/rice/Class.hpp +8 -0
  30. data/rice/Class.ipp +4 -0
  31. data/rice/Class_defn.hpp +83 -0
  32. data/rice/Constructor.hpp +189 -0
  33. data/rice/Critical_Guard.hpp +34 -0
  34. data/rice/Critical_Guard.ipp +20 -0
  35. data/rice/Data_Object.hpp +127 -0
  36. data/rice/Data_Object.ipp +129 -0
  37. data/rice/Data_Type.cpp +21 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +227 -0
  40. data/rice/Data_Type_defn.hpp +219 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Enum.hpp +118 -0
  43. data/rice/Enum.ipp +246 -0
  44. data/rice/Exception.cpp +59 -0
  45. data/rice/Exception.hpp +69 -0
  46. data/rice/Exception_Base.hpp +30 -0
  47. data/rice/Exception_Base.ipp +11 -0
  48. data/rice/Hash.hpp +206 -0
  49. data/rice/Hash.ipp +336 -0
  50. data/rice/Identifier.cpp +8 -0
  51. data/rice/Identifier.hpp +50 -0
  52. data/rice/Identifier.ipp +33 -0
  53. data/rice/Jump_Tag.hpp +24 -0
  54. data/rice/Makefile.am +112 -0
  55. data/rice/Makefile.in +675 -0
  56. data/rice/Module.cpp +75 -0
  57. data/rice/Module.hpp +8 -0
  58. data/rice/Module.ipp +6 -0
  59. data/rice/Module_defn.hpp +87 -0
  60. data/rice/Module_impl.hpp +237 -0
  61. data/rice/Module_impl.ipp +302 -0
  62. data/rice/Object.cpp +153 -0
  63. data/rice/Object.hpp +8 -0
  64. data/rice/Object.ipp +19 -0
  65. data/rice/Object_defn.hpp +183 -0
  66. data/rice/Require_Guard.hpp +21 -0
  67. data/rice/String.cpp +93 -0
  68. data/rice/String.hpp +88 -0
  69. data/rice/Struct.cpp +117 -0
  70. data/rice/Struct.hpp +162 -0
  71. data/rice/Struct.ipp +26 -0
  72. data/rice/Symbol.cpp +25 -0
  73. data/rice/Symbol.hpp +66 -0
  74. data/rice/Symbol.ipp +44 -0
  75. data/rice/VM.cpp +79 -0
  76. data/rice/VM.hpp +27 -0
  77. data/rice/config.hpp +23 -0
  78. data/rice/config.hpp.in +22 -0
  79. data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
  80. data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
  81. data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
  82. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
  83. data/rice/detail/Caster.hpp +61 -0
  84. data/rice/detail/Exception_Handler.hpp +118 -0
  85. data/rice/detail/Iterator_Definer.hpp +98 -0
  86. data/rice/detail/Not_Copyable.hpp +25 -0
  87. data/rice/detail/Wrapped_Function.hpp +33 -0
  88. data/rice/detail/check_ruby_type.cpp +21 -0
  89. data/rice/detail/check_ruby_type.hpp +23 -0
  90. data/rice/detail/creation_funcs.hpp +45 -0
  91. data/rice/detail/creation_funcs.ipp +62 -0
  92. data/rice/detail/default_allocation_func.hpp +23 -0
  93. data/rice/detail/default_allocation_func.ipp +11 -0
  94. data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
  95. data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
  96. data/rice/detail/env.hpp +13 -0
  97. data/rice/detail/from_ruby.hpp +43 -0
  98. data/rice/detail/from_ruby.ipp +74 -0
  99. data/rice/detail/method_data.cpp +105 -0
  100. data/rice/detail/method_data.hpp +33 -0
  101. data/rice/detail/node.hpp +13 -0
  102. data/rice/detail/object_call.hpp +85 -0
  103. data/rice/detail/object_call.ipp +147 -0
  104. data/rice/detail/protect.cpp +27 -0
  105. data/rice/detail/protect.hpp +34 -0
  106. data/rice/detail/remove_const.hpp +21 -0
  107. data/rice/detail/ruby.hpp +85 -0
  108. data/rice/detail/rubysig.hpp +13 -0
  109. data/rice/detail/st.hpp +56 -0
  110. data/rice/detail/to_ruby.hpp +16 -0
  111. data/rice/detail/to_ruby.ipp +10 -0
  112. data/rice/detail/win32.hpp +16 -0
  113. data/rice/detail/wrap_function.hpp +288 -0
  114. data/rice/detail/wrap_function.ipp +473 -0
  115. data/rice/generate_code.rb +1092 -0
  116. data/rice/global_function.hpp +16 -0
  117. data/rice/global_function.ipp +11 -0
  118. data/rice/protect.hpp +91 -0
  119. data/rice/protect.ipp +803 -0
  120. data/rice/ruby_try_catch.hpp +86 -0
  121. data/rice/to_from_ruby.hpp +8 -0
  122. data/rice/to_from_ruby.ipp +299 -0
  123. data/rice/to_from_ruby_defn.hpp +71 -0
  124. data/ruby.ac +105 -0
  125. data/ruby/Makefile.am +1 -0
  126. data/ruby/Makefile.in +493 -0
  127. data/ruby/lib/Makefile.am +3 -0
  128. data/ruby/lib/Makefile.in +369 -0
  129. data/ruby/lib/mkmf-rice.rb.in +199 -0
  130. data/sample/Makefile.am +47 -0
  131. data/sample/Makefile.in +375 -0
  132. data/sample/enum/extconf.rb +3 -0
  133. data/sample/enum/sample_enum.cpp +54 -0
  134. data/sample/enum/test.rb +8 -0
  135. data/sample/inheritance/animals.cpp +98 -0
  136. data/sample/inheritance/extconf.rb +3 -0
  137. data/sample/inheritance/test.rb +7 -0
  138. data/sample/map/extconf.rb +3 -0
  139. data/sample/map/map.cpp +81 -0
  140. data/sample/map/test.rb +7 -0
  141. data/test/Makefile.am +44 -0
  142. data/test/Makefile.in +575 -0
  143. data/test/test_Address_Registration_Guard.cpp +43 -0
  144. data/test/test_Allocation_Strategies.cpp +77 -0
  145. data/test/test_Array.cpp +241 -0
  146. data/test/test_Builtin_Object.cpp +72 -0
  147. data/test/test_Class.cpp +350 -0
  148. data/test/test_Constructor.cpp +30 -0
  149. data/test/test_Critical_Guard.cpp +47 -0
  150. data/test/test_Data_Object.cpp +235 -0
  151. data/test/test_Enum.cpp +162 -0
  152. data/test/test_Exception.cpp +46 -0
  153. data/test/test_Hash.cpp +195 -0
  154. data/test/test_Identifier.cpp +70 -0
  155. data/test/test_Jump_Tag.cpp +17 -0
  156. data/test/test_Module.cpp +253 -0
  157. data/test/test_Object.cpp +148 -0
  158. data/test/test_String.cpp +94 -0
  159. data/test/test_Struct.cpp +192 -0
  160. data/test/test_Symbol.cpp +63 -0
  161. data/test/test_To_From_Ruby.cpp +281 -0
  162. data/test/test_VM.cpp +26 -0
  163. data/test/test_rice.rb +30 -0
  164. data/test/unittest.cpp +136 -0
  165. data/test/unittest.hpp +292 -0
  166. metadata +209 -0
@@ -0,0 +1,59 @@
1
+ #include "Exception.hpp"
2
+ #include "protect.hpp"
3
+ #include "to_from_ruby.hpp"
4
+ #include "detail/ruby.hpp"
5
+
6
+ #ifdef HAVE_STDARG_PROTOTYPES
7
+ #include <stdarg.h>
8
+ #define va_init_list(a,b) va_start(a,b)
9
+ #else
10
+ #include <varargs.h>
11
+ #define va_init_list(a,b) va_start(a)
12
+ #endif
13
+
14
+ Rice::Exception::
15
+ Exception(VALUE e)
16
+ : Exception_Base(e)
17
+ , message_(Qnil)
18
+ , message_guard_(&message_)
19
+ {
20
+ }
21
+
22
+ Rice::Exception::
23
+ Exception(Exception const & other)
24
+ : Exception_Base(other)
25
+ , message_(other.message_)
26
+ , message_guard_(&message_)
27
+ {
28
+ }
29
+
30
+ Rice::Exception::
31
+ Exception(Object exc, char const * fmt, ...)
32
+ : Exception_Base(Qnil)
33
+ , message_(Qnil)
34
+ , message_guard_(&message_)
35
+ {
36
+ va_list args;
37
+ char buf[BUFSIZ];
38
+
39
+ va_init_list(args, fmt);
40
+ vsnprintf(buf, BUFSIZ, fmt, args);
41
+ buf[BUFSIZ - 1] = '\0';
42
+ va_end(args);
43
+
44
+ set_value(protect(rb_exc_new2, exc, buf));
45
+ }
46
+
47
+ Rice::String Rice::Exception::
48
+ message() const
49
+ {
50
+ return protect(rb_funcall, value(), rb_intern("message"), 0);
51
+ }
52
+
53
+ char const * Rice::Exception::
54
+ what() const throw()
55
+ {
56
+ message_ = message();
57
+ return from_ruby<char const *>(message_);
58
+ }
59
+
@@ -0,0 +1,69 @@
1
+ #ifndef Rice__Exception__hpp_
2
+ #define Rice__Exception__hpp_
3
+
4
+ #include "Exception_Base.hpp"
5
+ #include "String.hpp"
6
+ #include "Address_Registration_Guard.hpp"
7
+
8
+ #include <stdexcept>
9
+ #include "detail/ruby.hpp"
10
+
11
+ namespace Rice
12
+ {
13
+
14
+ //! A placeholder for Ruby exceptions.
15
+ /*! You can use this to safely throw a Ruby exception using C++ syntax:
16
+ * \code
17
+ * VALUE foo(VALUE self) {
18
+ * RUBY_TRY {
19
+ * throw Rice::Exception(rb_eMyException, "uh oh!");
20
+ * RUBY_CATCH
21
+ * }
22
+ * \endcode
23
+ */
24
+ class Exception
25
+ : public Exception_Base
26
+ {
27
+ public:
28
+ //! Construct a Exception with the exception e.
29
+ explicit Exception(VALUE e);
30
+
31
+ //! Copy constructor.
32
+ Exception(Exception const & other);
33
+
34
+ //! Construct a Exception with printf-style formatting.
35
+ /*! \param exc either an exception object or a class that inherits
36
+ * from Exception.
37
+ * \param fmt a printf-style format string
38
+ * \param ... the arguments to the format string.
39
+ */
40
+ Exception(Object exc, char const * fmt, ...);
41
+
42
+ //! Destructor
43
+ virtual ~Exception() throw() { }
44
+
45
+ //! Get the message the exception holds
46
+ /*! \return the result of calling message() on the underlying
47
+ * exception object.
48
+ */
49
+ String message() const;
50
+
51
+ //! Get message as a char const *.
52
+ /*! If message is a non-string object, then this function will attempt
53
+ * to throw an exception (which it can't do because of the no-throw
54
+ * specification).
55
+ * \return the underlying C pointer of the underlying message object.
56
+ */
57
+ virtual char const * what() const throw();
58
+
59
+ private:
60
+ // Keep message around in case someone calls what() and then the GC
61
+ // gets invoked.
62
+ mutable VALUE message_;
63
+ Address_Registration_Guard message_guard_;
64
+ };
65
+
66
+ } // namespace Rice
67
+
68
+ #endif // Rice__Exception__hpp_
69
+
@@ -0,0 +1,30 @@
1
+ #ifndef Rice__Exception_Base__hpp_
2
+ #define Rice__Exception_Base__hpp_
3
+
4
+ #include "Object_defn.hpp"
5
+
6
+ namespace Rice
7
+ {
8
+
9
+ //! An abstract interface for Exception
10
+ /*! This class exists to prevent a circular reference between
11
+ * Exception.hpp and ruby_try_catch.hpp
12
+ */
13
+ class Exception_Base
14
+ : public std::exception
15
+ , public Object
16
+ {
17
+ public:
18
+ Exception_Base(VALUE v);
19
+
20
+ virtual ~Exception_Base() throw() = 0;
21
+
22
+ virtual char const * what() const throw() = 0;
23
+ };
24
+
25
+ } // Rice
26
+
27
+ #include "Exception_Base.ipp"
28
+ #include "Object.hpp"
29
+
30
+ #endif // Rice__Exception_Base__hpp_
@@ -0,0 +1,11 @@
1
+ inline Rice::Exception_Base::
2
+ Exception_Base(VALUE v)
3
+ : Object(v)
4
+ {
5
+ }
6
+
7
+ inline Rice::Exception_Base::
8
+ ~Exception_Base() throw()
9
+ {
10
+ }
11
+
data/rice/Hash.hpp ADDED
@@ -0,0 +1,206 @@
1
+ #ifndef Rice__Hash__hpp_
2
+ #define Rice__Hash__hpp_
3
+
4
+ #include "Builtin_Object_defn.hpp"
5
+ #include "to_from_ruby_defn.hpp"
6
+ #include "detail/ruby.hpp"
7
+ #include "detail/st.hpp"
8
+ #include "detail/remove_const.hpp"
9
+ #include <iterator>
10
+
11
+ namespace Rice
12
+ {
13
+
14
+ //! A wrapper for the ruby Hash class.
15
+ //! This class provides a C++-style interface to ruby's Hash class and
16
+ //! its associated rb_hash_* functions.
17
+ //! Example:
18
+ //! \code
19
+ //! Hash h;
20
+ //! h[42] = String("foo");
21
+ //! h[10] = String("bar");
22
+ //! std::cout << String(h[42]) << std::endl;
23
+ //! \endcode
24
+ class Hash
25
+ : public Builtin_Object<RHash, T_HASH>
26
+ {
27
+ public:
28
+ //! Construct a new hash.
29
+ Hash();
30
+
31
+ //! Wrap an existing hash.
32
+ /*! \param v the hash to wrap.
33
+ */
34
+ Hash(Object v);
35
+
36
+ //! Return the number of elements in the hash.
37
+ size_t size() const;
38
+
39
+ private:
40
+ //! A helper class so hash[key]=value can work.
41
+ class Proxy;
42
+
43
+ public:
44
+ //! Get the value for the given key.
45
+ /*! \param key the key whose value should be retrieved from the hash.
46
+ * \return the value associated with the given key.
47
+ */
48
+ template<typename Key_T>
49
+ Proxy const operator[](Key_T const & key) const;
50
+
51
+ //! Get the value for the given key.
52
+ /*! \param key the key whose value should be retrieved from the hash.
53
+ * \return the value associated with the given key.
54
+ */
55
+ template<typename Key_T>
56
+ Proxy operator[](Key_T const & key);
57
+
58
+ //! Get the value for the given key
59
+ /*! The returned value is converted to the type given by Value_T.
60
+ * \param key the key whose value should be retrieved from the hash.
61
+ * \return the value associated with the given key, converted to C++
62
+ * type Value_T.
63
+ */
64
+ template<typename Value_T, typename Key_T>
65
+ Value_T get(Key_T const & key);
66
+
67
+ //! A helper class for dereferencing iterators
68
+ class Entry;
69
+
70
+ //! A helper class for implementing iterators for a Hash.
71
+ template<typename Hash_Ref_T, typename Value_T>
72
+ class Iterator;
73
+
74
+ public:
75
+ //! An iterator.
76
+ typedef Iterator<Hash &, Entry> iterator;
77
+
78
+ //! A const iterator.
79
+ typedef Iterator<Hash const &, Entry const> const_iterator;
80
+
81
+ public:
82
+ //! Return an iterator to the beginning of the hash.
83
+ iterator begin();
84
+
85
+ //! Return a const iterator to the beginning of the hash.
86
+ const_iterator begin() const;
87
+
88
+ //! Return an iterator to the end of the hash.
89
+ iterator end();
90
+
91
+ //! Return a const to the end of the hash.
92
+ const_iterator end() const;
93
+ };
94
+
95
+ //! A helper class so hash[key]=value can work.
96
+ class Hash::Proxy
97
+ {
98
+ public:
99
+ //! Construct a new Proxy.
100
+ Proxy(Hash hash, Object key);
101
+
102
+ //! Implicit conversion to Object.
103
+ operator Object() const;
104
+
105
+ //! Explicit conversion to VALUE.
106
+ VALUE value() const;
107
+
108
+ //! Assignment operator.
109
+ template<typename T>
110
+ Object operator=(T const & value);
111
+
112
+ void swap(Proxy & proxy);
113
+
114
+ private:
115
+ Hash hash_;
116
+ Object key_;
117
+ };
118
+
119
+ //! A helper class for dereferencing iterators
120
+ /*! This class is intended to look similar to an std::pair.
121
+ */
122
+ class Hash::Entry
123
+ {
124
+ public:
125
+ //! Construct a new Entry.
126
+ Entry(Hash hash, Object key);
127
+
128
+ //! Copy constructor.
129
+ Entry(Entry const & entry);
130
+
131
+ Object const key; //!< The key
132
+ Object const & first; //!< An alias for the key
133
+
134
+ Proxy value; //!< The value
135
+ Proxy & second; //!< An alias for the value
136
+
137
+ Entry & operator=(Entry const & rhs);
138
+
139
+ void swap(Entry & entry);
140
+
141
+ friend bool operator<(Entry const & lhs, Entry const & rhs);
142
+ };
143
+
144
+ bool operator<(Hash::Entry const & lhs, Hash::Entry const & rhs);
145
+
146
+ //! A helper class for implementing iterators for a Hash.
147
+ template<typename Hash_Ref_T, typename Value_T>
148
+ class Hash::Iterator
149
+ : public std::iterator<
150
+ std::input_iterator_tag,
151
+ Value_T>
152
+ {
153
+ public:
154
+ //! Construct a new Iterator.
155
+ Iterator(Hash_Ref_T hash, size_t bin, st_table_entry * ptr);
156
+
157
+ //! Copy construct an Iterator.
158
+ Iterator(Iterator const & iterator);
159
+
160
+ //! Construct an Iterator from another Iterator of a different const
161
+ //! qualification.
162
+ template<typename Iterator_T>
163
+ Iterator(Iterator_T const & iterator);
164
+
165
+ //! Assignment operator.
166
+ Iterator & operator=(Iterator const & rhs);
167
+
168
+ //! Preincrement operator.
169
+ Iterator & operator++();
170
+
171
+ //! Postincrement operator.
172
+ Iterator operator++(int);
173
+
174
+ //! Dereference operator.
175
+ Value_T operator*();
176
+
177
+ //! Dereference operator.
178
+ Value_T * operator->();
179
+
180
+ //! Equality operator.
181
+ bool operator==(Iterator const & rhs) const;
182
+
183
+ //! Inequality operator.
184
+ bool operator!=(Iterator const & rhs) const;
185
+
186
+ template<typename Hash_Ref_T_, typename Value_T_>
187
+ friend class Hash::Iterator;
188
+
189
+ //! Swap with another iterator of the same type.
190
+ void swap(Iterator & iterator);
191
+
192
+ private:
193
+ Hash hash_;
194
+ st_table * tbl_;
195
+ int bin_;
196
+ st_table_entry * ptr_;
197
+
198
+ mutable typename detail::remove_const<Value_T>::Type tmp_;
199
+ };
200
+
201
+ } // namespace Rice
202
+
203
+ #include "Hash.ipp"
204
+
205
+ #endif // Rice__Hash__hpp_
206
+
data/rice/Hash.ipp ADDED
@@ -0,0 +1,336 @@
1
+ #ifndef Rice__Hash__ipp_
2
+ #define Rice__Hash__ipp_
3
+
4
+ #include "protect.hpp"
5
+ #include "to_from_ruby.hpp"
6
+ #include "Exception.hpp"
7
+ #include <algorithm>
8
+
9
+ // TODO: Evil hack
10
+ struct st_table_entry {
11
+ unsigned int hash;
12
+ st_data_t key;
13
+ st_data_t record;
14
+ st_table_entry *next;
15
+ };
16
+
17
+ inline Rice::Hash::
18
+ Hash()
19
+ : Builtin_Object<RHash, T_HASH>(protect(rb_hash_new))
20
+ {
21
+ }
22
+
23
+ inline Rice::Hash::
24
+ Hash(Object v)
25
+ : Builtin_Object<RHash, T_HASH>(v)
26
+ {
27
+ }
28
+
29
+ inline size_t Rice::Hash::
30
+ size() const
31
+ {
32
+ return (*this)->tbl->num_entries;
33
+ }
34
+
35
+ inline Rice::Hash::Proxy::
36
+ Proxy(Hash hash, Object key)
37
+ : hash_(hash)
38
+ , key_(key)
39
+ {
40
+ }
41
+
42
+ /*
43
+ inline Rice::Hash::Proxy::
44
+ operator VALUE() const
45
+ {
46
+ return value();
47
+ }
48
+ */
49
+
50
+ inline Rice::Hash::Proxy::
51
+ operator Rice::Object() const
52
+ {
53
+ return value();
54
+ }
55
+
56
+ inline VALUE Rice::Hash::Proxy::
57
+ value() const
58
+ {
59
+ return protect(rb_hash_aref, hash_, key_);
60
+ }
61
+
62
+ template<typename T>
63
+ inline Rice::Object Rice::Hash::Proxy::
64
+ operator=(T const & value)
65
+ {
66
+ return protect(rb_hash_aset, hash_, key_, to_ruby(value));
67
+ }
68
+
69
+ inline void Rice::Hash::Proxy::
70
+ swap(Proxy & proxy)
71
+ {
72
+ hash_.swap(proxy.hash_);
73
+ key_.swap(proxy.key_);
74
+ }
75
+
76
+ template<typename Key_T>
77
+ inline Rice::Hash::Proxy const Rice::Hash::
78
+ operator[](Key_T const & key) const
79
+ {
80
+ return Proxy(*this, to_ruby(key));
81
+ }
82
+
83
+ template<typename Key_T>
84
+ inline Rice::Hash::Proxy Rice::Hash::
85
+ operator[](Key_T const & key)
86
+ {
87
+ return Proxy(*this, to_ruby(key));
88
+ }
89
+
90
+ template<typename Value_T, typename Key_T>
91
+ inline Value_T Rice::Hash::
92
+ get(Key_T const & key)
93
+ {
94
+ Object ruby_key(to_ruby(key));
95
+ Object value = operator[](ruby_key);
96
+ try
97
+ {
98
+ return from_ruby<Value_T>(value);
99
+ }
100
+ catch(Exception const & ex)
101
+ {
102
+ String s_key(ruby_key.to_s());
103
+ throw Exception(
104
+ ex,
105
+ "%s while converting value for key %s",
106
+ ex.what(),
107
+ s_key.c_str());
108
+ }
109
+ }
110
+
111
+ inline Rice::Hash::Entry::
112
+ Entry(Hash hash, Object key)
113
+ : key(key)
114
+ , first(Hash::Entry::key)
115
+ , value(hash, key)
116
+ , second(Hash::Entry::value)
117
+ {
118
+ }
119
+
120
+ inline Rice::Hash::Entry::
121
+ Entry(Entry const & entry)
122
+ : key(entry.key)
123
+ , first(Hash::Entry::key)
124
+ , value(entry.value)
125
+ , second(Hash::Entry::value)
126
+ {
127
+ }
128
+
129
+ inline Rice::Hash::Entry & Rice::Hash::Entry::
130
+ operator=(Rice::Hash::Entry const & rhs)
131
+ {
132
+ Entry tmp(rhs);
133
+ swap(tmp);
134
+ return *this;
135
+ }
136
+
137
+ inline void Rice::Hash::Entry::
138
+ swap(Rice::Hash::Entry & entry)
139
+ {
140
+ const_cast<Object &>(key).swap(const_cast<Object &>(entry.key));
141
+ value.swap(entry.value);
142
+ }
143
+
144
+ template<typename Hash_Ref_T, typename Value_T>
145
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
146
+ Iterator(Hash_Ref_T hash, size_t bin, st_table_entry * ptr)
147
+ : hash_(hash)
148
+ , tbl_(RHASH(hash.value())->tbl)
149
+ , bin_(bin)
150
+ , ptr_(ptr)
151
+ , tmp_(hash, Qnil)
152
+ {
153
+ // If we aren't already at the end, then use the increment operator to
154
+ // point to the first element
155
+ if(!ptr_ && bin_ < tbl_->num_bins)
156
+ {
157
+ operator++();
158
+ }
159
+ }
160
+
161
+ template<typename Hash_Ref_T, typename Value_T>
162
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
163
+ Iterator(Iterator const & iterator)
164
+ : hash_(iterator.hash_.value())
165
+ , tbl_(iterator.tbl_)
166
+ , bin_(iterator.bin_)
167
+ , ptr_(iterator.ptr_)
168
+ , tmp_(iterator.hash_, Qnil)
169
+ {
170
+ }
171
+
172
+ template<typename Hash_Ref_T, typename Value_T>
173
+ template<typename Iterator_T>
174
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
175
+ Iterator(Iterator_T const & iterator)
176
+ : hash_(iterator.hash_.value())
177
+ , tbl_(iterator.tbl_)
178
+ , bin_(iterator.bin_)
179
+ , ptr_(iterator.ptr_)
180
+ , tmp_(iterator.hash_, Qnil)
181
+ {
182
+ }
183
+
184
+ template<typename Hash_Ref_T, typename Value_T>
185
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T> &
186
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
187
+ operator=(Iterator const & iterator)
188
+ {
189
+ Iterator tmp(iterator);
190
+
191
+ this->swap(tmp);
192
+
193
+ return *this;
194
+ }
195
+
196
+ template<typename Hash_Ref_T, typename Value_T>
197
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T> &
198
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
199
+ operator++()
200
+ {
201
+ // Go to the next element in the bin; this will be a no-op if we were
202
+ // called from the constructor, because ptr_ will be 0 (and if its
203
+ // not, this function won't get called).
204
+ if(ptr_)
205
+ {
206
+ ptr_ = ptr_->next;
207
+ }
208
+
209
+ // If we've reached the end of the bin, then try the next bin until
210
+ // we have run out of bins
211
+ while(ptr_ == 0)
212
+ {
213
+ ++bin_;
214
+ if(bin_ == tbl_->num_bins)
215
+ {
216
+ // At the end..
217
+ return *this;
218
+ }
219
+ ptr_ = tbl_->bins[bin_];
220
+ }
221
+
222
+ return *this;
223
+ }
224
+
225
+ template<typename Hash_Ref_T, typename Value_T>
226
+ inline Rice::Hash::Iterator<Hash_Ref_T, Value_T>
227
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
228
+ operator++(int)
229
+ {
230
+ Iterator copy(*this);
231
+ ++(*this);
232
+ return copy;
233
+ }
234
+
235
+ template<typename Hash_Ref_T, typename Value_T>
236
+ inline Value_T
237
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
238
+ operator*()
239
+ {
240
+ return Value_T(hash_, ptr_->key);
241
+ }
242
+
243
+ template<typename Hash_Ref_T, typename Value_T>
244
+ inline Value_T *
245
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
246
+ operator->()
247
+ {
248
+ Entry tmp(hash_, ptr_->key);
249
+ this->tmp_.swap(tmp);
250
+ return &tmp_;
251
+ }
252
+
253
+ template<typename Hash_Ref_T, typename Value_T>
254
+ inline bool Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
255
+ operator==(Iterator const & rhs) const
256
+ {
257
+ return hash_.value() == rhs.hash_.value()
258
+ && tbl_ == rhs.tbl_
259
+ && bin_ == rhs.bin_
260
+ && ptr_ == rhs.ptr_;
261
+ }
262
+
263
+ template<typename Hash_Ref_T, typename Value_T>
264
+ inline bool Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
265
+ operator!=(Iterator const & rhs) const
266
+ {
267
+ return !(*this == rhs);
268
+ }
269
+
270
+ template<typename Hash_Ref_T, typename Value_T>
271
+ inline void
272
+ Rice::Hash::Iterator<Hash_Ref_T, Value_T>::
273
+ swap(Iterator& iterator)
274
+ {
275
+ using namespace std;
276
+
277
+ hash_.swap(iterator.hash_);
278
+ swap(tbl_, iterator.tbl_);
279
+ swap(bin_, iterator.bin_);
280
+ swap(ptr_, iterator.ptr_);
281
+ }
282
+
283
+ inline Rice::Hash::iterator Rice::Hash::
284
+ begin()
285
+ {
286
+ st_table * tbl(RHASH(value())->tbl);
287
+ return iterator(*this, 0, tbl->bins[0]);
288
+ }
289
+
290
+ inline Rice::Hash::const_iterator Rice::Hash::
291
+ begin() const
292
+ {
293
+ st_table * tbl(RHASH(value())->tbl);
294
+ return const_iterator(*this, 0, tbl->bins[0]);
295
+ }
296
+
297
+ inline Rice::Hash::iterator Rice::Hash::
298
+ end()
299
+ {
300
+ st_table * tbl(RHASH(value())->tbl);
301
+ return iterator(*this, tbl->num_bins, 0);
302
+ }
303
+
304
+ inline Rice::Hash::const_iterator Rice::Hash::
305
+ end() const
306
+ {
307
+ st_table * tbl(RHASH(value())->tbl);
308
+ return const_iterator(*this, tbl->num_bins, 0);
309
+ }
310
+
311
+ inline bool Rice::
312
+ operator<(
313
+ Hash::Entry const & lhs, Hash::Entry const & rhs)
314
+ {
315
+ Object lhs_key(lhs.key);
316
+ Object rhs_key(rhs.key);
317
+ if(lhs_key < rhs_key)
318
+ {
319
+ return true;
320
+ }
321
+ else if(lhs_key > rhs_key)
322
+ {
323
+ return false;
324
+ }
325
+ else if(Object(lhs.value.value()) < Object(rhs.value.value()))
326
+ {
327
+ return true;
328
+ }
329
+ else
330
+ {
331
+ return false;
332
+ }
333
+ }
334
+
335
+ #endif // Rice__Hash__ipp_
336
+