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

Packet_Queue< Packet > Class Template Reference

#include <Packet_Queue.h>

Inheritance diagram for Packet_Queue< Packet >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class Packet>
class Packet_Queue< Packet >

This class demonstrates the use of the STL queue container adaptor in implementing a message queue.

Packet Queues are a very important design pattern in embedded and real-time systems. Here we implement the Packet Queue class as a very thin wrapper over the STL queue container adaptor.

STL queue container adaptor supports the standard queue operations, viz. add to queue, remove from queue. STL allows you to specify the underlying container used for implementing the queue. By changing one line of code you could change from a linked list implementation to an array like double ended queue In this example we will be implementing the queue using the list. This organizes the message queue as a linked list of nodes containing pointers to the message.

Definition at line 29 of file Packet_Queue.h.

Public Member Functions

void Add (Packet *p_Packet)
 Add a message to the end of the queue.

Packet * Remove ()
 Remove a message from the head of the queue.

size_t Get_Length () const
 Obtain the length of the queue.


Private Types

typedef queue< Packet *, list<
Packet * > > 
Packet_Queue_Type
 Declaring the type for a queue.


Private Attributes

Packet_Queue_Type m_packet_Queue
 Declaration of the message queue based on the type declaration Packet_Queue_Type.


Member Typedef Documentation

template<class Packet>
typedef queue<Packet *, list<Packet *> > Packet_Queue< Packet >::Packet_Queue_Type [private]
 

Declaring the type for a queue.

Here we are specifying a queue of message pointers organized as a linked list.

Definition at line 33 of file Packet_Queue.h.


Member Function Documentation

template<class Packet>
void Packet_Queue< Packet >::Add Packet * p_Packet  ) [inline]
 

Add a message to the end of the queue.

The push method supported by queue is used to add the message to the end of the queue. Note that all the memory management associated with the queue container management is taken care by STL.

Parameters:
p_Packet Pointer to the message that needs to be added to the queue.

Definition at line 45 of file Packet_Queue.h.

00046    {
00047       // Insert the element at the end of the queue
00048       m_packet_Queue.push(p_Packet);
00049    }

template<class Packet>
Packet* Packet_Queue< Packet >::Remove  ) [inline]
 

Remove a message from the head of the queue.

Returns NULL if no message is found. This method performs the following steps:

  • Make sure that the queue is not empty
  • If so, get a pointer to the message at the head of the queue.
  • Now pop the message out of the queue.

retval Packet Pointer to the message removed from the queue. Returns NULL if no message is found in the queue.

Definition at line 61 of file Packet_Queue.h.

00062    {
00063       Packet *p_Packet = NULL;
00064       
00065       // Check if the message queue is not empty
00066       if (!m_packet_Queue.empty())
00067       {
00068          // Queue is not empty so get a pointer to the
00069          // first message in the queue
00070          p_Packet = m_packet_Queue.front();
00071          
00072          // Now remove the pointer from the message queue
00073          m_packet_Queue.pop();
00074       }
00075       return p_Packet;
00076    }

template<class Packet>
size_t Packet_Queue< Packet >::Get_Length  ) const [inline]
 

Obtain the length of the queue.

The size method is used to obtain the queue length.

Return values:
int Total number of messages in the queue.

Definition at line 81 of file Packet_Queue.h.

00082    {
00083       return m_packet_Queue.size();
00084    }   


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.