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

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