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

ruby_array.hpp

00001 #ifndef Exc_Ruby__ruby_array__hpp_
00002 #define Exc_Ruby__ruby_array__hpp_
00003 
00004 #ident "$Id$"
00005 
00006 #include "../ruby_reference.hpp"
00007 #include "../detail/ruby_hacks.hpp"
00008 #include <iterator>
00009 
00010 namespace Exc_Ruby
00011 {
00012 
00013 // TODO: For now, we throw only ruby exceptions, but this should be
00014 // configurable.
00015 class Ruby_Array
00016   : public Ruby_Reference<
00017       RArray, 
00018       Exception_Safe_Builtin_Wrapper<RArray, T_ARRAY> >
00019 {
00020 public:
00022   Ruby_Array();
00023 
00025   Ruby_Array(VALUE v);
00026 
00028   void freeze();
00029 
00030 public:
00031   size_t size() const;
00032 
00034   VALUE operator[](ssize_t index) const;
00035 
00037   VALUE & operator[](ssize_t index);
00038 
00040   VALUE to_s() const;
00041 
00043   VALUE push(VALUE v);
00044 
00046   VALUE pop();
00047 
00049   VALUE unshift(VALUE v);
00050 
00052   VALUE shift();
00053 
00056   VALUE * to_c_array();
00057 
00058 private:
00060   // TODO: This really should be a random-access iterator.
00061   template<typename T, typename Ptr_To_Value, typename Ref_To_Value>
00062   class Iterator
00063     : public std::iterator<
00064         std::forward_iterator_tag,
00065         VALUE,
00066         Ptr_To_Value,
00067         Ref_To_Value>
00068   {
00069   public:
00070     Iterator(T array, size_t index);
00071     Iterator operator++();
00072     Ref_To_Value operator*();
00073     bool operator==(Iterator const & rhs);
00074     bool operator!=(Iterator const & rhs);
00075 
00076   private:
00077     T array_;
00078     size_t index_;
00079   };
00080 
00081 public:
00083   typedef Iterator<Ruby_Array &, VALUE *, VALUE &> iterator;
00084 
00086   typedef Iterator<Ruby_Array const &, VALUE const *, VALUE const &> const_iterator;
00087 
00089   iterator begin();
00090 
00092   const_iterator begin() const;
00093 
00095   iterator end();
00096 
00098   const_iterator end() const;
00099 };
00100 
00101 } // namespace Exc_Ruby
00102 
00103 #include "ruby_array.ipp"
00104 
00105 #endif // Exc_Ruby__ruby_array__hpp_
00106 

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