Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ruby_hash.hpp

00001 #ifndef Exc_Ruby__ruby_hash__hpp_
00002 #define Exc_Ruby__ruby_hash__hpp_
00003 
00004 #ident "$Id$"
00005 
00006 #include "../ruby_reference.hpp"
00007 #include "../detail/ruby_hacks.hpp"
00008 #include <iterator>
00009 #include <st.h>
00010 
00011 namespace Exc_Ruby
00012 {
00013 
00014 // TODO: For now, we throw only ruby exceptions, but this should be
00015 // configurable.
00016 class Ruby_Hash
00017   : public Ruby_Reference<
00018       RHash, 
00019       Exception_Safe_Builtin_Wrapper<RHash, T_HASH> >
00020 {
00021 public:
00023   Ruby_Hash();
00024 
00026   Ruby_Hash(VALUE v);
00027 
00029   void freeze();
00030 
00032   size_t size() const;
00033 
00034 private:
00036   class Proxy
00037   {
00038   public:
00039     Proxy(VALUE hash, VALUE key);
00040     operator VALUE() const;
00041     VALUE operator=(VALUE value);
00042 
00043   private:
00044     VALUE hash_;
00045     VALUE key_;
00046   };
00047 
00048 public:
00050   Proxy const operator[](VALUE key) const;
00051 
00053   Proxy operator[](VALUE key);
00054 
00055 private:
00057   // TODO: This really should be a random-access iterator.
00058   template<typename T, typename Ptr_To_Value, typename Ref_To_Value>
00059   class Iterator
00060     : public std::iterator<
00061         std::forward_iterator_tag,
00062         VALUE,
00063         Ptr_To_Value,
00064         Ref_To_Value>
00065   {
00066   public:
00067     Iterator(T hash, size_t index, st_table_entry * ptr);
00068     Iterator operator++();
00069     Ref_To_Value operator*();
00070     bool operator==(Iterator const & rhs);
00071     bool operator!=(Iterator const & rhs);
00072 
00073   private:
00074     T hash_;
00075     int i_;
00076     st_table_entry * ptr_;
00077   };
00078 
00079 public:
00081   typedef Iterator<Ruby_Hash &, VALUE *, VALUE &> iterator;
00082 
00084   typedef Iterator<Ruby_Hash const &, VALUE const *, VALUE const &> const_iterator;
00085 
00087   iterator begin();
00088 
00090   const_iterator begin() const;
00091 
00093   iterator end();
00094 
00096   const_iterator end() const;
00097 };
00098 
00099 } // namespace Exc_Ruby
00100 
00101 #include "ruby_hash.ipp"
00102 
00103 #endif // Exc_Ruby__ruby_hash__hpp_
00104 

Generated on Sat Jan 1 12:02:19 2005 for Exceptional Ruby by doxygen 1.3.6