rice 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +736 -0
- data/README +881 -0
- data/README.mingw +8 -0
- data/bootstrap +8 -0
- data/config.guess +1535 -0
- data/config.sub +1644 -0
- data/configure +7310 -0
- data/configure.ac +48 -0
- data/depcomp +584 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/install-sh +507 -0
- data/missing +367 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +262 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +4 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +189 -0
- data/rice/Critical_Guard.hpp +34 -0
- data/rice/Critical_Guard.ipp +20 -0
- data/rice/Data_Object.hpp +127 -0
- data/rice/Data_Object.ipp +129 -0
- data/rice/Data_Type.cpp +21 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +227 -0
- data/rice/Data_Type_defn.hpp +219 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Enum.hpp +118 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +69 -0
- data/rice/Exception_Base.hpp +30 -0
- data/rice/Exception_Base.ipp +11 -0
- data/rice/Hash.hpp +206 -0
- data/rice/Hash.ipp +336 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +112 -0
- data/rice/Makefile.in +675 -0
- data/rice/Module.cpp +75 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +87 -0
- data/rice/Module_impl.hpp +237 -0
- data/rice/Module_impl.ipp +302 -0
- data/rice/Object.cpp +153 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +183 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +93 -0
- data/rice/String.hpp +88 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/VM.cpp +79 -0
- data/rice/VM.hpp +27 -0
- data/rice/config.hpp +23 -0
- data/rice/config.hpp.in +22 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
- data/rice/detail/Caster.hpp +61 -0
- data/rice/detail/Exception_Handler.hpp +118 -0
- data/rice/detail/Iterator_Definer.hpp +98 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/check_ruby_type.cpp +21 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +45 -0
- data/rice/detail/creation_funcs.ipp +62 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
- data/rice/detail/env.hpp +13 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +74 -0
- data/rice/detail/method_data.cpp +105 -0
- data/rice/detail/method_data.hpp +33 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +85 -0
- data/rice/detail/object_call.ipp +147 -0
- data/rice/detail/protect.cpp +27 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/remove_const.hpp +21 -0
- data/rice/detail/ruby.hpp +85 -0
- data/rice/detail/rubysig.hpp +13 -0
- data/rice/detail/st.hpp +56 -0
- data/rice/detail/to_ruby.hpp +16 -0
- data/rice/detail/to_ruby.ipp +10 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +288 -0
- data/rice/detail/wrap_function.ipp +473 -0
- data/rice/generate_code.rb +1092 -0
- data/rice/global_function.hpp +16 -0
- data/rice/global_function.ipp +11 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +803 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +299 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby.ac +105 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +493 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +369 -0
- data/ruby/lib/mkmf-rice.rb.in +199 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +375 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +44 -0
- data/test/Makefile.in +575 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +350 -0
- data/test/test_Constructor.cpp +30 -0
- data/test/test_Critical_Guard.cpp +47 -0
- data/test/test_Data_Object.cpp +235 -0
- data/test/test_Enum.cpp +162 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Module.cpp +253 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +281 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_rice.rb +30 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +209 -0
data/rice/String.hpp
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#ifndef Rice__String__hpp_
|
2
|
+
#define Rice__String__hpp_
|
3
|
+
|
4
|
+
#include "Identifier.hpp"
|
5
|
+
#include "Builtin_Object.hpp"
|
6
|
+
#include "detail/ruby.hpp"
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
namespace Rice
|
10
|
+
{
|
11
|
+
|
12
|
+
//! A Wraper for the ruby String class.
|
13
|
+
/*! This class provides a C++-style interface to ruby's String class and
|
14
|
+
* its associated rb_str_* functions.
|
15
|
+
*
|
16
|
+
* Example:
|
17
|
+
* \code
|
18
|
+
* String s(String::format("%s: %d", "foo", 42));
|
19
|
+
* std::cout << s.length() << std::endl;
|
20
|
+
* \endcode
|
21
|
+
*/
|
22
|
+
class String
|
23
|
+
: public Builtin_Object<RString, T_STRING>
|
24
|
+
{
|
25
|
+
public:
|
26
|
+
//! Construct a new string.
|
27
|
+
String();
|
28
|
+
|
29
|
+
//! Wrap an existing string.
|
30
|
+
String(VALUE v);
|
31
|
+
|
32
|
+
//! Wrap an existing string.
|
33
|
+
String(Object v);
|
34
|
+
|
35
|
+
//! Construct a String from an Identifier.
|
36
|
+
String(Identifier id);
|
37
|
+
|
38
|
+
//! Construct a String from a null-terminated C string.
|
39
|
+
String(char const * s);
|
40
|
+
|
41
|
+
//! Construct a String from an std::string.
|
42
|
+
String(std::string const & s);
|
43
|
+
|
44
|
+
//! Format a string using printf-style formatting.
|
45
|
+
static String format(char const * s, ...);
|
46
|
+
|
47
|
+
//! Get the length of the String.
|
48
|
+
/*! \return the length of the string.
|
49
|
+
*/
|
50
|
+
size_t length() const;
|
51
|
+
|
52
|
+
//! Get the character at the given index.
|
53
|
+
/*! \param index the desired index.
|
54
|
+
* \return the character at the given index.
|
55
|
+
*/
|
56
|
+
char operator[](ptrdiff_t index) const;
|
57
|
+
|
58
|
+
//! Return a pointer to the beginning of the underlying C string.
|
59
|
+
char const * c_str() const;
|
60
|
+
|
61
|
+
//! Return a copy of the string as an std::string.
|
62
|
+
std::string str() const;
|
63
|
+
|
64
|
+
//! Create an Identifier from the String.
|
65
|
+
/*! Calls rb_intern to create an ID.
|
66
|
+
* \return an Identifier holding the ID returned from rb_intern.
|
67
|
+
*/
|
68
|
+
Identifier intern() const;
|
69
|
+
};
|
70
|
+
|
71
|
+
} // namespace Rice
|
72
|
+
|
73
|
+
template<>
|
74
|
+
inline
|
75
|
+
Rice::String from_ruby<Rice::String>(Rice::Object x)
|
76
|
+
{
|
77
|
+
return Rice::String(x);
|
78
|
+
}
|
79
|
+
|
80
|
+
template<>
|
81
|
+
inline
|
82
|
+
Rice::Object to_ruby<Rice::String>(Rice::String const & x)
|
83
|
+
{
|
84
|
+
return x;
|
85
|
+
}
|
86
|
+
|
87
|
+
#endif // Rice__String__hpp_
|
88
|
+
|
data/rice/Struct.cpp
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#include "Struct.hpp"
|
2
|
+
#include "Symbol.hpp"
|
3
|
+
|
4
|
+
#include <stdexcept>
|
5
|
+
|
6
|
+
Rice::Struct::
|
7
|
+
Struct()
|
8
|
+
: Module_impl<Class, Struct>(rb_cObject)
|
9
|
+
, members_()
|
10
|
+
, members_guard_(&members_)
|
11
|
+
, member_offset_()
|
12
|
+
, member_offset_guard_(&member_offset_)
|
13
|
+
{
|
14
|
+
}
|
15
|
+
|
16
|
+
Rice::Struct::
|
17
|
+
Struct(Rice::Struct const & s)
|
18
|
+
: Module_impl<Class, Struct>(s)
|
19
|
+
, members_(s.members_.value())
|
20
|
+
, members_guard_(&members_)
|
21
|
+
, member_offset_(s.member_offset_.value())
|
22
|
+
, member_offset_guard_(&member_offset_)
|
23
|
+
{
|
24
|
+
}
|
25
|
+
|
26
|
+
Rice::Struct::
|
27
|
+
~Struct()
|
28
|
+
{
|
29
|
+
}
|
30
|
+
|
31
|
+
Rice::Struct & Rice::Struct::
|
32
|
+
initialize(
|
33
|
+
Module module,
|
34
|
+
Identifier name)
|
35
|
+
{
|
36
|
+
Class struct_class(rb_cStruct);
|
37
|
+
Object type = struct_class.vcall("new", members_);
|
38
|
+
|
39
|
+
set_value(type);
|
40
|
+
module.const_set(name, type);
|
41
|
+
|
42
|
+
return *this;
|
43
|
+
}
|
44
|
+
|
45
|
+
Rice::Struct & Rice::Struct::
|
46
|
+
define_member(
|
47
|
+
Identifier name)
|
48
|
+
{
|
49
|
+
if(value() != rb_cObject)
|
50
|
+
{
|
51
|
+
throw std::runtime_error("struct is already initialized");
|
52
|
+
}
|
53
|
+
|
54
|
+
// TODO: not exception-safe
|
55
|
+
Symbol ruby_name(name);
|
56
|
+
member_offset_[ruby_name] = members_.size();
|
57
|
+
members_.push(ruby_name);
|
58
|
+
|
59
|
+
return *this;
|
60
|
+
}
|
61
|
+
|
62
|
+
size_t Rice::Struct::
|
63
|
+
offset_of(Identifier name) const
|
64
|
+
{
|
65
|
+
Symbol ruby_name(name);
|
66
|
+
return from_ruby<size_t>(member_offset_[ruby_name]);
|
67
|
+
}
|
68
|
+
|
69
|
+
void Rice::Struct::
|
70
|
+
swap(Rice::Struct & other)
|
71
|
+
{
|
72
|
+
members_.swap(other.members_);
|
73
|
+
members_guard_.swap(other.members_guard_);
|
74
|
+
member_offset_.swap(other.member_offset_);
|
75
|
+
member_offset_guard_.swap(other.member_offset_guard_);
|
76
|
+
Class::swap(other);
|
77
|
+
}
|
78
|
+
|
79
|
+
Rice::Struct::Instance
|
80
|
+
Rice::Struct::
|
81
|
+
new_instance(Array args) const
|
82
|
+
{
|
83
|
+
Object instance = const_cast<Struct *>(this)->vcall("new", args);
|
84
|
+
return Instance(*this, instance);
|
85
|
+
}
|
86
|
+
|
87
|
+
Rice::Struct::Instance::
|
88
|
+
Instance(
|
89
|
+
Struct const & type,
|
90
|
+
Array args)
|
91
|
+
: Builtin_Object<RStruct, T_STRUCT>(type.new_instance(args))
|
92
|
+
, type_(type)
|
93
|
+
{
|
94
|
+
}
|
95
|
+
|
96
|
+
Rice::Struct::Instance::
|
97
|
+
Instance(
|
98
|
+
Struct const & type,
|
99
|
+
Object s)
|
100
|
+
: Builtin_Object<RStruct, T_STRUCT>(s)
|
101
|
+
, type_(type)
|
102
|
+
{
|
103
|
+
}
|
104
|
+
|
105
|
+
void Rice::Struct::Instance::
|
106
|
+
swap(Instance & other)
|
107
|
+
{
|
108
|
+
type_.swap(other.type_);
|
109
|
+
Builtin_Object<RStruct, T_STRUCT>::swap(other);
|
110
|
+
}
|
111
|
+
|
112
|
+
Rice::Struct Rice::
|
113
|
+
define_struct()
|
114
|
+
{
|
115
|
+
return Struct();
|
116
|
+
}
|
117
|
+
|
data/rice/Struct.hpp
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
#ifndef Rice__ruby_struct__hpp_
|
2
|
+
#define Ruplu__ruby_struct__hpp_
|
3
|
+
|
4
|
+
#include "Array.hpp"
|
5
|
+
#include "Hash.hpp"
|
6
|
+
#include "Module.hpp"
|
7
|
+
#include "Class.hpp"
|
8
|
+
#include "Builtin_Object.hpp"
|
9
|
+
#include "Address_Registration_Guard.hpp"
|
10
|
+
|
11
|
+
namespace Rice
|
12
|
+
{
|
13
|
+
class Struct;
|
14
|
+
|
15
|
+
//! Define a new Struct
|
16
|
+
Struct define_struct();
|
17
|
+
|
18
|
+
//! A wrapper for creating Struct classes.
|
19
|
+
/*! The Struct class is used for creating new Classes. Note that the
|
20
|
+
* notation used here differs slightly from the notation inside the
|
21
|
+
* interpreter.
|
22
|
+
*
|
23
|
+
* Inside the interpreter, calling Struct.new creates a new Class:
|
24
|
+
* \code
|
25
|
+
* irb(main):001:0> MyStruct = Struct.new(:a, :b, :c)
|
26
|
+
* => S
|
27
|
+
* irb(main):002:0> MyStruct.class
|
28
|
+
* => Class
|
29
|
+
* \endcode
|
30
|
+
*
|
31
|
+
* Instantiating that Class creates an instance of that Class:
|
32
|
+
* \code
|
33
|
+
* irb(main):003:0> mystruct_instance = MyStruct.new
|
34
|
+
* => #<struct MyStruct a=nil, b=nil, c=nil>
|
35
|
+
* irb(main):004:0> mystruct_instance.class
|
36
|
+
* => MyStruct
|
37
|
+
* irb(main):005:0> mystruct_instance.class.ancestors
|
38
|
+
* => [MyStruct, Struct, Enumerable, Object, Kernel]
|
39
|
+
* \endcode
|
40
|
+
*
|
41
|
+
* Thus, inside the interpreter, MyStruct is a Class which inherits
|
42
|
+
* from Struct, and mystruct_instance is an instance of MyStruct.
|
43
|
+
*
|
44
|
+
* At the C++ level, we might do this instead:
|
45
|
+
* \code
|
46
|
+
* Struct rb_cMyStruct = define_struct()
|
47
|
+
* .define_member("a")
|
48
|
+
* .define_member("b")
|
49
|
+
* .define_member("c")
|
50
|
+
* .initialize("MyStruct");
|
51
|
+
* Struct::Instance mystruct_instance(rb_cMyStruct.new_instance());
|
52
|
+
* \endcode
|
53
|
+
*
|
54
|
+
* Here rb_cMyStruct is an instance of Struct and that mystruct_instance
|
55
|
+
* is an instance of Struct::Instance.
|
56
|
+
*/
|
57
|
+
class Struct
|
58
|
+
: public Module_impl<Class, Struct>
|
59
|
+
{
|
60
|
+
public:
|
61
|
+
//! Create a new Struct.
|
62
|
+
Struct();
|
63
|
+
|
64
|
+
//! Copy constructor.
|
65
|
+
Struct(Struct const & s);
|
66
|
+
|
67
|
+
//! Destructor.
|
68
|
+
virtual ~Struct();
|
69
|
+
|
70
|
+
//! Define a new Struct member.
|
71
|
+
/*! Defines a new member of the Struct. Must be called before the
|
72
|
+
* Struct is initialized.
|
73
|
+
* \return *this
|
74
|
+
*/
|
75
|
+
Struct & define_member(
|
76
|
+
Identifier name);
|
77
|
+
|
78
|
+
//! Initialize the Struct class.
|
79
|
+
/*! Must be called after all Struct members have been defined.
|
80
|
+
* \param module the module under which to define the Struct.
|
81
|
+
* \param name the name of the Class at the ruby level.
|
82
|
+
*/
|
83
|
+
Struct & initialize(
|
84
|
+
Module module,
|
85
|
+
Identifier name);
|
86
|
+
|
87
|
+
//! Get the offset of a member in the Struct.
|
88
|
+
/*! Internally, Struct members are stored as a single array of VALUE.
|
89
|
+
* This function determines the offset of a given member in that
|
90
|
+
* array.
|
91
|
+
* \param member the name of the desired member.
|
92
|
+
* \return the index of the given member.
|
93
|
+
*/
|
94
|
+
size_t offset_of(Identifier name) const;
|
95
|
+
|
96
|
+
class Instance;
|
97
|
+
friend class Instance;
|
98
|
+
friend Struct Rice::define_struct();
|
99
|
+
|
100
|
+
//! Create a new instance of the Struct
|
101
|
+
/*! \param args the arguments to the constructor.
|
102
|
+
* \return a new Struct::Instance
|
103
|
+
*/
|
104
|
+
Instance new_instance(Array args = Array()) const;
|
105
|
+
|
106
|
+
//! Swap with another Struct.
|
107
|
+
void swap(Struct & other);
|
108
|
+
|
109
|
+
Array members() const { return members_; }
|
110
|
+
|
111
|
+
private:
|
112
|
+
Array members_;
|
113
|
+
Address_Registration_Guard members_guard_;
|
114
|
+
|
115
|
+
Hash member_offset_;
|
116
|
+
Address_Registration_Guard member_offset_guard_;
|
117
|
+
};
|
118
|
+
|
119
|
+
|
120
|
+
//! An instance of a Struct
|
121
|
+
//! \sa Struct
|
122
|
+
class Struct::Instance
|
123
|
+
: public Builtin_Object<RStruct, T_STRUCT>
|
124
|
+
{
|
125
|
+
public:
|
126
|
+
//! Create a new Instance of a Struct.
|
127
|
+
/*! \param type the Struct type to create.
|
128
|
+
* \param args the initial values for the objects of the instance.
|
129
|
+
*/
|
130
|
+
Instance(
|
131
|
+
Struct const & type,
|
132
|
+
Array args = Array());
|
133
|
+
|
134
|
+
//! Encapsulate an existing Struct instance.
|
135
|
+
/*! \param type the Struct type to encapsulate.
|
136
|
+
* \param s the instance to encapsulate.
|
137
|
+
*/
|
138
|
+
Instance(
|
139
|
+
Struct const & type,
|
140
|
+
Object s);
|
141
|
+
|
142
|
+
//! Get a member, given its offset.
|
143
|
+
/*! \param index the (integral) index into the Struct's internal
|
144
|
+
* array or its name (an Identifier or char const *)
|
145
|
+
* \return the member.
|
146
|
+
*/
|
147
|
+
template<typename T>
|
148
|
+
Object operator[](T index);
|
149
|
+
|
150
|
+
//! Swap with another Struct::Instance.
|
151
|
+
void swap(Instance & other);
|
152
|
+
|
153
|
+
private:
|
154
|
+
Struct type_;
|
155
|
+
};
|
156
|
+
|
157
|
+
} // namespace Rice
|
158
|
+
|
159
|
+
#include "Struct.ipp"
|
160
|
+
|
161
|
+
#endif // Rice__ruby_struct__hpp_
|
162
|
+
|
data/rice/Struct.ipp
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace Rice
|
2
|
+
{
|
3
|
+
|
4
|
+
template<typename T>
|
5
|
+
inline Object Struct::Instance::
|
6
|
+
operator[](T index)
|
7
|
+
{
|
8
|
+
return rb_struct_aref(value(), ULONG2NUM(index));
|
9
|
+
}
|
10
|
+
|
11
|
+
template<>
|
12
|
+
inline Object Struct::Instance::
|
13
|
+
operator[]<Identifier>(Identifier member)
|
14
|
+
{
|
15
|
+
size_t index = type_.offset_of(member);
|
16
|
+
return (*this)[index];
|
17
|
+
}
|
18
|
+
|
19
|
+
template<>
|
20
|
+
inline Object Struct::Instance::
|
21
|
+
operator[]<char const *>(char const * name)
|
22
|
+
{
|
23
|
+
return (*this)[Identifier(name)];
|
24
|
+
}
|
25
|
+
|
26
|
+
} // Rice
|
data/rice/Symbol.cpp
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#include "Symbol.hpp"
|
2
|
+
|
3
|
+
namespace
|
4
|
+
{
|
5
|
+
VALUE check_type(Rice::Object value, int type)
|
6
|
+
{
|
7
|
+
rb_check_type(value, type);
|
8
|
+
return Qnil;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
Rice::Symbol::
|
13
|
+
Symbol(VALUE v)
|
14
|
+
: Object(v)
|
15
|
+
{
|
16
|
+
protect(check_type, v, T_SYMBOL);
|
17
|
+
}
|
18
|
+
|
19
|
+
Rice::Symbol::
|
20
|
+
Symbol(Object v)
|
21
|
+
: Object(v)
|
22
|
+
{
|
23
|
+
protect(check_type, v, T_SYMBOL);
|
24
|
+
}
|
25
|
+
|
data/rice/Symbol.hpp
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#ifndef Rice__Symbol__hpp_
|
2
|
+
#define Rice__Symbol__hpp_
|
3
|
+
|
4
|
+
#include "Identifier.hpp"
|
5
|
+
#include "Object.hpp"
|
6
|
+
#include "detail/ruby.hpp"
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
namespace Rice
|
10
|
+
{
|
11
|
+
|
12
|
+
//! A wrapper for ruby's Symbol class.
|
13
|
+
/*! Symbols are internal identifiers in ruby. They are singletons and
|
14
|
+
* can be thought of as frozen strings. They differ from an Identifier
|
15
|
+
* in that they are in fact real Objects, but they can be converted
|
16
|
+
* back and forth between Identifier and Symbol.
|
17
|
+
*/
|
18
|
+
class Symbol
|
19
|
+
: public Object
|
20
|
+
{
|
21
|
+
public:
|
22
|
+
//! Wrap an existing symbol.
|
23
|
+
Symbol(VALUE v);
|
24
|
+
|
25
|
+
//! Wrap an existing symbol.
|
26
|
+
Symbol(Object v);
|
27
|
+
|
28
|
+
//! Construct a Symbol from an Identifier.
|
29
|
+
Symbol(Identifier id);
|
30
|
+
|
31
|
+
//! Construct a Symbol from a null-terminated C string.
|
32
|
+
Symbol(char const * s = "");
|
33
|
+
|
34
|
+
//! Construct a Symbol from an std::string.
|
35
|
+
Symbol(std::string const & s);
|
36
|
+
|
37
|
+
//! Return a string representation of the Symbol.
|
38
|
+
char const * c_str() const;
|
39
|
+
|
40
|
+
//! Return a string representation of the Symbol.
|
41
|
+
std::string str() const;
|
42
|
+
|
43
|
+
//! Return the Symbol as an Identifier.
|
44
|
+
Identifier to_id() const;
|
45
|
+
};
|
46
|
+
|
47
|
+
} // namespace Rice
|
48
|
+
|
49
|
+
template<>
|
50
|
+
inline
|
51
|
+
Rice::Symbol from_ruby<Rice::Symbol>(Rice::Object x)
|
52
|
+
{
|
53
|
+
return Rice::Symbol(x);
|
54
|
+
}
|
55
|
+
|
56
|
+
template<>
|
57
|
+
inline
|
58
|
+
Rice::Object to_ruby<Rice::Symbol>(Rice::Symbol const & x)
|
59
|
+
{
|
60
|
+
return x;
|
61
|
+
}
|
62
|
+
|
63
|
+
#include "Symbol.ipp"
|
64
|
+
|
65
|
+
#endif // Rice__Symbol__hpp_
|
66
|
+
|