Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Container.h

Go to the documentation of this file.
00001 /*
00002  * Dibbler - a portable DHCPv6
00003  *
00004  * authors: Tomasz Mrugalski <thomson@klub.com.pl>
00005  *          Marek Senderski <msend@o2.pl>
00006  *
00007  * $Id: Container.h,v 1.5 2005/07/17 21:09:52 thomson Exp $
00008  *
00009  * $Log: Container.h,v $
00010  * Revision 1.5  2005/07/17 21:09:52  thomson
00011  * Minor improvements for 0.4.1 release.
00012  *
00013  * Revision 1.4  2004/10/25 20:45:54  thomson
00014  * Option support, parsers rewritten. ClntIfaceMgr now handles options.
00015  *
00016  * Revision 1.3  2004/03/29 22:06:49  thomson
00017  * 0.1.1 version
00018  *
00019  *
00020  * Released under GNU GPL v2 licence
00021  *
00022  */
00023 
00024 #ifndef CONTAINER_H
00025 #define CONTAINER_H
00026 
00027 #include <list>
00028 
00029 using namespace std;
00030 
00031 #define TContainer< SmartPtr<x> > TContainer< SmartPtr< x > >
00032 
00033 template <class TYP>
00034 class TContainer{
00035 public:
00036         TContainer();
00037         ~TContainer();
00038 
00039         bool    append(const TYP &foo);
00040         bool    prepend(const TYP& foo);    
00041         int     count();
00042         void    first();
00043         void    delFirst();
00044         void    del();
00045         void    clear();
00046         TYP     get();
00047         TYP     getLast();
00048         TYP     getFirst();
00049         void    delLast();
00050 
00051 private:
00052         list<TYP> lista;
00053         typename list<TYP>::iterator it;
00054 };
00055 
00056 template <class TYP>
00057 TContainer<TYP>::TContainer() {
00058 }
00059 
00060 template <class TYP>
00061 TContainer<TYP>::~TContainer() {
00062         lista.clear();
00063 }
00064 
00065 template <class TYP>
00066 void TContainer<TYP>::clear() {
00067         lista.clear();
00068 }
00069 
00070 template <class TYP>
00071 int TContainer<TYP>::count() {
00072         return (int)lista.size();
00073 }
00074 
00075 template <class TYP>
00076 bool TContainer<TYP>::append(const TYP& foo) {
00077         lista.push_back(foo);
00078         return true;
00079 }
00080 template <class TYP>bool TContainer<TYP>::prepend(const TYP& foo) {
00081         lista.push_front(foo);    
00082         return true;
00083 }
00084 template <class TYP>
00085 void TContainer<TYP>::first() {
00086         it=lista.begin();
00087         return;
00088 }
00089 
00090 template <class TYP>
00091 TYP TContainer<TYP>::get() {
00092         if (it!=lista.end())    
00093                 return *it++;   
00094         else            
00095                 return TYP();
00096 }
00097 
00098 template <class TYP>
00099 void TContainer<TYP>::delFirst() {
00100         lista.pop_front();
00101         first();
00102 }
00103 
00104 template <class TYP>
00105 void TContainer<TYP>::del() {
00106         it--;
00107         lista.erase(it);
00108         first();
00109 }
00110 
00111 template <class TYP>TYP TContainer<TYP>::getLast() {    
00112     return lista.back();
00113 }
00114 
00115 template <class TYP>void TContainer<TYP>::delLast() {    
00116     lista.pop_back();    first();
00117 }
00118 
00119 template <class TYP>TYP TContainer<TYP>::getFirst() {   
00120         return lista.front();
00121 }
00122 #endif
00123 

Generated on Sun Aug 7 22:47:14 2005 for Dibbler - a portable DHCPv6 by  doxygen 1.3.9.1