---
name: "CL_ResourceManager"
section: "3"
platform: "linux"
package: "clanlib0-common-dev"
version: "0.4.4-8"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/CL_ResourceManager"
---

# CL\_ResourceManager(3)

The ClanLib resource manager.

## NAME

CL\_ResourceManager - The ClanLib resource manager.

## 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 = CL_Res_Surface::load("my_surface", res_manager);
  ```

Getting the same resource twice won't create a new instance of the resource, but you will still have to clean up the resource after yourself. In other words: If you load a resource twice, you only have to delete it once.

## CLASS MEMBERS

- static CL\_ResourceManager \***create**(

  ```
   const char *config_file,
  CL_InputSourceProvider *provider = NULL,
  bool read_directly_from_source=false,
  bool delete_inputsource_provider=false)
  ```

- static CL\_ResourceManager \***create**(

  ```
   const char *file_name,
  const bool is_datafile )
  ```

- virtual **~CL\_ResourceManager**()

  - virtual void **load\_all\_resources**()

  - virtual void **unload\_all\_resources**()

  - virtual void **load\_section**(

  ```
  const char *section_name)
  ```

- virtual void **unload\_section**(

  ```
  const char *section_name)
  ```

- virtual CL\_Resource \***get\_resource**(

  ```
  std::string res_id)
  ```

- virtual std::list\<std::string\> \***get\_all\_resources**()

  - virtual std::list\<std::string\> \***get\_resources\_of\_type**(

  ```
  std::string type_id)
  ```

- virtual CL\_InputSourceProvider \***get\_resource\_provider**()

  ## MEMBERS WITH DESCRIPTIONS

- static CL\_ResourceManager \***create**(

  ```
   const char *config_file,
  CL_InputSourceProvider *provider = NULL,
  bool read_directly_from_source=false,
  bool delete_inputsource_provider=false)
  ```

  ```
  Parameters:
  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.
  ```

  ```
  Description:
  ```

  Resource Manager constructor.

- static CL\_ResourceManager \***create**(

  ```
   const char *file_name,
  const bool is_datafile )
  ```

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

  ```
  Description:
  ```

  Resource Manager constructor.

- virtual **~CL\_ResourceManager**()

  ```
  Description:
  ```

- virtual void **load\_all\_resources**()

  ```
  Description:
  ```

  Loads all resources into memory.

- virtual void **unload\_all\_resources**()

  ```
  Description:
  ```

  Unloads all resources from memory.

- virtual void **load\_section**(

  ```
  const char *section_name)
  ```

  ```
  Parameters:
  section_name - the section to be loaded
  ```

  ```
  Description:
  ```

  Loads all resources in a given section into memory.

- virtual void **unload\_section**(

  ```
  const char *section_name)
  ```

  ```
  Parameters:
  section_name - the section to be unloaded
  ```

  ```
  Description:
  ```

  Unloads all resources in a given section into memory.

- virtual CL\_Resource \***get\_resource**(

  ```
  std::string res_id)
  ```

  ```
  Parameters:
  Name of the resource in the configuration file - note: the name of resources are absolute, eg. including section names with slashes (Graphics/Pacman/sur_pacman)
  ```

  ```
  Description:
  ```

  Returns a pointer to the CL\_Resource representing the given resource

- virtual std::list\<std::string\> \***get\_all\_resources**()

  ```
  Description:
  ```

  Returns a list of all resources available. Primarily used by the ClanCompiler to build datafiles from resources.

  ```
  Return value:
  ```

  The list of resources available. You'll have to delete all strings in the returned list manually (including the list-instance itself).

- virtual std::list\<std::string\> \***get\_resources\_of\_type**(

  ```
  std::string type_id)
  ```

  ```
  Description:
  ```

  Returns a list of all resources available matching a given type. Primarily used by the ClanCompiler to build datafiles from resources.

  ```
  Return value:
  ```

  The list of resources available. You'll have to delete all strings in the  list manually (including the list-instance itself).

- virtual CL\_InputSourceProvider \***get\_resource\_provider**()

  ```
  Description:
  ```

  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)

  ```
  Return value:
  ```

  Pointer to inputsourceprovider containing resource data.

## SEE ALSO

All ClanLib API classes can be found in **clanlib (3)**.

## AUTHORS

Originally written by Magnus Norddahl \<*mbn@dark.x.dtu.dk*\> and Martin Starch \<*starch@dark.x.dtu.dk*\>. ClanLib is now developed by the ClanLib Development team as an Open Source project.

The ClanLib man pages was created using the Perceps documentation system (another excellent piece of Open Source software, available at **http://somewhere.in.the.world.org**).

See **clanlib (3)** to find out how to get a full list of contributors and details on how to submit bug reports, comments etc.
