delegate.h

Engine/source/core/util/delegate.h

More...

Classes:

Public Defines

define

The macro which abstracts the details of the delegate implementation.

Public Typedefs

DelegateMemento 

An opaque structure which can hold an arbitary delegate.

Detailed Description

Public Defines

Delegate() 

The macro which abstracts the details of the delegate implementation.

Public Typedefs

typedef fastdelegate::DelegateMemento DelegateMemento 

An opaque structure which can hold an arbitary delegate.

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _UTIL_DELEGATE_H_
25#define _UTIL_DELEGATE_H_
26
27#include "core/util/FastDelegate.h"
28
29/// @def Delegate
30/// The macro which abstracts the details of the delegate implementation.
31#define Delegate fastdelegate::FastDelegate
32
33/// @typedef DelegateMemento
34/// An opaque structure which can hold an arbitary delegate.
35/// @see Delegate
36typedef fastdelegate::DelegateMemento DelegateMemento;
37
38
39template<class T>
40class DelegateRemapper : public DelegateMemento
41{
42public:
43   DelegateRemapper() : mOffset(0) {}
44
45   void set(T * t, const DelegateMemento & memento)
46   {
47      SetMementoFrom(memento);
48      if (m_pthis)
49         mOffset = ((int)m_pthis) - ((int)t);
50   }
51
52   void rethis(T * t)
53   {
54      if (m_pthis)
55         m_pthis = (fastdelegate::detail::GenericClass *)(mOffset + (int)t);
56   }
57
58protected:
59   S32 mOffset;
60};
61
62#endif // _UTIL_DELEGATE_H_
63