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

#include <Hash.hpp>

Inheritance diagram for Rice::Hash:
Rice::Builtin_Object< RHash, T_HASH > Rice::Object

Classes

class  Entry
 A helper class for dereferencing iterators. More...
 
class  Iterator
 A helper class for implementing iterators for a Hash. More...
 
class  Proxy
 A helper class so hash[key]=value can work. More...
 

Public Types

typedef Iterator< Hash &, Entryiterator
 An iterator.
 
typedef Iterator< Hash const
&, Entry const > 
const_iterator
 A const iterator.
 

Public Member Functions

 Hash ()
 Construct a new hash.
 
 Hash (Object v)
 Wrap an existing hash. More...
 
size_t size () const
 Return the number of elements in the hash.
 
template<typename Key_T >
Proxy const operator[] (Key_T const &key) const
 Get the value for the given key. More...
 
template<typename Key_T >
Proxy operator[] (Key_T const &key)
 Get the value for the given key. More...
 
template<typename Value_T , typename Key_T >
Value_T get (Key_T const &key)
 Get the value for the given key. More...
 
iterator begin ()
 Return an iterator to the beginning of the hash.
 
const_iterator begin () const
 Return a const iterator to the beginning of the hash.
 
iterator end ()
 Return an iterator to the end of the hash.
 
const_iterator end () const
 Return a const to the end of the hash.
 
- Public Member Functions inherited from Rice::Builtin_Object< RHash, T_HASH >
 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...
 
RHash & operator* () const
 Return a reference to obj_.
 
RHash * operator-> () const
 Return a pointer to obj_.
 
RHash * get () const
 Return a pointer to obj_.
 
void swap (Builtin_Object< RHash, 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 Hash class. This class provides a C++-style interface to ruby's Hash class and its associated rb_hash_* functions. Example:

* Hash h;
* h[42] = String("foo");
* h[10] = String("bar");
* std::cout << String(h[42]) << std::endl;
*

Constructor & Destructor Documentation

Rice::Hash::Hash ( Object  v)

Wrap an existing hash.

Parameters
vthe hash to wrap.

Member Function Documentation

template<typename Value_T , typename Key_T >
Value_T Rice::Hash::get ( Key_T const &  key)

Get the value for the given key.

The returned value is converted to the type given by Value_T.

Parameters
keythe key whose value should be retrieved from the hash.
Returns
the value associated with the given key, converted to C++ type Value_T.
template<typename Key_T >
Proxy const Rice::Hash::operator[] ( Key_T const &  key) const

Get the value for the given key.

Parameters
keythe key whose value should be retrieved from the hash.
Returns
the value associated with the given key.
template<typename Key_T >
Proxy Rice::Hash::operator[] ( Key_T const &  key)

Get the value for the given key.

Parameters
keythe key whose value should be retrieved from the hash.
Returns
the value associated with the given key.

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