Hosting courtesy of Sourceforge

SourceForge Logo
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

STL_Helper.h

Go to the documentation of this file.
00001 #ifndef STL_HELPER_H_
00002 #define STL_HELPER_H_
00003 
00004 #include <list>
00005 
00006 using namespace std;
00007 
00008 namespace Util {
00009         enum ListOpResult {
00010                 LIST_END,
00011                 LIST_MIDDLE
00012         };
00013 
00015         template <class T> T min(const T& a, const T& b);
00016 
00023         template <class T> ListOpResult safeIteratorRemove(list<T>& l, list<T>::iterator& i);
00024 
00032         template <class T> ListOpResult safeIteratorSwap(list<T>& src, list<T>& dst, list<T>::iterator& i);
00033 
00035         template <class container>      void freeDynamicContainer(container& c);
00036         
00037         template <class T> T min(const T& a, const T& b) {
00038                 if (a < b) return a;
00039                 return b;
00040         }
00041 
00042         template <class T> ListOpResult safeIteratorRemove(list<T>& l, list<T>::iterator& i) {
00043                 list<T>::iterator cpy = i;
00044                 i++;
00045                 l.erase(cpy);
00046                 if (i == l.end()) return LIST_END;
00047                 return LIST_MIDDLE;
00048         }
00049         
00050         template <class T> ListOpResult safeIteratorSwap(list<T>& src, list<T>& dst, list<T>::iterator& i) {
00051                 dst.push_back(*i);
00052                 return (safeIteratorRemove<T>(src, i));         
00053         }
00054 
00055         template <class container> void freeDynamicContainer(container& c) {
00056                 for (typename container::iterator i = c.begin(); i != c.end(); i++) {
00057                         delete (*i);
00058                 }
00059                 c.clear();
00060         }
00061 
00062 };
00063 
00064 #endif // ifndef STL_HELPER_H_
00065 
00066 

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001