libassa  3.5.1
Repository.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // Repository.h
4 //------------------------------------------------------------------------------
5 // Copyright (c) 2003 by Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 // Date: May 7, 2003
13 //------------------------------------------------------------------------------
14 
15 #ifndef REPOSITORY_H
16 #define REPOSITORY_H
17 
18 #include <vector>
19 using std::vector;
20 
21 namespace ASSA {
22 
32  template<typename T>
33  class Repository
34  {
35  public:
36  typedef T* value_type;
37  typedef size_t size_type;
38 
39  typedef typename std::vector<value_type> list_t;
40  typedef typename std::vector<value_type>::iterator iterator;
41  typedef typename std::vector<value_type>::const_iterator const_iterator;
42 
46  m_collection = new list_t;
47  }
48 
50  virtual ~Repository () {
51  if (m_collection) { clear (); delete m_collection; }
52  }
53 
55  iterator begin () { return m_collection->begin (); }
56 
58  const_iterator begin () const { return m_collection->begin (); }
59 
61  iterator end () { return m_collection->end (); }
62 
64  const_iterator end () const { return m_collection->end (); }
65 
67  bool empty () const { return m_collection->empty (); }
68 
70  size_type size () const { return m_collection->size (); }
71 
73  void push_back (const value_type& x_) { m_collection->push_back (x_); }
74 
76  void erase (iterator position_) { m_collection->erase (position_); }
77 
81  bool erase (const value_type& x_) {
82  iterator it = begin ();
83  while (it != end ()) {
84  if ((*it) == x_) { erase (it); break; }
85  it++;
86  }
87  }
88 
90  void clear () {
91  m_collection->erase (m_collection->begin (), m_collection->end ());
92  }
93 
94  private:
96  };
97 } // @end namespace ASSA
98 
99 #endif /* REPOSITORY_H */
std::vector< value_type >::const_iterator const_iterator
Definition: Repository.h:41
iterator begin()
Get iterator to the first element of the repository.
Definition: Repository.h:55
list_t * m_collection
Definition: Repository.h:95
size_t size_type
Definition: Repository.h:37
bool erase(const value_type &x_)
Remove element.
Definition: Repository.h:81
void clear()
Empty repository.
Definition: Repository.h:90
std::vector< value_type > list_t
Definition: Repository.h:39
void erase(iterator position_)
Remove element at the position_ iterator.
Definition: Repository.h:76
virtual ~Repository()
Destructor.
Definition: Repository.h:50
size_type size() const
Return number of elements in the repository.
Definition: Repository.h:70
bool empty() const
Return true if repository is empty.
Definition: Repository.h:67
std::vector< value_type >::iterator iterator
Definition: Repository.h:40
const_iterator begin() const
Get constant iterator to the first element of the repository.
Definition: Repository.h:58
void push_back(const value_type &x_)
Add new element to the repository.
Definition: Repository.h:73
iterator end()
Get iterator to the end of the repository.
Definition: Repository.h:61
const_iterator end() const
Get constant iterator to the end of the repository.
Definition: Repository.h:64
Repository()
Constructor.
Definition: Repository.h:45
Definition: Acceptor.h:40