scoped_array.hpp

Go to the documentation of this file.
00001 #ifndef SCOPED_ARRAY_HPP
00002 #define SCOPED_ARRAY_HPP
00003 
00004 #include <cstddef>
00005 
00006 
00007 template<class T>
00008 class scoped_array
00009 {
00010 private:
00011     T *px;
00012 
00013     scoped_array(scoped_array const &);
00014     scoped_array &operator=(scoped_array const &);
00015 
00016     typedef scoped_array<T> this_type;
00017 
00018     void operator==(scoped_array const &) const;
00019     void operator!=(scoped_array const &) const;
00020 
00021 public:
00022     typedef T element_type;
00023 
00024     explicit scoped_array(T *p = 0)
00025     :   px(p)
00026     {
00027     }
00028 
00029     ~scoped_array()
00030     {
00031         delete px;
00032     }
00033 
00034     void reset(T *p = 0)
00035     {
00036         this_type(p).swap(*this);
00037     }
00038 
00039     T &operator[](std::ptrdiff_t i) const
00040     {
00041         return px[i];
00042     }
00043 
00044     T *get() const
00045     {
00046         return px;
00047     }
00048 
00049     void swap(scoped_array &b)
00050     {
00051         T *tmp = b.px;
00052         b.px = px;
00053         px = tmp;
00054     }
00055 };
00056 
00057 template<class T> inline void swap(scoped_array<T> &a, scoped_array<T> &b)
00058 {
00059     a.swap(b);
00060 }
00061 
00062 
00063 #endif
00064 
Generated on Sun Apr 11 12:23:09 2010 for RenderStack by  doxygen 1.6.3