Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7456 was 7456, checked in by dafrick, 15 years ago

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • Property svn:eol-style set to native
File size: 6.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
[5633]45#include "tools/interfaces/Tickable.h"
[7403]46
[5619]47#include "interfaces/NotificationListener.h"
[7403]48#include "NotificationManager.h"
[2280]49
[7403]50namespace orxonox // tolua_export
51{ // tolua_export
[2911]52
53    //! Container to allow easy handling.
[7403]54    struct NotificationContainer
[2911]55    {
[7403]56        Notification* notification; //!< The Notification displayed.
[2911]57        time_t time; //!< The time the Notification was sent and thus first displayed.
58    };
[5619]59
[7403]60    //! Struct to allow ordering of NotificationContainers.
61    struct NotificationContainerCompare {
62        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
[2911]63            { return a->time < b->time; } //!< Ordered by time.
64    };
65
[2280]66    /**
67    @brief
[2911]68        Displays Notifications from specific senders.
[2280]69    @author
70        Damian 'Mozork' Frick
71    */
[7403]72    class _NotificationsExport NotificationQueue // tolua_export
73        : public Tickable, public NotificationListener
74    { // tolua_export
[2911]75
76        public:
[7403]77            NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
[2911]78            virtual ~NotificationQueue();
[5619]79
[7403]80            /**
81            @brief Destroys the NotificationQueue.
82                   Used in lua.
83            */
84            void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
[5619]85
[2911]86            virtual void tick(float dt); //!< To update from time to time.
[5619]87
[7403]88            void update(void); //!< Updates the NotificationQueue.
89            void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification.
[5619]90
[7403]91            // tolua_begin
[2911]92            /**
[7403]93            @brief Get the name of the NotificationQueue.
94            @return Returns the name.
95            */
96            inline const std::string& getName() const
97                { return this->name_; }
98
99            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
100            /**
[2911]101            @brief Returns the maximum number of Notifications displayed.
102            @return Returns maximum size.
103            */
[7403]104            inline unsigned int getMaxSize() const
[2911]105                { return this->maxSize_; }
[7403]106
107            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
[2911]108            /**
109            @brief Returns the time interval the Notification is displayed.
110            @return Returns the display time.
111            */
[7410]112            inline unsigned int getDisplayTime() const
[2911]113                { return this->displayTime_; }
[7403]114            // tolua_end
115
[2911]116            /**
[7403]117            @brief Returns the current number of Notifications displayed.
118            @return Returns the size of the NotificationQueue.
[2911]119            */
[7403]120            inline unsigned int getSize() const
121                { return this->size_; }
[5619]122
[2911]123            /**
[7403]124            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
125            @return Returns a set of strings holding the different targets.
[2911]126            */
[7417]127            inline const std::set<std::string> & getTargetsSet()
[2911]128                { return this->targets_; }
[5619]129
[7403]130            // tolua_begin
131            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
132            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
133            // tolua_end
[2501]134
[2911]135        private:
[7403]136            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
137            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
[2501]138
[7403]139            std::string name_; //!< The name of the NotificationQueue.
[5619]140
[7403]141            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
142            unsigned int size_; //!< The number of Notifications displayed.
143            unsigned int displayTime_; //!< The time a Notification is displayed.
[5619]144
[7163]145            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
146
[7417]147            std::set<std::string> targets_; //!< The targets the NotificationQueue displays Notifications of.
[5619]148
[7403]149            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
150            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
[5619]151
[7403]152            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
153            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
[5619]154
[7403]155            void create(void); //!< Creates the NotificationQueue in lua.
[2501]156
[7403]157            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
[5619]158
[7403]159            void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
160            void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
[7412]161            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer.
[5619]162
[7403]163            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
[5619]164
[7403]165    }; // tolua_export
[2280]166
[7403]167} // tolua_export
[2280]168
169#endif /* _NotificationOverlay_H__ */
Note: See TracBrowser for help on using the repository browser.