/home/vlg/develop/libASSA/libassa/assa/Repository.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                             Repository.h
00004 //------------------------------------------------------------------------------
00005 //  Copyright (c) 2003 by Vladislav Grinchenko
00006 //
00007 //  This library is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU Library General Public
00009 //  License as published by the Free Software Foundation; either
00010 //  version 2 of the License, or (at your option) any later version.
00011 //------------------------------------------------------------------------------
00012 //  Date: May 7, 2003
00013 //------------------------------------------------------------------------------
00014 
00015 #ifndef REPOSITORY_H
00016 #define REPOSITORY_H
00017 
00018 #include <vector>
00019 using std::vector;
00020 
00021 namespace ASSA {
00022 
00032     template<typename T>
00033     class Repository 
00034     {
00035     public:
00036         typedef T* value_type;
00037         typedef size_t size_type;
00038 
00039         typedef typename std::vector<value_type> list_t;
00040         typedef typename std::vector<value_type>::iterator iterator;
00041         typedef typename std::vector<value_type>::const_iterator const_iterator;
00042 
00045         Repository () {
00046             m_collection = new list_t; 
00047         }
00048 
00050         virtual ~Repository () {
00051             if (m_collection) { clear (); delete m_collection; }
00052         }
00053 
00055         iterator begin () { return m_collection->begin (); }
00056 
00058         const_iterator begin () const { return m_collection->begin (); }
00059 
00061         iterator end () { return m_collection->end (); }
00062 
00064         const_iterator end () const { return m_collection->end (); }
00065 
00067         bool empty () const { return m_collection->empty (); }
00068 
00070         size_type size () const { return m_collection->size (); }
00071 
00073         void push_back (const value_type& x_) { m_collection->push_back (x_); }
00074 
00076         void erase (iterator position_) { m_collection->erase (position_); }
00077 
00081         bool erase (const value_type& x_) {
00082             iterator it = begin ();
00083             while (it != end ()) {
00084                 if ((*it) == x_) { erase (it); break; }
00085                 it++;
00086             }
00087         }
00088 
00090         void clear () {
00091             m_collection->erase (m_collection->begin (), m_collection->end ());
00092         }
00093 
00094     private:
00095         list_t* m_collection;
00096     };
00097 }  // @end namespace ASSA
00098 
00099 #endif /* REPOSITORY_H */  

Generated on Sun Aug 13 15:08:00 2006 for libassa by  doxygen 1.4.6