Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Classes | Public Types | Public Member Functions | List of all members
Rice::Array Class Reference

A wrapper for the ruby Array class. More...

#include <Array.hpp>

Inheritance diagram for Rice::Array:
Rice::Builtin_Object< RArray, T_ARRAY > Rice::Object

Classes

class  Proxy
 A helper class so array[index]=value can work. More...
 

Public Types

typedef Iterator< Array &, Proxyiterator
 An iterator.
 
typedef Iterator< Array const
&, Object
const_iterator
 A const iterator.
 

Public Member Functions

 Array ()
 Construct a new array.
 
 Array (Object v)
 Wrap an existing array. More...
 
 Array (VALUE v)
 Wrap an existing array. More...
 
template<typename Iter_T >
 Array (Iter_T begin, Iter_T end)
 Construct an array from a sequence. More...
 
template<typename T , size_t n>
 Array (T const (&a)[n])
 Construct an Array from a C array. More...
 
size_t size () const
 Return the size of the array.
 
Object operator[] (ptrdiff_t index) const
 Return the element at the given index. More...
 
Proxy operator[] (ptrdiff_t index)
 Return a reference to the element at the given index. More...
 
template<typename T >
Object push (T const &obj)
 Push an element onto the end of the array. More...
 
Object pop ()
 Pop an element from the end of the array. More...
 
template<typename T >
Object unshift (T const &obj)
 Unshift an element onto the beginning of the array. More...
 
Object shift ()
 Shift an element from the beginning of the array. More...
 
VALUE * to_c_array ()
 
iterator begin ()
 Return an iterator to the beginning of the array.
 
const_iterator begin () const
 Return a const iterator to the beginning of the array.
 
iterator end ()
 Return an iterator to the end of the array.
 
const_iterator end () const
 Return a const iterator to the end of the array.
 
- Public Member Functions inherited from Rice::Builtin_Object< RArray, T_ARRAY >
 Builtin_Object (Object value)
 Wrap an already allocated Ruby object. More...
 
 Builtin_Object (Builtin_Object const &other)
 Make a copy of a Builtin_Object. More...
 
RArray & operator* () const
 Return a reference to obj_.
 
RArray * operator-> () const
 Return a pointer to obj_.
 
RArray * get () const
 Return a pointer to obj_.
 
void swap (Builtin_Object< RArray, Builtin_Type > &ref)
 Swap with another builtin object of the same type. More...
 
- Public Member Functions inherited from Rice::Object
 Object (VALUE value=Qnil)
 Encapsulate an existing ruby object.
 
 Object (Object const &other)
 Copy constructor.
 
virtual ~Object ()
 Destructor.
 
bool test () const
 
 operator bool () const
 
bool is_nil () const
 Returns true if the object is nil, false otherwise.
 
 operator VALUE () const
 Implicit conversion to VALUE.
 
VALUE const volatile & value () const
 Explicitly get the encapsulated VALUE.
 
Class class_of () const
 Get the class of an object. More...
 
int compare (Object const &other) const
 Compare this object to another object. More...
 
String to_s () const
 Return a string representation of an object. More...
 
String inspect () const
 Inspect the object. More...
 
void freeze ()
 Freeze the object.
 
bool is_frozen () const
 Determine if the object is frozen. More...
 
void swap (Object &other)
 Swap with another Object.
 
Object instance_eval (String const &s)
 Evaluate the given string in the context of the object. More...
 
int rb_type () const
 Return the type of the underlying C object. More...
 
bool is_a (Object klass) const
 Determine whether the object is an instance of a class/module. More...
 
bool respond_to (Identifier id) const
 Determine if the objects responds to a method. More...
 
bool is_instance_of (Object klass) const
 Determine whether class is the object's class. More...
 
template<typename T >
void iv_set (Identifier name, T const &value)
 Set an instance variable. More...
 
Object iv_get (Identifier name) const
 Get the value of an instance variable. More...
 
Object attr_get (Identifier name) const
 Get the value of an instance variable, but don't warn if it is. More...
 
template<typename Retval_T >
Retval_T call (Identifier id, T1 arg1, T2 arg2,...) const
 Call the Ruby method specified by 'id' on object 'obj'. More...
 
Object call (Identifier id, T1 arg1, T2 arg2,...) const
 Version of call which defaults to Object return type.
 
Object vcall (Identifier id, Array args)
 Vectorized call. More...
 
void mark () const
 Mark the object with the garbage collector.
 

Additional Inherited Members

- Protected Member Functions inherited from Rice::Object
void set_value (VALUE v)
 Set the encapsulated value.
 

Detailed Description

A wrapper for the ruby Array class.

This class provides a C++-style interface to ruby's Array class and its associated rb_ary_* functions. Example:

* Array a;
* a.push(String("some string"));
* a.push(42);
*

Constructor & Destructor Documentation

Rice::Array::Array ( Object  v)

Wrap an existing array.

Parameters
va ruby object, which must be of type T_ARRAY.
Rice::Array::Array ( VALUE  v)

Wrap an existing array.

Parameters
va ruby object, which must be of type T_ARRAY.
template<typename Iter_T >
Rice::Array::Array ( Iter_T  begin,
Iter_T  end 
)

Construct an array from a sequence.

Parameters
beginan iterator to the beginning of the sequence.
endan iterator to the end of the sequence.
template<typename T , size_t n>
Rice::Array::Array ( T const (&)  a[n])

Construct an Array from a C array.

Parameters
aa C array of type T and size n.

Member Function Documentation

Object Rice::Array::operator[] ( ptrdiff_t  index) const

Return the element at the given index.

Parameters
indexThe index of the desired element. The index may be negative, to indicate an offset from the end of the array. If the index is out of bounds, this function has undefined behavior.
Returns
the element at the given index.
Proxy Rice::Array::operator[] ( ptrdiff_t  index)

Return a reference to the element at the given index.

Parameters
indexThe index of the desired element. The index may be negative, to indicate an offset from the end of the array. If the index is out of bounds, this function has undefined behavior.
Returns
the element at the given index.
Object Rice::Array::pop ( )

Pop an element from the end of the array.

Returns
the object which was popped from the array, or Qnil if the array was empty.
template<typename T >
Object Rice::Array::push ( T const &  obj)

Push an element onto the end of the array.

Parameters
van object to push onto the array.
Returns
the object which was pushed onto the array.
Object Rice::Array::shift ( )

Shift an element from the beginning of the array.

Returns
the object which was shifted from the array.
VALUE* Rice::Array::to_c_array ( )

Return a pointer to the beginning of the underlying C array. Use with caution!

Returns
a pointer to the beginning of the array.
template<typename T >
Object Rice::Array::unshift ( T const &  obj)

Unshift an element onto the beginning of the array.

Parameters
van object to unshift onto the array.
Returns
the object which was unshifted onto the array.

The documentation for this class was generated from the following file: