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

Generated on Mon Dec 27 21:55:22 2004 for Dibbler - a portable DHCPv6 by  doxygen 1.3.9.1