TrueReality  v0.1.1912
Invokable.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author David Guthrie
20 * @author Maxim Serebrennik
21 */
22 
23 #pragma once
24 
25 #include <trManager/Export.h>
26 
27 #include <trManager/MessageBase.h>
28 #include <trBase/SmrtClass.h>
29 #include <trBase/SmrtPtr.h>
30 #include <trUtil/Functor.h>
31 #include <trUtil/RefStr.h>
32 
33 #include <string>
34 
35 namespace trManager
36 {
38  {
39  public:
40  const static trUtil::RefStr CLASS_TYPE;
41 
49  virtual const std::string& GetType() const override { return CLASS_TYPE; }
50 
51  virtual void Call(const trManager::MessageBase& message) = 0;
52  };
53 
54  template <typename Message_T = trManager::MessageBase>
56  {
57  public:
59 
61  : mFunctor(func)
62  {
63  }
64 
65  virtual void Call(const trManager::MessageBase& message)
66  {
67  mFunctor(static_cast<const Message_T&>(message));
68  }
69  private:
71  };
72 
85  {
86  public:
87 
88  const static trUtil::RefStr CLASS_TYPE;
89 
97  virtual const std::string& GetType() const override { return CLASS_TYPE;}
98 
100 
101  template<typename Message_T>
102  Invokable(const std::string& name, trUtil::Functor<void, TYPELIST_1(const Message_T&)> toInvoke)
103  : mName(name)
104  , mCaller(new InvokableFunctorCaller<Message_T>(toInvoke))
105  {
106  }
107 
113  Invokable(const Invokable&) = delete;
114 
118  const std::string& GetName() const { return mName; }
119 
124  void Invoke(const trManager::MessageBase& message);
125  protected:
127  virtual ~Invokable();
128  private:
129  std::string mName;
130 
132 
133  Invokable& operator=(const Invokable&) { return *this; }
134  };
135 }
136 
static const trUtil::RefStr CLASS_TYPE
Definition: Invokable.h:88
Smart pointer for handling referenced counted objects.
Definition: SmrtPtr.h:36
const std::string & GetName() const
Definition: Invokable.h:118
virtual void Call(const trManager::MessageBase &message)
Definition: Invokable.h:65
An Invokable is a queriable method interface that can be added to a trManager::ActorBase Invoking the...
Definition: Invokable.h:84
A string wrapper that will make sure that all of the strings with the same value will point to the sa...
Definition: RefStr.h:50
virtual const std::string & GetType() const override
Holds the class type name for efficient comparisons.
Definition: Invokable.h:49
virtual const std::string & GetType() const override
Holds the class type name for efficient comparisons.
Definition: Invokable.h:97
This class is part of the internal garbage collection system.
Definition: SmrtClass.h:38
Invokable(const std::string &name, trUtil::Functor< void, TYPELIST_1(const Message_T &)> toInvoke)
Definition: Invokable.h:102
std::string mName
Definition: Invokable.h:129
InvokableFunctorCaller(InvokableFunc func)
Definition: Invokable.h:60
Invokable & operator=(const Invokable &)
Definition: Invokable.h:133
#define TYPELIST_1(T1)
Definition: TypeList.h:130
static const trUtil::RefStr CLASS_TYPE
Definition: Invokable.h:40
This is the base class for all the messages in TR.
Definition: MessageBase.h:40
#define TR_MANAGER_EXPORT
trBase::SmrtPtr< InvokableFunctorCallerBase > mCaller
Definition: Invokable.h:131