TrueReality  v0.1.1912
MessageBase.cpp
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 Maxim Serebrennik
20 */
21 
22 #include <trManager/MessageBase.h>
23 
24 #include <trUtil/Logging/Log.h>
25 
26 
27 namespace trManager
28 {
29  const trUtil::RefStr MessageBase::MESSAGE_TYPE("trManager::MessageBase");
30 
32  MessageBase::MessageBase(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const bool isDirect, const std::string &messageFilter)
33  {
34  LOG_D("Creating a message: " + mId.ToString())
35  mFromActorID = fromActorID;
36  mAboutActorID = aboutActorID;
37  mIsDirect = isDirect;
38  mMessageFilter = &messageFilter;
39  }
40 
43  {
44  LOG_D("Destroying a message: " + mId.ToString())
45  }
46 
48  bool MessageBase::operator==(const MessageBase& msg) const
49  {
50  if ((&msg) == this)
51  {
52  return true;
53  }
54 
55  if (mFromActorID != msg.mFromActorID ||
57  mIsDirect != msg.mIsDirect ||
59  {
60  return false;
61  }
62 
63  return true;
64  }
65 
67  const std::string& MessageBase::GetType() const
68  {
69  return MESSAGE_TYPE;
70  }
71 
74  {
75  return mFromActorID.get();
76  }
77 
80  {
81  return mAboutActorID.get();
82  }
83 
85  const bool& MessageBase::GetIsDirect() const
86  {
87  return mIsDirect;
88  }
89 
91  const std::string& MessageBase::GetMessageFilter()
92  {
93  return *mMessageFilter;
94  }
95 }
trBase::UniqueId mId
Definition: MessageBase.h:132
This class creates a GUID, or a Unique ID that is used through out TR to identify and distinguish one...
Definition: UniqueId.h:42
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
MessageBase(const trBase::UniqueId *fromActorID, const trBase::UniqueId *aboutActorID=NULL, const bool isDirect=false, const std::string &messageFilter=trUtil::StringUtils::STR_BLANK)
Holds the class/message type name for efficient comparisons.
Definition: MessageBase.cpp:32
const std::string * mMessageFilter
Definition: MessageBase.h:131
static const trUtil::RefStr MESSAGE_TYPE
Adds an easy and swappable access to the base class.
Definition: MessageBase.h:46
virtual const trBase::UniqueId * GetAboutActorID() const
Returns the ID of the actor this message is about, or sent to.
Definition: MessageBase.cpp:79
virtual const trBase::UniqueId * GetFromActorID() const
Returns the ID of the actor the message was sent from.
Definition: MessageBase.cpp:73
trBase::ObsrvrPtr< const trBase::UniqueId > mAboutActorID
Definition: MessageBase.h:129
trBase::ObsrvrPtr< const trBase::UniqueId > mFromActorID
Definition: MessageBase.h:129
virtual const bool & GetIsDirect() const
Returns True if this message is a direct message and skips all Directors.
Definition: MessageBase.cpp:85
virtual const std::string & GetType() const override
Returns the class type Made protected to hide it.
Definition: MessageBase.cpp:67
const std::string ToString() const
Convert the current GUID into a string.
Definition: UniqueId.cpp:294
This is the base class for all the messages in TR.
Definition: MessageBase.h:40
virtual const std::string & GetMessageFilter()
Returns the custom Filter string.
Definition: MessageBase.cpp:91
#define LOG_D(msg)
Log a DEBUG message.
Definition: Log.h:138