Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/NotificationQueue.h @ 12196

Last change on this file since 12196 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 8.9 KB
RevLine 
[2280]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) 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, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2911]29/**
[7403]30    @file NotificationQueue.h
[2911]31    @brief Definition of the NotificationQueue class.
[7456]32    @ingroup Notifications
[2911]33*/
34
[2280]35#ifndef _NotificationOueue_H__
36#define _NotificationOueue_H__
37
[7164]38#include "notifications/NotificationsPrereqs.h"
[2911]39
[3196]40#include <ctime>
41#include <set>
[2911]42#include <string>
[7403]43#include <vector>
[2280]44
[7489]45#include "NotificationManager.h"
46
[8706]47#include "core/BaseObject.h"
[5633]48#include "tools/interfaces/Tickable.h"
[8706]49#include "network/synchronisable/Synchronisable.h"
[2280]50
[8706]51namespace orxonox
52{
[2911]53
[7552]54    /**
55    @brief
56        Container to allow easy handling of the @ref orxonox::Notification "Notifications".
57
58    @ingroup Notifications
59    */
[7403]60    struct NotificationContainer
[2911]61    {
[7489]62        Notification* notification; //!< The Notification displayed.
63        time_t time; //!< The time the Notification was sent and thus first displayed.
[2911]64    };
[5619]65
[7552]66    /**
67    @brief
68        Struct to allow ordering of @ref orxonox::NotificationContainer "NotificationContainers".
69
70    @ingroup Notifications
71    */
[7403]72    struct NotificationContainerCompare {
73        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
[7489]74            { return a->time < b->time; } //!< Ordering by time.
[2911]75    };
76
[2280]77    /**
78    @brief
[7484]79        Displays @ref orxonox::Notification "Notifications" from specific senders.
80
[8706]81        There are quite some parameters that influence the behavior of the NotificationQueue:
[7488]82        - @b name The name of the NotificationQueue. It needs to be unique.
83        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
84        - @b size The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
85        - @b displayTime The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
[7486]86
[2280]87    @author
88        Damian 'Mozork' Frick
[7552]89
90    @ingroup Notifications
[2280]91    */
[8706]92    class _NotificationsExport NotificationQueue : public BaseObject, public Tickable, public Synchronisable
93    {
[2911]94
95        public:
[9667]96            NotificationQueue(Context* context);
[2911]97            virtual ~NotificationQueue();
[5619]98
[11071]99            virtual void tick(float dt) override; // To update from time to time.
100            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
[5619]101
[11071]102            virtual void changedName(void) override;
[8706]103           
104            void update(void); // Updates the NotificationQueue.
105            void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification.
[5619]106
[7403]107            // tolua_begin
[2911]108            /**
[7403]109            @brief Get the name of the NotificationQueue.
110            @return Returns the name.
111            */
[8706]112            inline const std::string& getName(void) const
113                { return this->BaseObject::getName(); }
[7403]114
[8706]115            void setMaxSize(unsigned int size); // Sets the maximum number of displayed Notifications.
[7403]116            /**
[2911]117            @brief Returns the maximum number of Notifications displayed.
118            @return Returns maximum size.
119            */
[8706]120            inline unsigned int getMaxSize(void) const
[2911]121                { return this->maxSize_; }
[7403]122
[8706]123            void setDisplayTime(int time); // Sets the maximum number of seconds a Notification is displayed.
[2911]124            /**
125            @brief Returns the time interval the Notification is displayed.
126            @return Returns the display time.
127            */
[8706]128            inline int getDisplayTime(void) const
[2911]129                { return this->displayTime_; }
[7403]130            // tolua_end
[8706]131            void maxSizeChanged(void); // Is called when the maximum number of displayed Notifications has changed.
132            void displayTimeChanged(void);
[7403]133
[2911]134            /**
[7403]135            @brief Returns the current number of Notifications displayed.
136            @return Returns the size of the NotificationQueue.
[2911]137            */
[8706]138            inline unsigned int getSize(void) const
[7403]139                { return this->size_; }
[5619]140
[2911]141            /**
[7403]142            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
143            @return Returns a set of strings holding the different targets.
[2911]144            */
[8706]145            inline const std::set<std::string> & getTargetsSet(void)
[2911]146                { return this->targets_; }
[5619]147
[8706]148            void setTargets(const std::string & targets); // Set the targets of this NotificationQueue.
149            const std::string& getTargets(void) const; // Returns a string consisting of the concatenation of the targets.
150            void targetsChanged(void); // Is called when the NotificationQueue's targets have changed.
[2501]151
[8706]152            /**
153            @brief Check whether the NotificationQueue is registered with the NotificationManager.
154            @return Returns true if it is registered, false if not.
155            */
156            inline bool isRegistered(void)
157                { return this->registered_; }
158
159            bool tidy(void); // Pops all Notifications from the NotificationQueue.
160           
161        protected:
162            void registerVariables();
163           
164            /**
165            @brief Is called when a notification was pushed.
166            @param notification The Notification that was pushed.
167            */
168            virtual void notificationPushed(Notification* notification) {}
169            /**
170            @brief Is called when a notification was popped.
171            */
172            virtual void notificationPopped(void) {}
173            /**
174            @brief Is called when a notification was removed.
175            @param index The index the removed notification was at.
176            */
177            virtual void notificationRemoved(unsigned int index) {}
178           
179            virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers.
180
181        protected:
[7403]182            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
183            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
[8706]184            static const int INF = -1; //!< Constant denoting infinity.
[2501]185
[8706]186            virtual void create(void); // Creates the NotificationQueue.
[5619]187
[8706]188        private:
189            time_t creationTime_; //!< The time this NotificationQueue was created.
190           
[7403]191            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
192            unsigned int size_; //!< The number of Notifications displayed.
[8706]193            int displayTime_; //!< The time a Notification is displayed.
[5619]194
[7163]195            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
196
[7417]197            std::set<std::string> targets_; //!< The targets the NotificationQueue displays Notifications of.
[5619]198
[7403]199            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
200            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
[5619]201
[7403]202            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
203            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
[5619]204
[7403]205            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
[5619]206
[8706]207            void push(Notification* notification, const std::time_t & time); // Adds (pushes) a Notification to the NotificationQueue.
208            void pop(void); // Removes (pops) the least recently added Notification form the NotificationQueue.
209            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // Removes the Notification that is stored in the input NotificationContainer.
[5619]210
[8706]211    };
[5619]212
[8706]213}
[2280]214
[8706]215#endif /* _NotificationQueue_H__ */
Note: See TracBrowser for help on using the repository browser.