SuperTuxKart
Loading...
Searching...
No Matches
profile_manager.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2013-2015 Glenn De Jonghe
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_ONLINE_PROFILE_MANAGER_HPP
20#define HEADER_ONLINE_PROFILE_MANAGER_HPP
21
22#include "utils/types.hpp"
23
24#include <irrString.h>
25
26#include <assert.h>
27#include <map>
28#include <string>
29
30namespace Online
31{
32 class OnlineProfile;
33
43{
44private:
47
50
52 typedef std::map<uint32_t, OnlineProfile*> ProfilesMap;
53
58
63
67
71 unsigned int m_max_cache_size;
72
73 void updateCacheBits(OnlineProfile *profile);
74 void addDirectToCache(OnlineProfile *profile);
75 void updateFriendFlagsInCache(const ProfilesMap &cache,
76 uint32_t profile_id);
77 void updateAllFriendFlags(const OnlineProfile *profile);
78public:
80 static void create()
81 {
82 assert(!m_profile_manager);
84 } // create
85
86 // ----------------------------------------------------------------
91 {
92 assert(m_profile_manager);
93 return m_profile_manager;
94 } // get
95 // ----------------------------------------------------------------
97 static void destroy()
98 {
99 delete m_profile_manager;
100 m_profile_manager = NULL;
101 } // destroy
102 // ----------------------------------------------------------------
103
104 void addToCache(OnlineProfile *profile);
106 void deleteFromPersistent(const uint32_t id);
107 void clearPersistent();
108 void moveToCache(const uint32_t id);
109 int guaranteeCacheSize(unsigned int max_num);
110 bool isInCache(const uint32_t id);
111 bool inPersistent(const uint32_t id);
112 OnlineProfile* getProfileByID(const uint32_t id);
113
114 // ----------------------------------------------------------------
118 void setVisiting(const uint32_t id)
119 {
121 } // setVisiting
122
123 // ----------------------------------------------------------------
127
128}; // class CurrentUser
129} // namespace Online
130#endif // HEADER_ONLINE_PROFILE_MANAGER_HPP
Class that represents an online profile.
Definition: online_profile.hpp:42
Class that manages all online profiles.
Definition: profile_manager.hpp:43
void updateFriendFlagsInCache(const ProfilesMap &cache, uint32_t profile_id)
This function is called when the specified profile id is removed from cache.
Definition: profile_manager.cpp:176
void clearPersistent()
Deletes all persistent profiles.
Definition: profile_manager.cpp:295
OnlineProfile * getProfileByID(const uint32_t id)
Search for a given profile in the set of persistent and cached entries.
Definition: profile_manager.cpp:86
ProfilesMap m_profiles_cache
Any profiles that don't go into the persistent map, go here.
Definition: profile_manager.hpp:62
bool isInCache(const uint32_t id)
Checks if a profile is in cache.
Definition: profile_manager.cpp:156
void addDirectToCache(OnlineProfile *profile)
Initialisation before the object is displayed.
Definition: profile_manager.cpp:123
std::map< uint32_t, OnlineProfile * > ProfilesMap
The mapping of ids to profile.
Definition: profile_manager.hpp:52
static void destroy()
Destroys the singleton.
Definition: profile_manager.hpp:97
bool inPersistent(const uint32_t id)
True if the profile with the given id is persistent.
Definition: profile_manager.cpp:244
void updateCacheBits(OnlineProfile *profile)
This function updates the cache bits of all cached entries.
Definition: profile_manager.cpp:216
int guaranteeCacheSize(unsigned int max_num)
Makes sure that the cache can store at least max_num entries.
Definition: profile_manager.cpp:66
OnlineProfile * getVisitingProfile()
Definition: profile_manager.hpp:126
void moveToCache(const uint32_t id)
Removes a currently persistent profile to the cache (where it can be deleted later).
Definition: profile_manager.cpp:311
ProfileManager()
Private constructor, used by static create() function.
Definition: profile_manager.cpp:40
static void create()
Create the singleton instance.
Definition: profile_manager.hpp:80
ProfilesMap m_profiles_persistent
A map of profiles that is persistent.
Definition: profile_manager.hpp:57
void deleteFromPersistent(const uint32_t id)
Removes and deletes an entry from the persistent map.
Definition: profile_manager.cpp:276
~ProfileManager()
Destructor, which frees the persistent and cached data.
Definition: profile_manager.cpp:49
OnlineProfile * addPersistent(OnlineProfile *profile)
Adds a profile to the persistent map.
Definition: profile_manager.cpp:256
void updateAllFriendFlags(const OnlineProfile *profile)
This function is called when the specified profile is removed from cache.
Definition: profile_manager.cpp:200
void setVisiting(const uint32_t id)
Marks a given profile to be the currently visited one.
Definition: profile_manager.hpp:118
OnlineProfile * m_currently_visiting
A temporary profile that is currently being 'visited', e.g.
Definition: profile_manager.hpp:66
static ProfileManager * get()
Returns the singleton.
Definition: profile_manager.hpp:90
void addToCache(OnlineProfile *profile)
Adds profile to the cache.
Definition: profile_manager.cpp:105
static ProfileManager * m_profile_manager
Singleton pointer.
Definition: profile_manager.hpp:46
unsigned int m_max_cache_size
The max size of the m_profiles cache.
Definition: profile_manager.hpp:71
Declares the general types that are used by the network.