Serial-TCP/IPbridge  1.0
auto_array.h
Go to the documentation of this file.
1 
12 #ifndef AUTO_ARRAY_H
13 #define AUTO_ARRAY_H
14 
26 template<typename T>
27 class auto_array {
28  public:
35  explicit auto_array(T *p = 0) throw(): _p(p) { }
36 
41  ~auto_array() throw() { delete[] _p; }
42 
49  T *get() const throw() { return _p; }
50 
61  T *release() throw() {
62  T *tmp = _p;
63  _p = 0;
64  return tmp;
65  }
66 
76  void reset(T *p = 0) throw() {
77  delete[] _p;
78  _p = p;
79  }
80 
81  private:
83  T *_p;
84 
85  private:
86  // TODO - implement these:
87  // http://www.cplusplus.com/reference/std/memory/auto_ptr/auto_ptr.html
88  auto_array(auto_array& a) throw();
89  template<class Y> auto_array(auto_array<Y> &a) throw();
90  // auto_array(auto_array_ref<T> r) throw();
91  T &operator*() const throw();
92  T *operator->() const throw();
93  auto_array &operator=(auto_array &a) throw();
94  template <class Y> auto_array &operator= (auto_array<Y> &a) throw();
95  //auto_array &operator=(auto_array_ref<T> r) throw();
96  //template <class Y> operator auto_array_ref<Y>() throw();
97  template <class Y> operator auto_array<Y>() throw();
98 };
99 
100 #endif // #ifndef AUTO_ARRAY_H
101 
102 // End of file auto_array.h
Limited version of std::auto_ptr for dynamic arrays.
Definition: auto_array.h:27
~auto_array()
Deallocates the block of memory the object "points to" using delete[] and destructs the object...
Definition: auto_array.h:41
T * release()
Returns the stored pointer and sets the internal pointer to 0.
Definition: auto_array.h:61
auto_array(T *p=0)
Constructs an auto_array object from an array pointer.
Definition: auto_array.h:35
T * _p
Stored pointer.
Definition: auto_array.h:83
T & operator*() const
void reset(T *p=0)
Deallocates the array that the auto_array points to and sets a new value.
Definition: auto_array.h:76