Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2010, 10:59:01 PM (14 years ago)
Author:
dafrick
Message:

Finished EditMode, needs some polish (no not the language…) though.
Took better advantage of lua tables in NotificationLayer.lua
Fixed a lot of bugs, it really is a miracle that the Notifications worked as well as they did.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/src/modules/notifications/NotificationQueue.cc

    r7354 r7395  
    3535
    3636#include <map>
     37#include <sstream>
    3738
    3839#include "core/CoreIncludes.h"
     
    6263        this->setDisplayTime(displayTime);
    6364
     65        bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
     66        this->registered_ = true;
     67        if(!queueRegistered)
     68        {
     69            this->registered_ = false;
     70            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
     71            return;
     72        }
     73
    6474        this->create();
    65 
    66         NotificationManager::getInstance().registerListener(this);
    67         this->registered_ = true;
     75       
     76        bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
     77        if(!listenerRegistered)
     78        {
     79            this->registered_ = false;
     80            NotificationManager::getInstance().unregisterQueue(this);
     81            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
     82            return;
     83        }
    6884
    6985        COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
     
    7793    {
    7894        this->targets_.clear();
    79         this->clear();
    8095
    8196        if(this->registered_)
     97        {
     98            this->clear();
     99           
    82100            NotificationManager::getInstance().unregisterListener(this);
     101            NotificationManager::getInstance().unregisterQueue(this);
     102        }
    83103    }
    84104
     
    100120    void NotificationQueue::create(void)
    101121    {
    102         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
     122        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    103123    }
    104124
     
    144164        }
    145165
    146         if(notifications->empty())
    147             return;
    148 
    149         for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
    150             this->push(it->second, it->first);
     166        if(!notifications->empty())
     167        {
     168            for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
     169            {
     170                this->push(it->second, it->first);
     171            }
     172        }
    151173
    152174        delete notifications;
    153175
    154         COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
     176        COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4.
    155177    }
    156178
     
    167189        this->push(notification, time);
    168190
    169         COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
     191        COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4.
    170192    }
    171193
     
    253275    bool NotificationQueue::setName(const std::string& name)
    254276    {
    255         //TODO: Test uniqueness of name.
    256277        this->name_ = name;
    257278        return true;
     
    268289    void NotificationQueue::setMaxSize(unsigned int size)
    269290    {
     291        if(this->maxSize_ == size)
     292            return;
     293       
    270294        this->maxSize_ = size;
    271295        this->sizeChanged();
     
    292316    void NotificationQueue::setDisplayTime(unsigned int time)
    293317    {
     318        if(this->displayTime_ == time)
     319            return;
     320
    294321        this->displayTime_ = time;
    295         this->update();
     322
     323        if(this->registered_)
     324            this->update();
    296325    }
    297326
     
    299328    @brief
    300329        Produces all targets concatinated as string, with kommas (',') as seperators.
    301     @param string
    302         Pointer to a string which will be used by the method to fill with the concatination of the targets.
    303     @return
    304         Returns true if successful.
    305     */
    306     bool NotificationQueue::getTargets(std::string* string) const
    307     {
    308         if(string == NULL)
    309         {
    310             COUT(4) << "Input string must have memory allocated." << std::endl;
    311             return false;
    312         }
    313         string->clear();
     330    @return
     331        Returns the targets as a string.
     332    */
     333    const std::string& NotificationQueue::getTargets(void) const
     334    {
     335        std::stringstream stream;
    314336        bool first = true;
    315         for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
     337        for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
    316338        {
    317339            if(!first)
    318                 *string += ',';
     340                stream << ',';
    319341            else
    320342                first = false;
    321             *string += *it;
    322         }
    323 
    324         return true;
     343            stream << *it;
     344        }
     345
     346        return *(new std::string(stream.str()));
    325347    }
    326348
     
    352374        }
    353375
     376        if(this->registered_)
     377        {
     378            NotificationManager::getInstance().unregisterListener(this);
     379            NotificationManager::getInstance().registerListener(this);
     380        }
     381
    354382        return true;
    355383    }
Note: See TracChangeset for help on using the changeset viewer.