Entire Class Index | Main Class Index | Cross Index | Global Index

# Class CL_ResourceManager

The ClanLib resource manager.
Contained in: global
Derived from: none
Derived by: none
Group: Core (Resources)

#include <ClanLib/core.h>

### public function member index:
### Construction:
`` | `CL_ResourceManager` | `(`const` `std::string`& `config_file`, `CL_InputSourceProvider`* `provider` = NULL, `bool` `read_directly_from_source`=false, `bool` `delete_inputsource_provider`=false)`;
`` | `CL_ResourceManager` | `(`const` `std::string`& `config_file`, `const` `bool` `is_datafile`)`;
`` | `CL_ResourceManager` | `(`const` `std::string`& `config_file`, `const` `bool` `is_datafile`, `CL_ResourceManager`& `additional_resources`)`;
`` | `CL_ResourceManager` | `(`const` `CL_ResourceManager`& `copy`)`;
`` | `CL_ResourceManager` | `()`;
`` | `~CL_ResourceManager` | `()`;
### Attributes:
``CL_Resource`&` | `get_resource` | `(`const` `std::string`& `res_id`)`;
``std::list`<`std::string`>*` | `get_all_resources` | `()`;
``std::list`<`std::string`>*` | `get_resources_of_type` | `(`const` `std::string`& `type_id`)`;
``CL_InputSourceProvider`*` | `get_resource_provider` | `() `const``;
``bool`` | `is_from_source` | `()`;
### Operations:
``void`` | `operator``=` | `(`const` `CL_ResourceManager`& `copy`)`;
``void`` | `add_resources` | `(`const` `CL_ResourceManager`& `additional_resources`)`;
``void`` | `remove_resources` | `(`const` `CL_ResourceManager`& `additional_resources`)`;
``void`` | `load_all` | `()`;
``void`` | `unload_all` | `()`;
``void`` | `load_section` | `(`const` `std::string`& `section_name`)`;
``void`` | `unload_section` | `(`const` `std::string`& `section_name`)`;
### Implementation:
`` | `CL_ResourceManager` | `(`class` `CL_ResourceManager_File`* `impl`)`;

## Description:

The resource manager is used to retrieve resources from a given resource source.
This can either be a resource script file (used as input to the datafile compiler), or a datafile with all the resources included into one large gzipped resource file.
To speedup loading of resources in a game, you can load entire sections of resources at once. When a resource in the section is requested, it is returned instantly without having to access the disk. This is especially useful to make sure all the game resources are loaded before the game is started.
Resources are normally not retrieved using the get_resource() function. Instead, you should load the resource using the appropiate resource type class. For instance, a surface is easiest loaded like this:
CL_ResourceManager res_manager("my_datafile.dat", true);
CL_Surface my_surface("my_surface", res_manager);
Getting the same resource twice won't create a new instance of the resource; they are reference counted.

## Function Member Descriptions:

CL_ResourceManager::CL_ResourceManager - Resource Manager constructor.
`` `CL_ResourceManager``(`const` `std::string`& `config_file`, `CL_InputSourceProvider`* `provider` = NULL, `bool` `read_directly_from_source`=false, `bool` `delete_inputsource_provider`=false)`;

> config_file - the name of the file in which the resources are defined
> provider - the optional inputprovider in which, the resource file is stored
> read_directly_from_source - if true, any resources are loaded directly from their source, meaning that any datafile-directive is ignored.

CL_ResourceManager::CL_ResourceManager - Resource Manager constructor.
`` `CL_ResourceManager``(`const` `std::string`& `config_file`, `const` `bool` `is_datafile`)`;

> file_name - the name of the file to open
> is_datafile - indicates if the file is a scriptfile or a datafile

CL_ResourceManager::CL_ResourceManager - Resource Manager constructor.
`` `CL_ResourceManager``(`const` `std::string`& `config_file`, `const` `bool` `is_datafile`, `CL_ResourceManager`& `additional_resources`)`;

> file_name - the name of the file to open
> is_datafile - indicates if the file is a scriptfile or a datafile
> additional_resources - additional resources to be included into the resource set.

CL_ResourceManager::CL_ResourceManager - Resource Manager Constructor
`` `CL_ResourceManager``(`const` `CL_ResourceManager`& `copy`)`;

CL_ResourceManager::CL_ResourceManager - Construct empty resource manager.
`` `CL_ResourceManager``()`;

CL_ResourceManager::CL_ResourceManager - Resource Manager Constructor
`` `CL_ResourceManager``(`class` `CL_ResourceManager_File`* `impl`)`;

CL_ResourceManager::add_resources - Add resources from an other resource manager.
``void`` `add_resources``(`const` `CL_ResourceManager`& `additional_resources`)`;

CL_ResourceManager::get_all_resources - Returns a list of all resources available.
Primarily used by the datafile compiler to build datafiles from resources.
``std::list`<`std::string`>*` `get_all_resources``()`;

> Returns - The list of resources available. You'll have to delete the list returned.

CL_ResourceManager::get_resource - Returns a pointer to the CL_Resource representing the given resource
``CL_Resource`&` `get_resource``(`const` `std::string`& `res_id`)`;

CL_ResourceManager::get_resource_provider - Returns a pointer to the inputsourceprovider, in which all resources are stored
(this can be a fileprovider or a datafileprovider depending on method used to load the script file)
``CL_InputSourceProvider`*` `get_resource_provider``() `const``;

> Returns - Pointer to inputsourceprovider containing resource data.

CL_ResourceManager::get_resources_of_type - Returns a list of all resources available matching a given type.
Primarily used by the ClanCompiler to build datafiles from resources.
``std::list`<`std::string`>*` `get_resources_of_type``(`const` `std::string`& `type_id`)`;

> Returns - The list of resources available. You'll have to delete the list returned.

CL_ResourceManager::is_from_source - Returns true if the resources are loaded from source. False if loaded from a datafile.
``bool`` `is_from_source``()`;

CL_ResourceManager::load_all - Loads all resources into memory.
``void`` `load_all``()`;

CL_ResourceManager::load_section - Loads all resources in a given section into memory.
``void`` `load_section``(`const` `std::string`& `section_name`)`;

CL_ResourceManager::operator = - Copy a resource manager.
``void`` `operator``=` `(`const` `CL_ResourceManager`& `copy`)`;

CL_ResourceManager::remove_resources - Remove resources from an other resource manager.
``void`` `remove_resources``(`const` `CL_ResourceManager`& `additional_resources`)`;

CL_ResourceManager::unload_all - Unloads all resources from memory.
``void`` `unload_all``()`;

CL_ResourceManager::unload_section - Unloads all resources in a given section into memory.
``void`` `unload_section``(`const` `std::string`& `section_name`)`;

CL_ResourceManager::~CL_ResourceManager - Resource Manager Destructor
`` `~CL_ResourceManager``()`;

## Variable Member Descriptions:

CL_ResourceManager::impl - Pointer to the implementation
``CL_ResourceManager_File` *` ``impl`;`