Ceylan::LoadableWithContent< Content > Class Template Reference

Loadable template, useful to have a way of retrieving the loaded content directly according to its specific type. More...

#include <CeylanLoadable.h>

Inheritance diagram for Ceylan::LoadableWithContent< Content >:
Inheritance graph
[legend]
Collaboration diagram for Ceylan::LoadableWithContent< Content >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LoadableWithContent (const std::string &contentFilePath)
 Creates a new loadable instance, whose content file is designated by the specified filename, but does not load anything.
virtual ~LoadableWithContent () throw ()
 Virtual destructor.
virtual bool load ()=0
 Loads the content of this instance from file.
virtual bool unload ()=0
 Unloads the content of this instance.
virtual bool reload (bool forceLoad=false)
 Reloads the content of this instance.
virtual bool hasContent () const
 Returns true iff the content is already loaded.
virtual Content & getExistingContent ()
 Returns the already loaded content.
virtual const Content & getExistingContentAsConst () const
 Returns a constant reference to the already loaded content.
virtual Content & getContent ()
 Returns the loaded content, either directly (if already available), otherwise after having loaded it.
virtual const Content & getContentAsConst ()
 Returns a constant reference to the loaded content, either directly (if already available), otherwise after having loaded it.
virtual const std::string & getContentPath () const
 Returns the path to the associated content file.

Protected Attributes

Content * _content
 The loaded content, if any.
std::string _contentPath
 The path to the file used for content loading.

Private Member Functions

 LoadableWithContent (const LoadableWithContent &source)
 Copy constructor made private to ensure that it will never be called.
LoadableWithContentoperator= (const LoadableWithContent &source)
 Assignment operator made private to ensure that it will never be called.

Detailed Description

template<typename Content>
class Ceylan::LoadableWithContent< Content >

Loadable template, useful to have a way of retrieving the loaded content directly according to its specific type.

Note:
No CEYLAN_DLL declaration for templates.

A class inheriting from this instanciated template just has to implement the load and unload method accordingly.

See also:
testCeylanLoadable.cc for an example of such implementation.

Definition at line 199 of file CeylanLoadable.h.


Constructor & Destructor Documentation

template<typename Content >
Ceylan::LoadableWithContent< Content >::LoadableWithContent ( const std::string &  contentFilePath  )  [inline, explicit]

Creates a new loadable instance, whose content file is designated by the specified filename, but does not load anything.

Exceptions:
LoadableException if the creation failed.

Definition at line 392 of file CeylanLoadable.h.

template<typename Content >
Ceylan::LoadableWithContent< Content >::~LoadableWithContent (  )  throw () [inline, virtual]

Virtual destructor.

Note:
Does not delete the content as this operation is usually content-specific.

Definition at line 412 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::_content, and Ceylan::Log::LogPlug::error().

