Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Object_defn.hpp
1 #ifndef Rice__Object_defn__hpp_
2 #define Rice__Object_defn__hpp_
3 
7 #include "Identifier.hpp"
8 #include "detail/ruby.hpp"
9 
10 #include <iosfwd>
11 
12 namespace Rice
13 {
14 
15 class Class;
16 class String;
17 class Array;
18 
20 
23 class Object
24 {
25 public:
27  Object(VALUE value = Qnil) : value_(value) { }
28 
30  Object(Object const & other) : value_(other.value()) { }
31 
33  virtual ~Object() { }
34 
37  // Having this conversion also prevents accidental conversion to
38  // undesired integral types (e.g. long or int) by making the
39  // conversion ambiguous.
40  bool test() const { return RTEST(value_); }
41 
44  operator bool() const { return test(); }
45 
47  bool is_nil() const { return NIL_P(value_); }
48 
50  operator VALUE() const { return value_; }
51 
53  // Returns a const ref so that Address_Registration_Guard can access
54  // the address where the VALUE is stored
55  VALUE const volatile & value() const { return value_; }
56 
58 
60  Class class_of() const;
61 
63 
67  int compare(Object const & other) const;
68 
70 
74  String to_s() const;
75 
77 
81  String inspect() const;
82 
84  void freeze();
85 
87 
89  bool is_frozen() const;
90 
92  void swap(Object & other);
93 
95 
99  Object instance_eval(String const & s);
100 
102 
106  int rb_type() const;
107 
109 
113  bool is_a(Object klass) const;
114 
116 
120  bool respond_to(Identifier id) const;
121 
123 
126  bool is_instance_of(Object klass) const;
127 
129 
134  template<typename T>
135  void iv_set(
136  Identifier name,
137  T const & value);
138 
140 
143  Object iv_get(
144  Identifier name) const;
145 
147  //unset.
152  Identifier name) const;
153 
154 #include "detail/object_call.hpp"
155 
157 
163  Object vcall(Identifier id, Array args);
164 
166  void mark() const;
167 
168 protected:
170  void set_value(VALUE v);
171 
172 private:
173  volatile VALUE value_;
174 };
175 
176 std::ostream & operator<<(std::ostream & out, Object const & obj);
177 
178 bool operator==(Object const & lhs, Object const & rhs);
179 bool operator!=(Object const & lhs, Object const & rhs);
180 bool operator<(Object const & lhs, Object const & rhs);
181 bool operator>(Object const & lhs, Object const & rhs);
182 
183 extern Object const Nil;
184 extern Object const True;
185 extern Object const False;
186 extern Object const Undef;
187 
188 } // namespace Rice
189 
190 #endif // Rice__Object_defn__hpp_
191 
Object vcall(Identifier id, Array args)
Vectorized call.
void set_value(VALUE v)
Set the encapsulated value.
A wrapper for the ID type.
Definition: Identifier.hpp:15
Object iv_get(Identifier name) const
Get the value of an instance variable.
bool is_frozen() const
Determine if the object is frozen.
Object(VALUE value=Qnil)
Encapsulate an existing ruby object.
Definition: Object_defn.hpp:27
String inspect() const
Inspect the object.
String to_s() const
Return a string representation of an object.
A Wraper for the ruby String class.
Definition: String.hpp:23
bool test() const
Definition: Object_defn.hpp:40
Class class_of() const
Get the class of an object.
void freeze()
Freeze the object.
int rb_type() const
Return the type of the underlying C object.
Object attr_get(Identifier name) const
Get the value of an instance variable, but don&#39;t warn if it is.
bool is_nil() const
Returns true if the object is nil, false otherwise.
Definition: Object_defn.hpp:47
void iv_set(Identifier name, T const &value)
Set an instance variable.
Object instance_eval(String const &s)
Evaluate the given string in the context of the object.
VALUE const volatile & value() const
Explicitly get the encapsulated VALUE.
Definition: Object_defn.hpp:55
void swap(Object &other)
Swap with another Object.
A helper for defining a Class and its methods.
Definition: Class_defn.hpp:21
void mark() const
Mark the object with the garbage collector.
The base class for all Objects.
Definition: Object_defn.hpp:23
int compare(Object const &other) const
Compare this object to another object.
bool is_instance_of(Object klass) const
Determine whether class is the object&#39;s class.
virtual ~Object()
Destructor.
Definition: Object_defn.hpp:33
A wrapper for the ruby Array class.
Definition: Array.hpp:22
bool is_a(Object klass) const
Determine whether the object is an instance of a class/module.
bool respond_to(Identifier id) const
Determine if the objects responds to a method.
Object(Object const &other)
Copy constructor.
Definition: Object_defn.hpp:30