00001 #ifndef SRC_INC_WEAK_POINTER_HPP
00002 #define SRC_INC_WEAK_POINTER_HPP
00003
00004 #include <gc++.hpp>
00005 #include <stdexcept>
00006
00007 namespace GCpp
00008 {
00009
00012 class bad_weak_pointer : public std::runtime_error
00013 {
00014 public:
00015 bad_weak_pointer ()
00016 : std::runtime_error ("bad weak pointer")
00017 {}
00018 };
00019
00028 template <class T>
00029 class weak_ptr
00030 {
00031 private:
00034 void* f_storage;
00035
00036 public:
00042 explicit weak_ptr (gc_ptr<T>& p_item)
00043 : f_storage (p_item.storage ())
00044 {}
00045
00052 operator gc_ptr<T> () const
00053 {
00054 if (not allocator_for_type<T>()->confirm (f_storage))
00055 throw bad_weak_pointer ();
00056
00057 return gc_ptr<T> ((T*)f_storage);
00058 }
00059 };
00060
00061 }
00062
00063 #endif