TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RefManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _REFMANAGER_H
20 #define _REFMANAGER_H
21 //=====================================================
22 
23 #include "Dynamic/LinkedList.h"
25 
26 template <class TO, class FROM> class RefManager : public LinkedListHead
27 {
28  public:
30  RefManager() { }
31  virtual ~RefManager() { clearReferences(); }
32 
37 
38  iterator begin() { return iterator(getFirst()); }
39  iterator end() { return iterator(NULL); }
40  iterator rbegin() { return iterator(getLast()); }
41  iterator rend() { return iterator(NULL); }
42 
44  {
45  LinkedListElement* ref;
46  while ((ref = getFirst()) != NULL)
47  {
48  ((Reference<TO, FROM>*) ref)->invalidate();
49  ref->delink(); // the delink might be already done by invalidate(), but doing it here again does not hurt and insures an empty list
50  }
51  }
52 };
53 
54 //=====================================================
55 #endif
56 
Reference< TO, FROM > const * getFirst() const
Definition: RefManager.h:34
virtual ~RefManager()
Definition: RefManager.h:31
LinkedListElement * getLast()
Definition: LinkedList.h:107
Definition: LinkedList.h:28
iterator rbegin()
Definition: RefManager.h:40
Reference< TO, FROM > const * getLast() const
Definition: RefManager.h:36
arena_t NULL
Definition: jemalloc_internal.h:624
LinkedListElement * getFirst()
Definition: LinkedList.h:104
Definition: RefManager.h:26
void delink()
Definition: LinkedList.h:53
Reference< TO, FROM > * getLast()
Definition: RefManager.h:35
void clearReferences()
Definition: RefManager.h:43
Definition: Reference.h:27
Definition: LinkedList.h:141
iterator begin()
Definition: RefManager.h:38
Reference< TO, FROM > * getFirst()
Definition: RefManager.h:33
iterator rend()
Definition: RefManager.h:41
Definition: LinkedList.h:84
LinkedListHead::Iterator< Reference< TO, FROM > > iterator
Definition: RefManager.h:29
iterator end()
Definition: RefManager.h:39
RefManager()
Definition: RefManager.h:30