Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 13, 2009, 3:39:54 PM (16 years ago)
Author:
dafrick
Message:

Erradicated an infinite loop, and some wannabe-memory leaks. Also started the positioning of the notifications. I'd actually call it usable at this point.

File:
1 edited

Legend:

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

    r2779 r2783  
    5959    @brief
    6060        Destructor.
    61     @todo
    62         I'm pretty sure that there are some thing that have to be distroyed.
    6361    */
    6462    NotificationQueue::~NotificationQueue()
    6563    {
    66        
     64        this->targets_.clear();
     65        this->clear();
    6766    }
    6867   
     
    7675        RegisterObject(NotificationQueue);
    7776       
    78         this->setDefaults();
    7977        this->size_ = 0;
    8078        this->tickTime_ = 0.0;
     
    107105        SUPER(NotificationQueue, XMLPort, xmlElement, mode);
    108106       
     107        this->setDefaults();
     108
    109109        XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode);
    110110        XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode);
     
    135135            {
    136136                this->removeContainer(*it);
     137                this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
    137138                it = this->containers_.begin(); //TDO: Needed?
    138139            }
     
    176177        this->addNotification(notification, time);
    177178       
    178         //TDO: Position!
    179        
    180179        std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
    181180        while(this->getSize() > this->getMaxSize())
     
    183182            it = this->containers_.begin();
    184183            this->removeContainer(*it);
     184            this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
    185185        }
    186186       
     
    241241    /**
    242242    @brief
    243         Returns all targets concatinated as string, with kommas (',') as seperators.
    244     @return
    245         Returns all targets concatinated as string, with kommas (',') as seperators.
    246     @todo
    247         Where is the string deleted?
    248     */
    249     const std::string & NotificationQueue::getTargets() const
    250     {
    251         std::string* pTemp = new std::string("");
     243        Produces all targets concatinated as string, with kommas (',') as seperators.
     244    @param string
     245        Pointer to a string which will be used by the method to fill with the concatination of the targets.
     246    @return
     247        Returns true if successful.
     248    */
     249    bool NotificationQueue::getTargets(std::string* string) const
     250    {
     251        if(string == NULL)
     252        {
     253            COUT(4) << "Input string must have memory allocated." << std::endl;
     254            return false;
     255        }
     256        string->clear();
    252257        bool first = true;
    253258        for(std::set<std::string>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
     
    255260            if(!first)
    256261            {
    257                 *pTemp += ",";
     262                *string += ",";
    258263            }
    259264            else
     
    261266                first = false;
    262267            }
    263             *pTemp += *it;
    264         }
    265        
    266         return *pTemp;
     268            *string += *it;
     269        }
     270       
     271        return true;
    267272    }
    268273   
     
    278283    bool NotificationQueue::setTargets(const std::string & targets)
    279284    {
     285        this->targets_.clear();
     286
    280287        std::string* pTemp;
    281288        unsigned int index = 0;
     
    283290        {
    284291            pTemp = new std::string("");
    285             while(targets[index] != ',' && targets[index] != ' ' && index < targets.size())
     292            while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
    286293            {
    287294                *pTemp += targets[index];
    288295                index++;
    289296            }
     297            index++;
    290298            this->targets_.insert(*pTemp);
    291299        }
     
    331339        return true;
    332340    }
    333    
     341
     342    void NotificationQueue::scroll(const Vector2 pos)
     343    {
     344        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
     345        {
     346            it->second->overlay->scroll(pos);
     347        }
     348    }
     349
    334350    /**
    335351    @brief
     
    358374        this->insertElement(container->overlay, container->name);
    359375        this->size_= this->size_+1;
     376
     377        container->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*(this->getSize()-1)));
    360378    }
    361379   
Note: See TracChangeset for help on using the changeset viewer.