100 lines
3.1 KiB
C++
100 lines
3.1 KiB
C++
/*
|
|
* File: UnicastMessageList.h
|
|
* Author: jgaebler
|
|
*
|
|
* Created on October 30, 2012, 3:35 PM
|
|
*/
|
|
#pragma once
|
|
|
|
#ifndef UNICASTMESSAGELIST_H
|
|
#define UNICASTMESSAGELIST_H
|
|
|
|
#include "common/container/List.h"
|
|
|
|
#include "msg/UnicastMessage.h"
|
|
#include "common/Exception.h"
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
/**
|
|
* @brief Defines a list to store unicast messages
|
|
* @ingroup Moversight
|
|
* @class UnicastMessageList
|
|
* @author Jan Gäbler
|
|
*/
|
|
class UnicastMessageList : public List<UnicastMessage * > {
|
|
public:
|
|
|
|
/**
|
|
* @brief Checks, if the message identified by the given message reference already stored in the queue.
|
|
* @param mRef The message reference to check
|
|
* @return True, if the message stored in the list, false otherwise.
|
|
*/
|
|
bool contains(MessageReference const & mRef) const {
|
|
|
|
for (size_t i = 0; i < size(); i++) {
|
|
|
|
if (get(i) != NULL) {
|
|
MessageReference pmRef = get(i)->getMessageReference();
|
|
if (pmRef == mRef) {
|
|
return true;
|
|
}//end if
|
|
}//end if
|
|
}//end for
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Searches the message for the given message reference and
|
|
* returns that message. If no message found, an
|
|
* EntryNotFoundException is thrown.
|
|
* @param mRef The message reference pointing to a message stored in
|
|
* the queue.
|
|
* @return The desired message, if stored.
|
|
* @throw EntryNotFoundException If no message stored with the given
|
|
* message reference.
|
|
*/
|
|
UnicastMessage * find(MessageReference const & mRef) const {
|
|
|
|
for (size_t i = 0; i < size(); i++) {
|
|
|
|
if (get(i) != NULL) {
|
|
MessageReference pmRef = get(i)->getMessageReference();
|
|
if (pmRef == mRef) {
|
|
return get(i);
|
|
}//end if
|
|
}//end if
|
|
}//end for
|
|
|
|
throw EntryNotFoundException("the given message reference points not to an stored message");
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Removes the message from the queue, identified by the
|
|
* message reference.
|
|
* @param mRef The message reference identifying the message to delete.
|
|
*/
|
|
void removeByMessageReference(MessageReference const & mRef) {
|
|
|
|
for(size_t i=0; i<size(); i++){
|
|
|
|
if (get(i) != NULL) {
|
|
MessageReference pmRef = get(i)->getMessageReference();
|
|
if (pmRef == mRef) {
|
|
remove(get(i));
|
|
return;
|
|
}//end if
|
|
}//end if
|
|
}//End for
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif /* UNICASTMESSAGELIST_H */
|
|
|