EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Priority_Message_Queue Class Reference

#include <Priority_Message_Queue.h>

List of all members.


Detailed Description

This class queues up messages according to the priority assigned to the message at the time of adding it to the queue.

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.


Member Typedef Documentation

typedef priority_queue<Entry, vector<Entry>, Compare_Messages > Priority_Message_Queue::Message_Queue_Type [private]
 

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.


Member Function Documentation

void Priority_Message_Queue::Add Message * pMsg,
int priority
[inline]
 

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.

Parameters:
pMsg Pointer to the message being enqueued.
priority Priority to be assigned to the message. Note that priority is treated as an integer number. So 3 is higher priority than 2.

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    }

Message* Priority_Message_Queue::Remove  ) [inline]
 

Remove a message from the queue.

Returns NULL if no message is found.

This method performs the following steps:

  • Check if the queue is empty. If empty, just return NULL.
  • If the queue is not empty, get the message from the entry at the top
  • Pop out the Entry at the top. This removes the Entry from the queue.

Return values:
Message* Pointer to the message extracted from the queue. NULL is returned if no message is found in the queue.

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    }

size_t Priority_Message_Queue::Get_Length  ) const [inline]
 

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    }   


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:33 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.