template<typename Content >
Ceylan::LoadableWithContent< Content >::LoadableWithContent ( const LoadableWithContent< Content > &  source  )  [private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

template<typename Content >
Content & Ceylan::LoadableWithContent< Content >::getContent (  )  [inline, virtual]

Returns the loaded content, either directly (if already available), otherwise after having loaded it.

Exceptions:
LoadableException if the operation failed.
Note:
Ownership of the content is kept by this instance.

Definition at line 506 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::_content, Ceylan::LoadableWithContent< Content >::hasContent(), and Ceylan::LoadableWithContent< Content >::load().

template<typename Content >
const Content & Ceylan::LoadableWithContent< Content >::getContentAsConst (  )  [inline, virtual]

Returns a constant reference to the loaded content, either directly (if already available), otherwise after having loaded it.

Exceptions:
LoadableException if the operation failed.
Note:
Ownership of the content is kept by this instance.
The method cannot be const as it may have to load the content.
See also:
getExistingContentAsConst

Definition at line 519 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::_content, Ceylan::LoadableWithContent< Content >::hasContent(), and Ceylan::LoadableWithContent< Content >::load().

const std::string & Loadable::getContentPath (  )  const [virtual, inherited]

Returns the path to the associated content file.

Definition at line 70 of file CeylanLoadable.cc.

References Ceylan::Loadable::_contentPath.

template<typename Content >
Content & Ceylan::LoadableWithContent< Content >::getExistingContent (  )  [inline, virtual]

Returns the already loaded content.

Exceptions:
LoadableException if the operation failed, including if there is no available content to be returned (it will not be loaded if lacking).
Note:
Ownership of the content is kept by this instance.

Definition at line 475 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::_content, and Ceylan::LoadableWithContent< Content >::hasContent().

template<typename Content >
const Content & Ceylan::LoadableWithContent< Content >::getExistingContentAsConst (  )  const [inline, virtual]

Returns a constant reference to the already loaded content.

Exceptions:
LoadableException if the operation failed, including if there is no available content to be returned (it will not be loaded if lacking).
Note:
Ownership of the content is kept by this instance.

Definition at line 490 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::_content, and Ceylan::LoadableWithContent< Content >::hasContent().

template<typename Content >
bool Ceylan::LoadableWithContent< Content >::hasContent (  )  const [inline, virtual]
template<typename Content >
virtual bool Ceylan::LoadableWithContent< Content >::load (  )  [pure virtual]

Loads the content of this instance from file.

Returns:
true iff the content had to be actually loaded (otherwise it was already loaded and nothing was done).
Exceptions:
LoadableException whenever the loading fails.
Note:
This method is still pure virtual here, as loading the file in memory would not be enough: a Content object is still to be created, and we cannot expect that each Content type is a class, and has a constructor taking exactly, for example, a Ceylan::Byte pointer.

Implements Ceylan::Loadable.

Referenced by Ceylan::LoadableWithContent< Content >::getContent(), Ceylan::LoadableWithContent< Content >::getContentAsConst(), and Ceylan::LoadableWithContent< Content >::reload().

template<typename Content >
LoadableWithContent& Ceylan::LoadableWithContent< Content >::operator= ( const LoadableWithContent< Content > &  source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

template<typename Content >
bool Ceylan::LoadableWithContent< Content >::reload ( bool  forceLoad = false  )  [inline, virtual]

Reloads the content of this instance.

Parameters:
forceLoad if true, then any previously loaded content will be deleted before an unconditional loading is performed. If false, then if there were no content already loaded, no loading will be performed (content availability will be kept as was), but if the content was loaded, it will be unloaded and reloaded.
Returns:
true iff a reload had to take place.
Exceptions:
LoadableException whenever the reloading fails.

Definition at line 436 of file CeylanLoadable.h.

References Ceylan::LoadableWithContent< Content >::hasContent(), Ceylan::LoadableWithContent< Content >::load(), generalUtils::true, and Ceylan::LoadableWithContent< Content >::unload().

template<typename Content >
virtual bool Ceylan::LoadableWithContent< Content >::unload (  )  [pure virtual]

Unloads the content of this instance.

Returns:
true iff the content had to be actually unloaded (otherwise it was not already available and nothing was done).
Exceptions:
LoadableException whenever the unloading fails.
Note:
This method is still pure virtual here, as unloading the content can be specific to the content.

Implements Ceylan::Loadable.

Referenced by Ceylan::LoadableWithContent< Content >::reload().


Member Data Documentation

template<typename Content >
Content* Ceylan::LoadableWithContent< Content >::_content [protected]
std::string Ceylan::Loadable::_contentPath [protected, inherited]

The path to the file used for content loading.

Definition at line 154 of file CeylanLoadable.h.

Referenced by Ceylan::Loadable::getContentPath().


The documentation for this class was generated from the following file:
Generated on Mon Nov 29 13:40:42 2010 for Ceylan by  doxygen 1.6.3