dtDAL::ResourceHelper Class Reference

This class is a registry of file types with handlers to allow file type specifice resource handling. More...

#include <resourcehelper.h>

List of all members.

Public Member Functions

 ResourceHelper ()
 ~ResourceHelper ()
const std::string GetResourcePath (const ResourceDescriptor &descriptor) const
 Converts a resource descriptor into relative file path to the main file of the given resource.
const ResourceTypeHandlerGetHandlerForFile (const DataType &resourceType, const std::string &filePath) const
 
Parameters:
resourceType the type of resource.

void GetHandlersForDataType (const DataType &resourceType, std::vector< const ResourceTypeHandler * > &toFill) const
 
Parameters:
resourceType the type of resource.

void RegisterResourceTypeHander (ResourceTypeHandler &handler)
 Registers a new type handler.
void IndexResources (dtUtil::tree< ResourceTreeNode > &tree) const
 Indexes the resources for a project.
const std::string CreateResourceCategory (const std::string &category, const DataType &type, dtUtil::tree< ResourceTreeNode > *dataTypeTree, dtUtil::tree< ResourceTreeNode > *&categoryInTree) const
 Creates a resource category.
bool RemoveResourceCategory (const std::string &category, const DataType &type, bool recursive, dtUtil::tree< ResourceTreeNode > *dataTypeTree) const
 Removes a category.
void RemoveResource (const ResourceDescriptor &resource, dtUtil::tree< ResourceTreeNode > *resourceTree) const
 Removes a resource and updates the tree.
const ResourceDescriptor AddResource (const std::string &newName, const std::string &pathToFile, const std::string &category, const DataType &type, dtUtil::tree< ResourceTreeNode > *dataTypeTree) const
 Adds a new resource to the current project and updates the tree.
void RemoveResourceFromTree (dtUtil::tree< ResourceTreeNode > &resourceTree, const ResourceDescriptor &resource) const
 Removes a resource from the tree.


Detailed Description

This class is a registry of file types with handlers to allow file type specifice resource handling.

Constructor & Destructor Documentation

dtDAL::ResourceHelper::ResourceHelper (  ) 

dtDAL::ResourceHelper::~ResourceHelper (  ) 


Member Function Documentation

const std::string dtDAL::ResourceHelper::GetResourcePath ( const ResourceDescriptor descriptor  )  const

Converts a resource descriptor into relative file path to the main file of the given resource.

It does not validate if the path is valid, nor does it have the context to do so.

Parameters:
descriptor the resource descriptor to convert.
Returns:
the relative file path for the descriptor.

const ResourceTypeHandler * dtDAL::ResourceHelper::GetHandlerForFile ( const DataType resourceType,
const std::string &  filePath 
) const

Parameters:
resourceType the type of resource.

The datatype passed in MUST be a resource type.

Parameters:
filePath the handler for this file name will be returned. This should specify a full path.
Returns:
The resource type that will handle the give file and resource type or NULL if there is no match.
Exceptions:
ExceptionEnum::ProjectResourceError if the datatype is a primitive type, not a resource type.

void dtDAL::ResourceHelper::GetHandlersForDataType ( const DataType resourceType,
std::vector< const ResourceTypeHandler * > &  toFill 
) const

Parameters:
resourceType the type of resource.

The datatype passed in MUST be a resource type.

Parameters:
toFill the vector to fill with the handlers.
Returns:
The resource types that are available for the given handler.
Exceptions:
ExceptionEnum::ProjectResourceError if the datatype is a primitive type, not a resource type.

void dtDAL::ResourceHelper::RegisterResourceTypeHander ( ResourceTypeHandler handler  ) 

Registers a new type handler.

The method will get the datatype and applicable filters from the handler itself.

Parameters:
handler The resource type handler to register.
Exceptions:
ExceptionEnum::ProjectResourceError if the datatype of the handler is a primitive type, not a resource type.

void dtDAL::ResourceHelper::IndexResources ( dtUtil::tree< ResourceTreeNode > &  tree  )  const

Indexes the resources for a project.

It will use the handlers to index all of the different types of resources. The current directory should be the top of the project when this is called.

Note:
The current directory must be the top of the project.
Parameters:
tree the tree of resources to fill.

const std::string dtDAL::ResourceHelper::CreateResourceCategory ( const std::string &  category,
const DataType type,
dtUtil::tree< ResourceTreeNode > *  dataTypeTree,
dtUtil::tree< ResourceTreeNode > *&  categoryInTree 
) const

Creates a resource category.

The current directory should be the project context when this is called.

Note:
The current directory must be the top of the project.
Parameters:
category The category of the resource.
type the datatype of the category
dataTypeTree a pointer to the resource tree for the datatype, or null to ignore resource indexing.
categoryInTree a output parameter that will be the resource tree for the newly created category. This value is undefined if the dataTypeTree parameter is NULL.
Returns:
the file path to the category relative to the project context.

bool dtDAL::ResourceHelper::RemoveResourceCategory ( const std::string &  category,
const DataType type,
bool  recursive,
dtUtil::tree< ResourceTreeNode > *  dataTypeTree 
) const

Removes a category.

This method expects the current directory to be the root of the project context.

Note:
The current directory must be the top of the project.
Parameters:
category The category to remove.
type The datatype the category is in.
recursive true to recursively delete the category and all subcategories and resources.
dataTypeTree a pointer to the resource tree for the datatype, or null to ignore resource indexing.
Returns:
true if the category was removed, or didn't exist. false if the category could not be removed because recursive was false and the category was not empty.
Exceptions:
ExceptionEnum::ProjectIOException if the could not complete because of some sort of IO exception.
ExceptionEnum::ProjectResourceError if the resource could not be removed for reasons other than file io.
ExceptionEnum::ProjectFileNotFound on rare occasion, this could possibly be thrown if the file contents are changed while the recusive delete is occuring.

void dtDAL::ResourceHelper::RemoveResource ( const ResourceDescriptor resource,
dtUtil::tree< ResourceTreeNode > *  resourceTree 
) const

Removes a resource and updates the tree.

Note:
The current directory must be the top of the project.
Parameters:
resource the resource descriptor of the resource to remove.
resourceTree the tree to update or NULL to ignore.

const ResourceDescriptor dtDAL::ResourceHelper::AddResource ( const std::string &  newName,
const std::string &  pathToFile,
const std::string &  category,
const DataType type,
dtUtil::tree< ResourceTreeNode > *  dataTypeTree 
) const

Adds a new resource to the current project and updates the tree.

Note:
The current directory must be the top of the project.
Parameters:
newName the new name of the resource. This must NOT have an extension on it.
pathToFile the path to the file or directory to import.
category the category for the new resource.
type the datatype of the resource.
dataTypeTree pointer to the tree for the dataType to update, or NULL to ignore
Returns:
the resource descriptor for the newly added resource.

void dtDAL::ResourceHelper::RemoveResourceFromTree ( dtUtil::tree< ResourceTreeNode > &  resourceTree,
const ResourceDescriptor resource 
) const

Removes a resource from the tree.

This is called by removeResource.

Parameters:
resourceTree the tree of resources.
resource the resource descriptor for the resource to remove.


http://www.delta3d.org
2.0.0 generated 14 Feb 2008