Back to index

libsfml  1.6+dfsg2
Public Member Functions | Private Attributes
sf::ResourcePtr< T > Class Template Reference

Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted when the resource is destroyed /////////////////////////////////////////////////////////. More...

#include <Resource.hpp>

Inheritance diagram for sf::ResourcePtr< T >:
Inheritance graph
[legend]
Collaboration diagram for sf::ResourcePtr< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ResourcePtr ()
 Default constructor.
 ResourcePtr (const T *Resource)
 Construct from a raw resource.
 ResourcePtr (const ResourcePtr< T > &Copy)
 Copy constructor.
 ~ResourcePtr ()
 Destructor.
ResourcePtr< T > & operator= (const ResourcePtr< T > &Other)
 Assignment operator from another ResourcePtr.
ResourcePtr< T > & operator= (const T *Resource)
 Assignment operator from a raw resource.
 operator const T * () const
 Cast operator to implicitely convert the resource pointer to its raw pointer type. This might be dangerous in the general case, but in this context it is safe enough to define this operator.
const T & operator* () const
 Operator * overload to return a reference to the actual resource.
const T * operator-> () const
 Operator -> overload to return a pointer to the actual resource.
void OnResourceDestroyed ()
 Function called when the observed resource is about to be destroyed.

Private Attributes

const T * myResource

Detailed Description

template<typename T>
class sf::ResourcePtr< T >

Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted when the resource is destroyed /////////////////////////////////////////////////////////.

Definition at line 116 of file Resource.hpp.


Constructor & Destructor Documentation

template<typename T>
ResourcePtr::ResourcePtr ( )

Default constructor.

Default constructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 30 of file ResourcePtr.inl.

                            :
myResource(NULL)
{

}
template<typename T>
ResourcePtr::ResourcePtr ( const T *  Resource)

Construct from a raw resource.

Construct from a raw resource /////////////////////////////////////////////////////////.

Parameters:
Resource: Internal resource

/////////////////////////////////////////////////////////

Definition at line 41 of file ResourcePtr.inl.

                                             :
myResource(Resource)
{
    if (myResource)
        myResource->Connect(*this);
}
template<typename T>
ResourcePtr::ResourcePtr ( const ResourcePtr< T > &  Copy)

Copy constructor.

Copy constructor /////////////////////////////////////////////////////////.

Parameters:
Copy: Instance to copy

/////////////////////////////////////////////////////////

Definition at line 53 of file ResourcePtr.inl.

                                                      :
myResource(Copy.myResource)
{
    if (myResource)
        myResource->Connect(*this);
}
template<typename T>
ResourcePtr::~ResourcePtr ( )

Destructor.

Destructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 65 of file ResourcePtr.inl.

{
    if (myResource)
        myResource->Disconnect(*this);
}

Member Function Documentation

template<typename T>
void ResourcePtr::OnResourceDestroyed ( )

Function called when the observed resource is about to be destroyed.

Function called when the observed resource is about to be destroyed /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 146 of file ResourcePtr.inl.

{
    myResource = NULL;
}
template<typename T>
ResourcePtr::operator const T * ( ) const

Cast operator to implicitely convert the resource pointer to its raw pointer type. This might be dangerous in the general case, but in this context it is safe enough to define this operator.

Cast operator to implicitely convert the resource pointer to its raw pointer type. This might be dangerous in the general case, but in this context it is safe enough to define this operator /////////////////////////////////////////////////////////.

Returns:
Pointer to the actual resource

/////////////////////////////////////////////////////////

Definition at line 115 of file ResourcePtr.inl.

{
    return myResource;
}
template<typename T>
const T & ResourcePtr::operator* ( ) const

Operator * overload to return a reference to the actual resource.

Operator * overload to return a reference to the actual resource /////////////////////////////////////////////////////////.

Returns:
Reference to the internal resource

/////////////////////////////////////////////////////////

Definition at line 125 of file ResourcePtr.inl.

{
    return *myResource;
}
template<typename T>
const T * ResourcePtr::operator-> ( ) const

Operator -> overload to return a pointer to the actual resource.

Operator -> overload to return a pointer to the actual resource /////////////////////////////////////////////////////////.

Returns:
Pointer to the internal resource

/////////////////////////////////////////////////////////

Definition at line 135 of file ResourcePtr.inl.

{
    return myResource;
}
template<typename T>
ResourcePtr< T > & ResourcePtr::operator= ( const ResourcePtr< T > &  Other)

Assignment operator from another ResourcePtr.

Assignment operator from another ResourcePtr /////////////////////////////////////////////////////////.

Parameters:
Other: Resource pointer to assign
Returns:
Reference to this

/////////////////////////////////////////////////////////

Definition at line 76 of file ResourcePtr.inl.

{
    if (myResource)
        myResource->Disconnect(*this);

    myResource = Other.myResource;

    if (myResource)
        myResource->Connect(*this);

    return *this;
}
template<typename T>
ResourcePtr< T > & ResourcePtr::operator= ( const T *  Resource)

Assignment operator from a raw resource.

Assignment operator from a raw resource /////////////////////////////////////////////////////////.

Parameters:
Resource: Resource to assign
Returns:
Reference to this

/////////////////////////////////////////////////////////

Definition at line 94 of file ResourcePtr.inl.

{
    if (myResource)
        myResource->Disconnect(*this);

    myResource = Resource;

    if (myResource)
        myResource->Connect(*this);

    return *this;
}

Member Data Documentation

template<typename T>
const T* sf::ResourcePtr< T >::myResource [private]

Definition at line 207 of file Resource.hpp.


The documentation for this class was generated from the following files: