Spinning Topp Logo BlackTopp Studios
inc
eventarguments.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine 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 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine 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.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _eventarguments_h
41 #define _eventarguments_h
42 
43 #include "datatypes.h"
44 #include "countedptr.h"
45 
46 namespace Mezzanine
47 {
48  ///////////////////////////////////////////////////////////////////////////////
49  /// @brief This is a common class to represent all possible arguments for a given event that is fired.
50  /// @details
51  ///////////////////////////////////////
53  {
54  private:
55  /// @brief This is count of the number of references to this object.
56  Whole RefCount;
57  public:
58  ///////////////////////////////////////////////////////////////////////////////
59  // Public Data Members
60 
61  /// @brief The name of the event being fired.
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // Construction and Destruction
66 
67  /// @brief Class constructor.
68  /// @param Name The name of the event being fired.
69  EventArguments(const String& Name) :
70  EventName(Name) { }
71  /// @brief Class destructor.
72  virtual ~EventArguments() { }
73 
74  ///////////////////////////////////////////////////////////////////////////////
75  // CountedPtr Functionality
76 
77  /// @brief Increase the reference count by one and return the updated count.
78  /// @return Returns a Whole representing the updated count.
80  { return ++this->RefCount; }
81  /// @brief Decrease the reference count by one and return the updated count.
82  /// @return Returns a Whole representing the updated count.
84  { return --this->RefCount; }
85  /// @brief Get the current amount of references.
86  /// @return A Whole with the current reference count
88  { return this->RefCount; }
89 
90  /// @brief Gets the actual pointer to the target of the base type.
91  /// @return Returns a pointer of the targeted type to the object being managed.
93  { return this; }
94  /// @brief Get a pointer to the most Derived type of this instance.
95  /// @return Returns a pointer of the most derived type of this.
97  { return this; }
98  };//EventArguments
99 
100  ///////////////////////////////////////////////////////////////////////////////
101  /// @brief This is a metaprogramming traits class used by EventArguments.
102  /// @details This is need for an intrusive CountedPtr implementation. Should a working external reference count be made this
103  /// could be dropped in favor of a leaner implementation.
104  ///////////////////////////////////////
105  template <>
107  {
108  public:
109  /// @brief Typedef communicating the reference count type to be used.
111 
112  /// @brief Method responsible for creating a reference count for a CountedPtr of the templated type.
113  /// @param Target A pointer to the target class that is to be reference counted.
114  /// @return Returns a pointer to a new reference counter for the templated type.
115  static RefCountType* ConstructionPointer(RefCountType* Target)
116  { return Target; }
117 
118  /// @brief Enum used to decide the type of casting to be used by a reference counter of the templated type.
119  enum { IsCastable = CastStatic };
120  };//ReferenceCountTraits<EventArguments>
121 
122  /// @brief Convenience typedef for passing around EventArguments.
124 }//Mezzanine
125 
126 #endif
Whole DecrementReferenceCount()
Decrease the reference count by one and return the updated count.
CountedPtr< EventArguments > EventArgumentsPtr
Convenience typedef for passing around EventArguments.
const String EventName
The name of the event being fired.
All the definitions for datatypes as well as some basic conversion functions are defined here...
A simple reference counting pointer.
Definition: countedptr.h:70
Whole GetReferenceCount() const
Get the current amount of references.
EventArguments RefCountType
Typedef communicating the reference count type to be used.
EventArguments * GetReferenceCountTargetAsPointer()
Gets the actual pointer to the target of the base type.
static RefCountType * ConstructionPointer(RefCountType *Target)
Method responsible for creating a reference count for a CountedPtr of the templated type...
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
Definition: countedptr.h:87
virtual ~EventArguments()
Class destructor.
This file describes and implements a reference counted pointer that is NOT threadsafe.
EventArguments(const String &Name)
Class constructor.
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:63
Whole IncrementReferenceCount()
Increase the reference count by one and return the updated count.
This is a common class to represent all possible arguments for a given event that is fired...
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual EventArguments * GetMostDerived()
Get a pointer to the most Derived type of this instance.