00001 /* 00002 * Copyright 2006 Baylor University 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _PROPHET_POINTER_LIST_H_ 00018 #define _PROPHET_POINTER_LIST_H_ 00019 00020 #include <vector> 00021 00022 namespace prophet 00023 { 00024 00030 template<class T> 00031 class PointerList : public std::vector<T*> 00032 { 00033 public: 00034 typedef std::vector<T*> List; 00035 typedef typename std::vector<T*>::iterator iterator; 00036 typedef typename std::vector<T*>::const_iterator const_iterator; 00037 00041 PointerList() 00042 : std::vector<T*>() {} 00043 00047 PointerList(const PointerList& a) 00048 : std::vector<T*>() 00049 { 00050 clear(); 00051 copy_from(a); 00052 } 00053 00057 virtual ~PointerList() 00058 { 00059 clear(); 00060 } 00061 00065 PointerList& operator= (const PointerList& a) 00066 { 00067 clear(); 00068 copy_from(a); 00069 return *this; 00070 } 00071 00075 void erase(iterator i) 00076 { 00077 delete (*i); 00078 List::erase(i); 00079 } 00080 00085 void clear() 00086 { 00087 free(); 00088 List::clear(); 00089 } 00090 00091 protected: 00095 void free() 00096 { 00097 for(iterator i = List::begin(); 00098 i != List::end(); 00099 i++) 00100 { 00101 delete *i; 00102 } 00103 } 00107 void copy_from(const PointerList& a) 00108 { 00109 for(const_iterator i = a.begin(); 00110 i != a.end(); 00111 i++) 00112 { 00113 push_back(new T(**i)); 00114 } 00115 } 00116 }; // template PointerList<T> 00117 00118 }; // namespace prophet 00119 00120 #endif // _PROPHET_POINTER_LIST_H_