Topic priority sorting class. More...
#include <topic_priority.h>
Public Member Functions | |
Usage | |
The correct use of this class is extremely simple, the used must only declare this class with a copy constructible and assignable class type, boost shared pointers are recommended. Function push_msg() add a new message to the queue while top_msg() returns a pointer to the current command message that should be respected while doing the necessary maintenance() to the list. The template type cmd_type must be a pointer to a class with variables lifetime and priority. Lifetime is the number of seconds that this message will live after arrival and priority is a positive integer value, with higher priority values overriding lower priority messages. | |
void | push_msg (cmd_type msg) |
Add new command message. | |
cmd_type | top_msg (void) |
Return the current command message. | |
Private Member Functions | |
void | maintenance (void) |
Do maintenance on the message map. | |
Private Attributes | |
std::map< int, cmd_type >::iterator | it |
Iterator for the messages. | |
std::map< int, cmd_type > | message_map |
Map of all the messages received. |
Topic priority sorting class.
This class was developed to simplify the lifetime/priority scheme used in the command messages, the use of this class guaranties that the command message being used fits the parameters.
Definition at line 45 of file topic_priority.h.
void TopicQueuePriority< cmd_type >::maintenance | ( | void | ) | [inline, private] |
Do maintenance on the message map.
Remove messages that are past their lifetime.
Definition at line 121 of file topic_priority.h.
void TopicQueuePriority< cmd_type >::push_msg | ( | cmd_type | msg | ) | [inline] |
Add new command message.
Add or replace a command message of a given priority, it replaces if a message with the same priority was already received.
msg | new message |
Definition at line 71 of file topic_priority.h.
cmd_type TopicQueuePriority< cmd_type >::top_msg | ( | void | ) | [inline] |
Return the current command message.
Returns the message with the most priority that is still alive
Definition at line 92 of file topic_priority.h.
std::map<int,cmd_type>::iterator TopicQueuePriority< cmd_type >::it [private] |
Iterator for the messages.
Definition at line 50 of file topic_priority.h.
std::map<int,cmd_type> TopicQueuePriority< cmd_type >::message_map [private] |
Map of all the messages received.
Definition at line 48 of file topic_priority.h.