| EventStudio 2.5 Sequence diagram based system design and modeling | |
#include <Priority_Message_Queue.h> Messages with higher priority are added ahead of previously enqueued low priority messages.
The Message_Queue class always adds the message to the end of the queue. In many applications, the messages need to be queued according to their priority, i.e. when a message arrives, it is enqueued before any previously present low priority messages. We will be using the priority_queue container adaptor to implement the Priority_Message_Queue class.
Definition at line 24 of file Priority_Message_Queue.h.
Public Member Functions | |
| void | Add (Message *pMsg, int priority) |
| Add a message to the queue with the specified priority. | |
| Message * | Remove () |
| Remove a message from the queue. | |
| size_t | Get_Length () const |
| Obtain the length of the queue. | |
Private Types | |
| typedef priority_queue< Entry, vector< Entry >, Compare_Messages > | Message_Queue_Type |
| Declaring the type for a priority queue. | |
Private Attributes | |
| Message_Queue_Type | m_message_Queue |
| Declaration of the message queue. See the Message_Queue_Type for details. | |
|
Declaring the type for a priority queue. Here we are specifying a queue of message pointers organized as a vector. The Compare_Messages functor is also passed to the template as a parameter. Definition at line 65 of file Priority_Message_Queue.h. |
| ||||||||||||
Add a message to the queue with the specified priority. When removing the messages from the queue, messages with higher priority will be removed before messages with lower priority. This is independent of the order in which the messages were enqueued. This method creates an Entry by storing the message pointer and the priority. The push method is used to add the message to the m_message_Quueue. Note that STL will make a copy of this Entry. The copy will be stored in the internal data structures of the priority_queue.
Definition at line 84 of file Priority_Message_Queue.h. 00085 {
00086 // Make an entry
00087 Entry entry;
00088 entry.pMsg = pMsg;
00089 entry.priority = priority;
00090 // Insert the element according to its priority
00091 m_message_Queue.push(entry);
00092 }
|
|
Remove a message from the queue. Returns NULL if no message is found. This method performs the following steps:
Definition at line 104 of file Priority_Message_Queue.h. 00105 {
00106 Message *pMsg = NULL;
00107
00108 // Check if the message queue is not empty
00109 if (!m_message_Queue.empty())
00110 {
00111 // Queue is not empty so get a pointer to the
00112 // first message in the queue
00113 pMsg = (m_message_Queue.top()).pMsg;
00114
00115 // Now remove the pointer from the message queue
00116 m_message_Queue.pop();
00117 }
00118 return (pMsg);
00119 }
|
|
Obtain the length of the queue. The size method is used to obtain the length. retval size_t Number of entries currently in the queue. Definition at line 123 of file Priority_Message_Queue.h. 00124 {
00125 return m_message_Queue.size();
00126 }
|
1.3.4 | |
| Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved. |