wurlinc-rice 1.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/README +1119 -0
  5. data/README.mingw +8 -0
  6. data/Rakefile +33 -0
  7. data/bootstrap +9 -0
  8. data/configure.ac +52 -0
  9. data/doxygen.ac +314 -0
  10. data/doxygen.am +186 -0
  11. data/extconf.rb +41 -0
  12. data/post-autoconf.rb +22 -0
  13. data/post-automake.rb +28 -0
  14. data/rice/Address_Registration_Guard.hpp +7 -0
  15. data/rice/Address_Registration_Guard.ipp +34 -0
  16. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  17. data/rice/Allocation_Strategies.hpp +37 -0
  18. data/rice/Arg.hpp +8 -0
  19. data/rice/Arg_impl.hpp +127 -0
  20. data/rice/Arg_operators.cpp +21 -0
  21. data/rice/Arg_operators.hpp +19 -0
  22. data/rice/Array.hpp +220 -0
  23. data/rice/Array.ipp +263 -0
  24. data/rice/Builtin_Object.hpp +8 -0
  25. data/rice/Builtin_Object.ipp +50 -0
  26. data/rice/Builtin_Object_defn.hpp +51 -0
  27. data/rice/Class.cpp +57 -0
  28. data/rice/Class.hpp +8 -0
  29. data/rice/Class.ipp +6 -0
  30. data/rice/Class_defn.hpp +83 -0
  31. data/rice/Constructor.hpp +367 -0
  32. data/rice/Critical_Guard.hpp +40 -0
  33. data/rice/Critical_Guard.ipp +26 -0
  34. data/rice/Data_Object.hpp +8 -0
  35. data/rice/Data_Object.ipp +133 -0
  36. data/rice/Data_Object_defn.hpp +132 -0
  37. data/rice/Data_Type.cpp +54 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +365 -0
  40. data/rice/Data_Type_defn.hpp +261 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Director.cpp +13 -0
  43. data/rice/Director.hpp +39 -0
  44. data/rice/Enum.hpp +117 -0
  45. data/rice/Enum.ipp +246 -0
  46. data/rice/Exception.cpp +59 -0
  47. data/rice/Exception.hpp +9 -0
  48. data/rice/Exception_Base.hpp +8 -0
  49. data/rice/Exception_Base.ipp +13 -0
  50. data/rice/Exception_Base_defn.hpp +27 -0
  51. data/rice/Exception_defn.hpp +69 -0
  52. data/rice/Hash.hpp +210 -0
  53. data/rice/Hash.ipp +338 -0
  54. data/rice/Identifier.cpp +8 -0
  55. data/rice/Identifier.hpp +50 -0
  56. data/rice/Identifier.ipp +33 -0
  57. data/rice/Jump_Tag.hpp +24 -0
  58. data/rice/Makefile.am +129 -0
  59. data/rice/Module.cpp +84 -0
  60. data/rice/Module.hpp +8 -0
  61. data/rice/Module.ipp +6 -0
  62. data/rice/Module_defn.hpp +88 -0
  63. data/rice/Module_impl.hpp +281 -0
  64. data/rice/Module_impl.ipp +348 -0
  65. data/rice/Object.cpp +160 -0
  66. data/rice/Object.hpp +8 -0
  67. data/rice/Object.ipp +19 -0
  68. data/rice/Object_defn.hpp +191 -0
  69. data/rice/Require_Guard.hpp +21 -0
  70. data/rice/String.cpp +94 -0
  71. data/rice/String.hpp +89 -0
  72. data/rice/Struct.cpp +117 -0
  73. data/rice/Struct.hpp +162 -0
  74. data/rice/Struct.ipp +26 -0
  75. data/rice/Symbol.cpp +25 -0
  76. data/rice/Symbol.hpp +66 -0
  77. data/rice/Symbol.ipp +44 -0
  78. data/rice/VM.cpp +92 -0
  79. data/rice/VM.hpp +32 -0
  80. data/rice/config.hpp.in +40 -0
  81. data/rice/detail/Arguments.hpp +118 -0
  82. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  83. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  84. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  85. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  86. data/rice/detail/Caster.hpp +103 -0
  87. data/rice/detail/Exception_Handler.hpp +8 -0
  88. data/rice/detail/Exception_Handler.ipp +68 -0
  89. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  90. data/rice/detail/Iterator.hpp +93 -0
  91. data/rice/detail/Not_Copyable.hpp +25 -0
  92. data/rice/detail/Wrapped_Function.hpp +33 -0
  93. data/rice/detail/cfp.hpp +24 -0
  94. data/rice/detail/cfp.ipp +51 -0
  95. data/rice/detail/check_ruby_type.cpp +27 -0
  96. data/rice/detail/check_ruby_type.hpp +23 -0
  97. data/rice/detail/creation_funcs.hpp +37 -0
  98. data/rice/detail/creation_funcs.ipp +36 -0
  99. data/rice/detail/default_allocation_func.hpp +23 -0
  100. data/rice/detail/default_allocation_func.ipp +11 -0
  101. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  102. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  103. data/rice/detail/demangle.cpp +56 -0
  104. data/rice/detail/demangle.hpp +19 -0
  105. data/rice/detail/env.hpp +19 -0
  106. data/rice/detail/from_ruby.hpp +43 -0
  107. data/rice/detail/from_ruby.ipp +60 -0
  108. data/rice/detail/method_data.cpp +159 -0
  109. data/rice/detail/method_data.hpp +21 -0
  110. data/rice/detail/mininode.cpp +1220 -0
  111. data/rice/detail/mininode.hpp +320 -0
  112. data/rice/detail/node.hpp +13 -0
  113. data/rice/detail/object_call.hpp +68 -0
  114. data/rice/detail/object_call.ipp +131 -0
  115. data/rice/detail/protect.cpp +29 -0
  116. data/rice/detail/protect.hpp +34 -0
  117. data/rice/detail/ruby.hpp +93 -0
  118. data/rice/detail/ruby_version_code.hpp.in +6 -0
  119. data/rice/detail/rubysig.hpp +19 -0
  120. data/rice/detail/st.hpp +60 -0
  121. data/rice/detail/to_ruby.hpp +22 -0
  122. data/rice/detail/to_ruby.ipp +36 -0
  123. data/rice/detail/traits.hpp +43 -0
  124. data/rice/detail/win32.hpp +16 -0
  125. data/rice/detail/wrap_function.hpp +341 -0
  126. data/rice/detail/wrap_function.ipp +514 -0
  127. data/rice/global_function.hpp +33 -0
  128. data/rice/global_function.ipp +22 -0
  129. data/rice/protect.hpp +91 -0
  130. data/rice/protect.ipp +1133 -0
  131. data/rice/ruby_mark.hpp +13 -0
  132. data/rice/ruby_try_catch.hpp +86 -0
  133. data/rice/rubypp.rb +97 -0
  134. data/rice/to_from_ruby.hpp +8 -0
  135. data/rice/to_from_ruby.ipp +297 -0
  136. data/rice/to_from_ruby_defn.hpp +71 -0
  137. data/ruby/Makefile.am +1 -0
  138. data/ruby/lib/Makefile.am +3 -0
  139. data/ruby/lib/mkmf-rice.rb.in +216 -0
  140. data/ruby/lib/version.rb +3 -0
  141. data/ruby.ac +136 -0
  142. data/sample/Makefile.am +47 -0
  143. data/sample/enum/extconf.rb +3 -0
  144. data/sample/enum/sample_enum.cpp +54 -0
  145. data/sample/enum/test.rb +8 -0
  146. data/sample/inheritance/animals.cpp +98 -0
  147. data/sample/inheritance/extconf.rb +3 -0
  148. data/sample/inheritance/test.rb +7 -0
  149. data/sample/map/extconf.rb +3 -0
  150. data/sample/map/map.cpp +81 -0
  151. data/sample/map/test.rb +7 -0
  152. data/test/Makefile.am +78 -0
  153. data/test/ext/Makefile.am +43 -0
  154. data/test/ext/t1/Foo.hpp +10 -0
  155. data/test/ext/t1/extconf.rb +2 -0
  156. data/test/ext/t1/t1.cpp +15 -0
  157. data/test/ext/t2/extconf.rb +2 -0
  158. data/test/ext/t2/t2.cpp +11 -0
  159. data/test/test_Address_Registration_Guard.cpp +43 -0
  160. data/test/test_Allocation_Strategies.cpp +77 -0
  161. data/test/test_Array.cpp +241 -0
  162. data/test/test_Builtin_Object.cpp +72 -0
  163. data/test/test_Class.cpp +498 -0
  164. data/test/test_Constructor.cpp +128 -0
  165. data/test/test_Critical_Guard.cpp +51 -0
  166. data/test/test_Data_Object.cpp +275 -0
  167. data/test/test_Data_Type.cpp +348 -0
  168. data/test/test_Director.cpp +301 -0
  169. data/test/test_Enum.cpp +195 -0
  170. data/test/test_Exception.cpp +46 -0
  171. data/test/test_Hash.cpp +195 -0
  172. data/test/test_Identifier.cpp +70 -0
  173. data/test/test_Jump_Tag.cpp +17 -0
  174. data/test/test_Memory_Management.cpp +50 -0
  175. data/test/test_Module.cpp +481 -0
  176. data/test/test_Object.cpp +148 -0
  177. data/test/test_String.cpp +94 -0
  178. data/test/test_Struct.cpp +192 -0
  179. data/test/test_Symbol.cpp +63 -0
  180. data/test/test_To_From_Ruby.cpp +263 -0
  181. data/test/test_VM.cpp +26 -0
  182. data/test/test_global_functions.cpp +114 -0
  183. data/test/test_rice.rb +43 -0
  184. data/test/unittest.cpp +136 -0
  185. data/test/unittest.hpp +292 -0
  186. metadata +276 -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,9 @@
