2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "Utilities/LinkedList.h"
24 //=====================================================
26 template <class TO
, class FROM
> class Reference
: public LinkedListElement
32 // Tell our refTo (target) object that we have a link
33 virtual void targetObjectBuildLink() = 0;
35 // Tell our refTo (taget) object, that the link is cut
36 virtual void targetObjectDestroyLink() = 0;
38 // Tell our refFrom (source) object, that the link is cut (Target destroyed)
39 virtual void sourceObjectDestroyLink() = 0;
41 Reference() { iRefTo
= NULL
; iRefFrom
= NULL
; }
42 virtual ~Reference() {}
45 inline void link(TO
* toObj
, FROM
* fromObj
)
47 assert(fromObj
); // fromObj MUST not be NULL
54 targetObjectBuildLink();
58 // We don't need the reference anymore. Call comes from the refFrom object
59 // Tell our refTo object, that the link is cut
60 inline void unlink() { targetObjectDestroyLink(); delink(); iRefTo
= NULL
; iRefFrom
= NULL
; }
62 // Link is invalid due to destruction of referenced target object. Call comes from the refTo object
63 // Tell our refFrom object, that the link is cut
64 inline void invalidate() // the iRefFrom MUST remain!!
66 sourceObjectDestroyLink(); delink(); iRefTo
= NULL
;
69 inline bool isValid() const // Only check the iRefTo
71 return iRefTo
!= NULL
;
74 Reference
<TO
,FROM
>* next() { return((Reference
<TO
,FROM
>*)LinkedListElement::next()); }
75 Reference
<TO
,FROM
>* prev() { return((Reference
<TO
,FROM
>*)LinkedListElement::prev()); }
77 inline TO
* operator ->() const { return iRefTo
; }
78 inline TO
* getTarget() const { return iRefTo
; }
80 inline FROM
* getSource() const { return iRefFrom
; }
83 //=====================================================