Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
auto_buffer.h
Go to the documentation of this file.00001 00004 /* 00005 * Copyright © 2004, Michael Geddes, Lijun Qin. 00006 * 00007 * This material is provided "as is", with absolutely no warranty 00008 * expressed or implied. Any use is at your own risk. Permission to 00009 * use or copy this software for any purpose is hereby granted without 00010 * fee, provided the above notices are retained on all copies. 00011 * Permission to modify the code and to distribute modified code is 00012 * granted, provided the above notices are retained, and a notice that 00013 * the code was modified is included with the above copyright notice. 00014 * 00015 * This header is part of comet. 00016 * http://www.lambdasoft.dk/comet 00017 */ 00018 00019 #ifndef INCLUDE_COMET_AUTO_BUFFER_H 00020 #define INCLUDE_COMET_AUTO_BUFFER_H 00021 00022 #ifdef _SHOW_INC 00023 #pragma message(" #Include " __FILE__) 00024 #endif 00025 00026 namespace comet 00027 { 00031 00036 template <typename T> 00037 class auto_buffer_t 00038 { 00039 public: 00040 typedef size_t size_type; 00044 explicit auto_buffer_t(size_type size) 00045 { 00046 begin_ = new T[size]; 00047 } 00049 ~auto_buffer_t() throw() { delete[] begin_; } 00050 00052 void clear() throw() 00053 { 00054 delete[] begin_; 00055 begin_ = 0; 00056 } 00058 bool empty() const throw() 00059 { 00060 return begin_ != NULL; 00061 } 00063 void resize( size_type newSize) throw() 00064 { 00065 delete[] begin_; 00066 begin_ = new T[newSize]; 00067 } 00068 00070 T & at( size_type t) throw() { return begin_[t]; } 00071 T & operator[]( size_type t) throw() { return begin_[t]; } 00073 const T & at( size_type t) const throw() { return begin_[t]; } 00074 const T & operator[]( size_type t) const throw() { return begin_[t]; } 00075 00077 T *detach() 00078 { 00079 T *val = begin_; 00080 begin_ = NULL; 00081 return val; 00082 } 00084 T *get() { return begin_; } 00085 const T *get()const { return begin_; } 00086 00087 private: 00089 auto_buffer_t &operator=(const auto_buffer_t &); 00091 auto_buffer_t(const auto_buffer_t&); 00092 00094 T *begin_; 00095 }; 00097 } 00098 00099 #endif /* INCLUDE_COMET_AUTO_BUFFER_H */