1
+ #ifndef Rice__Exception__hpp_
2
+ #define Rice__Exception__hpp_
3
+
4
+ #include "Exception_defn.hpp"
5
+ #include "Exception_Base.hpp"
6
+ #include "Address_Registration_Guard.hpp"
7
+
8
+ #endif // Rice__Exception__hpp_
9
+
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__Exception_Base__hpp_
2
+ #define Rice__Exception_Base__hpp_
3
+
4
+ #include "Exception_Base_defn.hpp"
5
+ #include "Exception_Base.ipp"
6
+
7
+ #endif // Rice__Exception_Base__hpp_
8
+
@@ -0,0 +1,13 @@
1
+ #include "Object.hpp"
2
+
3
+ inline Rice::Exception_Base::
4
+ Exception_Base(VALUE v)
5
+ : Object(v)
6
+ {
7
+ }
8
+
9
+ inline Rice::Exception_Base::
10
+ ~Exception_Base() throw()
11
+ {
12
+ }
13
+
@@ -0,0 +1,27 @@
1
+ #ifndef Rice__Exception_Base_defn__hpp_
2
+ #define Rice__Exception_Base_defn__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
+ #endif // Rice__Exception_Base_defn__hpp_
@@ -0,0 +1,69 @@
1
+ #ifndef Rice__Exception_defn__hpp_
2
+ #define Rice__Exception_defn__hpp_
3
+
4
+ #include "Exception_Base_defn.hpp"
5
+ #include "String.hpp"
6
+ #include "Address_Registration_Guard_defn.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_defn__hpp_
69
+
data/rice/Hash.hpp ADDED
@@ -0,0 +1,210 @@
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/traits.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, st_data_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
+ #if RICE__RUBY_VERSION_CODE >= 190
196
+ st_index_t bin_;
197
+ #else
198
+ int bin_;
199
+ #endif
200
+ st_table_entry * ptr_;
201
+
202
+ mutable typename detail::remove_const<Value_T>::Type tmp_;
203
+ };
204
+
205
+ } // namespace Rice
206
+
207
+ #include "Hash.ipp"
208
+
209
+ #endif // Rice__Hash__hpp_
210
+