ManaPlus
chatobject.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "resources/chatobject.h"
23 
24 #include "debug.h"
25 
26 std::map<std::string, ChatObject*> ChatObject::chatNameMap;
27 std::map<int, ChatObject*> ChatObject::chatIdMap;
28 
30  ownerId(BeingId_zero),
31  chatId(0),
32  maxUsers(0),
33  currentUsers(0),
34  type(0),
35  title()
36 {
37 }
38 
40 {
41  std::map<std::string, ChatObject*>::iterator it = chatNameMap.find(title);
42  if (it != chatNameMap.end() && (*it).second == this)
43  chatNameMap.erase(it);
44  std::map<int, ChatObject*>::iterator it2 = chatIdMap.find(chatId);
45  if (it2 != chatIdMap.end() && (*it2).second == this)
46  chatIdMap.erase(it2);
47 }
48 
50 {
51  chatNameMap[title] = this;
52  chatIdMap[chatId] = this;
53 }
54 
55 ChatObject *ChatObject::findByName(const std::string &name)
56 {
57  const std::map<std::string, ChatObject*>::iterator it =
58  chatNameMap.find(name);
59  if (it == chatNameMap.end())
60  return nullptr;
61  return (*it).second;
62 }
63 
65 {
66  const std::map<int, ChatObject*>::iterator it = chatIdMap.find(id);
67  if (it == chatIdMap.end())
68  return nullptr;
69  return (*it).second;
70 }
const BeingId BeingId_zero
Definition: beingid.h:30
static ChatObject * findByName(const std::string &name)
Definition: chatobject.cpp:55
std::string title
Definition: chatobject.h:51
static std::map< int, ChatObject * > chatIdMap
Definition: chatobject.h:54
static ChatObject * findById(const int id)
Definition: chatobject.cpp:64
int chatId
Definition: chatobject.h:47
void update()
Definition: chatobject.cpp:49
static std::map< std::string, ChatObject * > chatNameMap
Definition: chatobject.h:53