Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ResourceAccessor.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ResourceAccessor_h_
00003 #define INCLUDED_ResourceAccessor_h_
00004 
00005 #include "MarkScope.h"
00006 
00007 //! A variation of MarkScope which allows you to forward access to the resource via the '->' operator, smart-pointer style
00008 template <class R>
00009 class ResourceAccessor : public MarkScope {
00010 public:
00011   //! constructor, for marking resources which require no data
00012   ResourceAccessor(R& r) : MarkScope(r) {}
00013   //! constructor, accepts data parameter to pass to Resource::useResource()
00014   ResourceAccessor(R& r, Resource::Data& d) : MarkScope(r,d) {}
00015   //! copy constructor, marks resource used with default (empty) data
00016   ResourceAccessor(const ResourceAccessor& ra) : MarkScope(ra) {}
00017   //! copy constructor, accepts additional data parameter to pass to Resource::useResource()
00018   ResourceAccessor(const ResourceAccessor& ra, Resource::Data& d) : MarkScope(ra,d) {}
00019   
00020 #if !defined(__GNUC__) || __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ > 3))
00021   //! returns #rsrc cast as R
00022   inline R& accessResource() const __attribute__ ((warn_unused_result)) {
00023     return dynamic_cast<R&>(rsrc);
00024   }
00025 #else
00026   //! returns #rsrc cast as R
00027   inline R& accessResource() const {
00028     return dynamic_cast<R&>(rsrc);
00029   }
00030 #endif
00031   
00032   R* operator->() { return &accessResource(); } //!< smart pointer to the underlying Resource
00033   const R* operator->() const { return &accessResource(); } //!< smart pointer to the underlying Resource
00034   R& operator*() { return accessResource(); } //!< smart pointer to the underlying Resource
00035   const R& operator*() const { return accessResource(); } //!< smart pointer to the underlying Resource
00036   R& operator[](int i) { return (&accessResource())[i]; } //!< smart pointer to the underlying Resource
00037   const R& operator[](int i) const { return (&accessResource())[i]; } //!< smart pointer to the underlying Resource
00038 };
00039 
00040 /*! @file
00041  * @brief Describes ResourceAccessor, a variation of MarkScope which allows you to forward access to the resource via the '->' operator, smart-pointer style
00042  * @author Ethan Tira-Thompson (ejt) (Creator)
00043  *
00044  * $Author: ejt $
00045  * $Name: tekkotsu-4_0 $
00046  * $Revision: 1.2 $
00047  * $State: Exp $
00048  * $Date: 2006/09/16 17:32:40 $
00049  */
00050 
00051 #endif

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