#include <scoped_resource.hpp>
Public Types | |
typedef T | resource_type |
typedef ReleasePolicy | release_type |
Public Member Functions | |
scoped_resource (resource_type res=resource_type()) | |
Constructor. | |
virtual | ~scoped_resource () |
The destructor is the main point in this class. | |
operator resource_type () const | |
This operator makes sure you can access and use the scoped_resource just like you were using the resource itself. | |
resource_type | get () const |
This function provides explicit access to the resource. | |
resource_type | operator-> () const |
This function provides convenient direct access to the -> operator if the underlying resource is a pointer. | |
void | assign (const resource_type &o) |
Private Member Functions | |
scoped_resource (const scoped_resource &) | |
scoped_resource & | operator= (const scoped_resource &) |
Private Attributes | |
T | resource |
scoped_resource is designed to be used when a resource is initialized at the beginning or middle of a scope, and released at the end of the scope. The template argument ReleasePolicy is a functor which takes an argument of the type of the resource, and releases it.
Usage example, for working with files:
struct close_file { void operator()(int fd) const {close(fd);} }; ... { const scoped_resource<int,close_file> file(open("file.txt",O_RDONLY)); read(file, buf, 1000); } // file is automatically closed here
Note that scoped_resource has an explicit constructor, and prohibits copy-construction, and thus the initialization syntax. The assignment syntax must be used when initializing.
I.e. using scoped_resource<int,close_file> file = open("file.txt",O_RDONLY); in the above example is illegal.
Definition at line 58 of file scoped_resource.hpp.
typedef T util::scoped_resource< T, ReleasePolicy >::resource_type |
Definition at line 66 of file scoped_resource.hpp.
typedef ReleasePolicy util::scoped_resource< T, ReleasePolicy >::release_type |
Definition at line 67 of file scoped_resource.hpp.
util::scoped_resource< T, ReleasePolicy >::scoped_resource | ( | const scoped_resource< T, ReleasePolicy > & | ) | [private] |
util::scoped_resource< T, ReleasePolicy >::scoped_resource | ( | resource_type | res = resource_type() |
) | [inline] |
Constructor.
res | This is the resource to be managed |
Definition at line 74 of file scoped_resource.hpp.
virtual util::scoped_resource< T, ReleasePolicy >::~scoped_resource | ( | ) | [inline, virtual] |
The destructor is the main point in this class.
It takes care of proper deletion of the resource, using the provided release policy.
Definition at line 82 of file scoped_resource.hpp.
scoped_resource& util::scoped_resource< T, ReleasePolicy >::operator= | ( | const scoped_resource< T, ReleasePolicy > & | ) | [private] |
util::scoped_resource< T, ReleasePolicy >::operator resource_type | ( | ) | const [inline] |
This operator makes sure you can access and use the scoped_resource just like you were using the resource itself.
Definition at line 93 of file scoped_resource.hpp.
resource_type util::scoped_resource< T, ReleasePolicy >::get | ( | ) | const [inline] |
This function provides explicit access to the resource.
Its behaviour is identical to operator resource_type()
Definition at line 101 of file scoped_resource.hpp.
Referenced by gui::floating_textbox::active(), surface::assign(), surface::get(), map_editor::new_map_dialog(), surface::null(), surface::operator SDL_Surface *(), surface::operator->(), random_generate_map(), surface::surface(), and write_file().
resource_type util::scoped_resource< T, ReleasePolicy >::operator-> | ( | ) | const [inline] |
This function provides convenient direct access to the -> operator if the underlying resource is a pointer.
Only call this function if resource_type is a pointer type.
Definition at line 108 of file scoped_resource.hpp.
void util::scoped_resource< T, ReleasePolicy >::assign | ( | const resource_type & | o | ) | [inline] |
Definition at line 110 of file scoped_resource.hpp.
Referenced by surface::assign(), gui::widget::bg_restore(), gui::floating_textbox::close(), gui::widget::draw(), mp::gamebrowser::draw(), gui::menu::draw(), mp::create::hide_children(), map_editor::new_map_dialog(), mp::create::process_event(), and gui::floating_textbox::show().
T util::scoped_resource< T, ReleasePolicy >::resource [private] |
Definition at line 60 of file scoped_resource.hpp.
Referenced by util::scoped_resource< SDL_Surface *, surface::free_sdl_surface >::assign(), util::scoped_resource< SDL_Surface *, surface::free_sdl_surface >::get(), util::scoped_resource< SDL_Surface *, surface::free_sdl_surface >::operator resource_type(), util::scoped_resource< SDL_Surface *, surface::free_sdl_surface >::operator->(), and util::scoped_resource< SDL_Surface *, surface::free_sdl_surface >::~scoped_resource().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |