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 
00035 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3