Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Resource.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_Resource_h_
00003 #define INCLUDED_Resource_h_
00004 
00005 //! Provides a generic interface for resources which need to keep track of when they are in use, such as mutex locks
00006 class Resource {
00007 public:
00008   //! base class for holding data required for requesting to use/release the resource
00009   class Data {
00010   public:
00011     virtual ~Data() {} //!< empty virtual destructor to mark this as a base class
00012   };
00013   static Data emptyData; //!< to use as the data reference when none is needed/specified
00014   
00015   //! destructor (does nothing -- up to subclass if they need to release resource)
00016   virtual ~Resource() {}
00017   
00018   virtual void useResource(Data& d)=0; //!< marks the resource as in use
00019   virtual void releaseResource(Data& d)=0; //!< releases the resource
00020 };
00021 
00022 //! a no-op resource, since we don't want Resource itself to be directly instantiatable
00023 class EmptyResource : public Resource {
00024 public: 
00025   virtual void useResource(Data&) {} //!< would mark the resource in use, here is a no-op
00026   virtual void releaseResource(Data&) {} //!< would mark the resource no longer in use, here is a no-op
00027 };
00028 extern EmptyResource emptyResource; //!< a global instance of the empty resource, for no-op situations
00029 
00030 /*! @file
00031  * @brief Describes Resource (and EmptyResource), which provides a generic interface for resources which need to keep track of when they are in use, such as mutex locks
00032  * @author Ethan Tira-Thompson (ejt) (Creator)
00033  *
00034  * $Author: ejt $
00035  * $Name: tekkotsu-4_0 $
00036  * $Revision: 1.3 $
00037  * $State: Exp $
00038  * $Date: 2006/09/16 17:32:40 $
00039  */
00040 
00041 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4