Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2858


Ignore:
Timestamp:
Mar 26, 2009, 9:45:23 PM (15 years ago)
Author:
dafrick
Message:

Done some documenting, and resolved some (possible) issues. So the Notifications are about finished…

Location:
code/branches/questsystem5/src/orxonox/overlays/notifications
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc

    r2788 r2858  
    174174    @param queue
    175175        The NotificationQueue the Notifications are fetched for.
     176    @param map
     177        A multimap, in which the notifications are stored.
    176178    @param timeFrameStart
    177179        The start time of the timeframe.
     
    179181        The end time of the timeframe.
    180182    @return
    181         Returns a time-ordered list of Notifications.
    182     @todo
    183         Make sure the map is deleted.
    184     */
    185     std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    186     {
    187         std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]];
    188        
    189         if(notifications == NULL)
    190             return NULL;
     183        Returns true if successful.
     184    */
     185    bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     186    {
     187        if(queue == NULL || map == NULL)
     188            return false;
     189
     190        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue.
     191       
     192        if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
     193            return true;
    191194   
    192195        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
     
    194197        itHighest = notifications->upper_bound(timeFrameStart);
    195198       
    196         std::multimap<std::time_t,Notification*>* map = new std::multimap<std::time_t,Notification*>();
    197        
    198         for(it = itLowest; it != itHighest; it++)
    199         {
    200             map->insert(std::pair<std::time_t,Notification*>(it->first,it->second));
    201         }
    202        
    203         if(map->size() == 0)
    204         {
    205             delete map;
    206             return NULL;
    207         }
    208        
    209         return map;
     199        for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
     200        {
     201            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
     202        }
     203       
     204        return true;
    210205    }
    211206
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h

    r2788 r2858  
    6666            static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
    6767
    68             //TDO: Visibility?
    6968            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    7069            bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
    7170           
    72             std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
     71            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
    7372           
    7473            /**
    7574            @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
    7675            @param queue The NotificationQueue the Notifications are fetched for.
     76            @param map A multimap, in which the notifications are stored.
    7777            @param timeFrameStart The start time the Notifications are fetched from.
    78             @return Returns a time-ordered list of Notifications.
     78            @return Returns true if successful.
    7979            */
    80             std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
    81                 { return this->getNotifications(queue, timeFrameStart, std::time(0)); }
     80            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
     81                { return this->getNotifications(queue, map, timeFrameStart, std::time(0)); }
    8282            /**
    8383            @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
    8484            @param queue The NotificationQueue the Notifications are fetched for.
     85            @param map A multimap, in which the notifications are stored.
    8586            @param timeDelay The timespan.
    86             @return Returns a time-ordered list of Notifications.
     87            @return Returns true if successful.
    8788            */
    88             std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
    89                 { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
     89            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay)
     90                { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
    9091     
    9192        private:
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc

    r2785 r2858  
    2727 */
    2828
     29/**
     30    @file NotificationOverlay.cc
     31    @brief Implementation of the NotificationOverlay class.
     32*/
     33
    2934#include "OrxonoxStableHeaders.h"
    3035#include "NotificationOverlay.h"
     
    4348{
    4449
     50    /**
     51    @brief
     52        Constructor. Intializes the class.
     53    */
    4554    NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
    4655    {
     
    4857    }
    4958
     59    /**
     60    @brief
     61        Constructor. Initilaizes the class creates a graphical representation of the input Notification for the input Queue.
     62    @param queue
     63        A pointer to the queue the NotificatonOverlay belongs to.
     64    @param notification
     65        A pointer to the Notification represented by this overlay.
     66    @throws Argument
     67        Throws an Argument-Exception if either no Notification or no NotificationQueue were input.
     68    */
    5069    NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this)
    5170    {
    5271        this->initialize();
    5372       
    54         if(notification == NULL || queue == NULL)
     73        if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
    5574        {
    5675            ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation.");
     
    6382    }
    6483   
     84    /**
     85    @brief
     86        Initializes and Registers the object.
     87    */
    6588    void NotificationOverlay::initialize(void)
    6689    {
     
    7093    }
    7194   
     95    /**
     96    @brief
     97        Set some Overlay-specific values.
     98    */
    7299    void NotificationOverlay::defineOverlay(void)
    73100    {
     
    78105    }
    79106
     107    /**
     108    @brief
     109        Destructor.
     110    */
    80111    NotificationOverlay::~NotificationOverlay()
    81112    {
    82113    }
    83114
     115    /**
     116    @brief
     117        Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message.
     118    @param notification
     119        A pointer to the notification that should be processed.
     120    @return
     121        Returns true if successful.
     122    */
    84123    bool NotificationOverlay::processNotification(Notification* notification)
    85124    {
     125        if(notification == NULL)
     126            return false;
    86127        this->setCaption(clipMessage(notification->getMessage()));
    87128        this->notification_ = notification;
     
    89130    }
    90131
     132    /**
     133    @brief
     134        Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue.
     135    */
    91136    const std::string NotificationOverlay::clipMessage(const std::string & message)
    92137    {
    93         if(message.length() <= (unsigned int)this->queue_->getNotificationLength())
     138        if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long.
    94139            return message;
    95140        return message.substr(0, this->queue_->getNotificationLength());
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h

    r2781 r2858  
    2727 */
    2828
     29/**
     30    @file NotificationOverlay.h
     31    @brief Definition of the NotificationOverlay class.
     32*/
     33
     34
    2935#ifndef _NotificationOverlay_H__
    3036#define _NotificationOverlay_H__
     
    4450    /**
    4551    @brief
    46        
     52        The NotificationOverlay is used to display single Notifications, then bundled in a NotificationQUeue.
    4753    @author
    4854        Damian 'Mozork' Frick
     
    5662            virtual ~NotificationOverlay();
    5763           
    58             bool processNotification(Notification* notification);
     64            bool processNotification(Notification* notification); //!< Processes the input Notification.
    5965
    60             void setFontSize(float size)
     66            /**
     67            @brief Sets the font size of this overlay's text.
     68            @param size The font size.
     69            */
     70            inline void setFontSize(float size)
    6171                { this->setTextSize(size); }
    6272       
    6373        protected:
    64             const std::string clipMessage(const std::string & message);
     74            const std::string clipMessage(const std::string & message); //!< Clips the input message if too long.
    6575
    6676        private:
    67             NotificationQueue* queue_;
    68             Notification* notification_;
     77            NotificationQueue* queue_; //!< The NotificationQeue this overlay belongs to.
     78            Notification* notification_; //!< The Notification this overlay displays.
    6979
    70             void initialize(void);
    71             void defineOverlay(void);
     80            void initialize(void); //!< Initializes the object.
     81            void defineOverlay(void); //!< Sets some overlay-specific values.
    7282
    7383    };
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc

    r2785 r2858  
    2727 */
    2828
     29/**
     30    @file NotificationQueue.cc
     31    @brief Implementation of the NotificationQueue class.
     32*/
     33
    2934#include "OrxonoxStableHeaders.h"
    3035#include "NotificationQueue.h"
     
    3338#include <OgreTextAreaOverlayElement.h>
    3439#include <list>
     40#include <iostream>
     41#include <sstream>
    3542
    3643#include "core/CoreIncludes.h"
     
    155162        this->clear();
    156163   
    157         std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_);
    158        
    159         if(notifications == NULL)
     164        std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>;
     165        if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time.
     166        {
     167            COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
    160168            return;
    161        
    162         for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
     169        }
     170       
     171        if(notifications->empty())
     172            return;
     173       
     174        for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
    163175        {
    164176            this->addNotification(it->second, it->first);
    165177        }
     178       
     179        delete notifications;
    166180       
    167181        COUT(3) << "NotificationQueue updated." << std::endl;
     
    343357    }
    344358
     359    /**
     360    @brief
     361        Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
     362    @param pos
     363        The vector the NotificationQueue is scrolled.
     364    */
    345365    void NotificationQueue::scroll(const Vector2 pos)
    346366    {
     
    351371    }
    352372
    353     void NotificationQueue::positionChanged()
     373    /**
     374    @brief
     375        Aligns all the Notifications to the position of the NotificationQueue.
     376    */
     377    void NotificationQueue::positionChanged(void)
    354378    {
    355379        int counter = 0;
     
    379403        std::string timeString = std::ctime(&time);
    380404        timeString.erase(timeString.length()-1);
    381         char buffer[64]; //TDO: Very un-nice.
    382         std::sprintf(buffer,"%x",(unsigned long)notification); //TDO: Use other conversion to avoid 64bit problems.
    383         std::string addressString = buffer;
     405        std::ostringstream stream;
     406        stream << (unsigned long)notification;
     407        std::string addressString = stream.str() ;
    384408        container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
    385409       
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h

    r2785 r2858  
    7171    @brief
    7272        Displays Notifications from specific senders.
     73        Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)
     74
     75        Creating a NotificationQueue through XML goes as follows:
     76        <NotificationQueue
     77            name = "SuperQueue" //Name of your OverlayQueue.
     78            maxSize = "5" //The maximum size of Notifications displayed.
     79            notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5)
     80            displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)
     81            targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)
     82            font = "VeraMono" //The font (Default is VeraMono)
     83            fontSize = '0.4' //The font size. (Default is 0.025)
     84            position = "0.0, .0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
     85        />
    7386    @author
    7487        Damian 'Mozork' Frick
     
    140153            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
    141154           
    142             inline void setPosition(Vector2 pos)
     155            /**
     156            @brief Sets the position of the NotificationQueue.
     157            @param pos The position.
     158            */
     159            inline void setPosition(Vector2 pos)
    143160                { this->position_ = pos; this->positionChanged(); }
    144161
    145             void scroll(const Vector2 pos);
     162            void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
    146163           
    147164        private:
     
    183200            bool setFont(const std::string & font); //!< Set the font.
    184201
    185             void positionChanged();
     202            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
    186203           
    187204            void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
Note: See TracChangeset for help on using the changeset viewer.