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

Cold_Resource_Allocator.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include <queue>           // STL header file for queue
00009 #include <list>
00010 using namespace std;       // Specify that we are using the std namespace
00011 
00012 class Resource;
00013 
00020 
00021 class Cold_Resource_Allocator
00022 {
00029    typedef queue<Resource *, list<Resource *> > Free_Queue_Type;
00030 
00032    Free_Queue_Type m_free_Resource_Queue;
00033       
00034 public:
00035    
00040 
00041    Cold_Resource_Allocator(int resource_Count, Resource *resource_Array[])
00042    {
00043       for (int i = 0; i < resource_Count; i++)
00044       {
00045          m_free_Resource_Queue.push(resource_Array[i]);
00046       }
00047    }
00048 
00052 
00053    Resource * Allocate()
00054    {
00055       Resource *pResource = NULL;
00056       
00057       // Check if any free resources are available.
00058       if (!m_free_Resource_Queue.empty())
00059       {
00060          // Queue is not empty so get a pointer to the
00061          // first resource in the queue
00062          pResource = m_free_Resource_Queue.front();
00063          
00064          // Now remove the pointer from the free resource queue
00065          m_free_Resource_Queue.pop();
00066       }
00067       return pResource;
00068    }
00069    
00073 
00074    void Free(Resource *pResource)
00075    {
00076       // Insert the resource at the end of the free queue
00077       m_free_Resource_Queue.push(pResource);
00078    }
00079       
00082    size_t GetFreeResourceCount()
00083    {
00084       return m_free_Resource_Queue.size();
00085    }   
00086 };

Generated on Sun Feb 13 21:30:16 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.