My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ResourceMgr Class Reference

Singleton for managing resources compiled into an executable. More...

#include <resourcemgr.h>

Classes

class  Private
 

Public Member Functions

void registerResources (const Resource resources[], int numResources)
 
bool writeCategory (const char *categoryName, const char *targetDir) const
 
bool copyResource (const char *name, const char *targetDir) const
 
bool copyResourceAs (const char *name, const char *targetDir, const char *targetName) const
 
QCString getAsString (const char *name) const
 

Static Public Member Functions

static ResourceMgrinstance ()
 

Private Member Functions

const Resourceget (const char *name) const
 
 ResourceMgr ()
 
 ~ResourceMgr ()
 

Private Attributes

Privatep
 

Detailed Description

Singleton for managing resources compiled into an executable.

Definition at line 32 of file resourcemgr.h.

Constructor & Destructor Documentation

ResourceMgr::ResourceMgr ( )
private

Definition at line 41 of file resourcemgr.cpp.

References p, and Private.

{
p = new Private;
}
ResourceMgr::~ResourceMgr ( )
private

Definition at line 46 of file resourcemgr.cpp.

References p.

{
delete p;
}

Member Function Documentation

bool ResourceMgr::copyResource ( const char *  name,
const char *  targetDir 
) const
bool ResourceMgr::copyResourceAs ( const char *  name,
const char *  targetDir,
const char *  targetName 
) const

Copies a registered resource to a given target directory under a given target name

Definition at line 79 of file resourcemgr.cpp.

References ColoredImgDataItem::alpha, Config_getInt, ColoredImgDataItem::content, Resource::CSS, Resource::data, err(), ColoredImgDataItem::height, Resource::LumAlpha, Resource::Luminance, ColoredImgDataItem::name, p, replaceColorMarkers(), Resource::size, substitute(), Resource::type, Resource::Verbatim, versionString, ColoredImgDataItem::width, and writeColoredImgData().

Referenced by copyResource(), and TemplateNodeResource::render().

{
QCString pathName = QCString(targetDir)+"/"+targetName;
const Resource *res = get(name);
if (res)
{
switch (res->type)
{
{
QFile f(pathName);
if (f.open(IO_WriteOnly) && f.writeBlock((const char *)res->data,res->size)==res->size)
{
return TRUE;
}
}
break;
{
QCString n = name;
n = n.left(n.length()-4)+".png"; // replace .lum by .png
uchar *p = (uchar*)res->data;
int width = (p[0]<<8)+p[1];
int height = (p[2]<<8)+p[3];
ColoredImgDataItem images[2];
images[0].name = n;
images[0].width = width;
images[0].height = height;
images[0].content = &p[4];
images[0].alpha = 0;
images[1].name = 0; // terminator
writeColoredImgData(targetDir,images);
return TRUE;
}
break;
{
QCString n = name;
n = n.left(n.length()-5)+".png"; // replace .luma by .png
uchar *p = (uchar*)res->data;
int width = (p[0]<<8)+p[1];
int height = (p[2]<<8)+p[3];
ColoredImgDataItem images[2];
images[0].name = n;
images[0].width = width;
images[0].height = height;
images[0].content = &p[4];
images[0].alpha = &p[4+width*height];
images[1].name = 0; // terminator
writeColoredImgData(targetDir,images);
return TRUE;
}
break;
{
QFile f(pathName);
if (f.open(IO_WriteOnly))
{
QCString buf(res->size+1);
memcpy(buf.rawData(),res->data,res->size);
FTextStream t(&f);
buf = replaceColorMarkers(buf);
if (qstrcmp(name,"navtree.css")==0)
{
t << substitute(buf,"$width",QCString().setNum(Config_getInt(TREEVIEW_WIDTH))+"px");
}
else
{
t << substitute(buf,"$doxygenversion",versionString);
}
return TRUE;
}
}
break;
}
}
else
{
err("requested resource '%s' not compiled in!\n",name);
}
return FALSE;
}
const Resource * ResourceMgr::get ( const char *  name) const
private

Returns a pointer to the resource object with the given name.

Definition at line 167 of file resourcemgr.cpp.

References p, and ResourceMgr::Private::resources.

{
return p->resources.find(name);
}
QCString ResourceMgr::getAsString ( const char *  name) const

Gets the resource data as a C string

Definition at line 172 of file resourcemgr.cpp.

References Resource::data, and Resource::size.

Referenced by generateXML(), HtmlGenerator::init(), TemplateEngine::Private::loadByName(), writeDefaultStyleSheet(), HtmlGenerator::writeExternalSearchPage(), HtmlGenerator::writeFooterFile(), HtmlGenerator::writeHeaderFile(), HtmlGenerator::writeSearchData(), and HtmlGenerator::writeSearchPage().

{
const Resource *res = get(name);
if (res)
{
QCString result(res->size+1);
memcpy(result.rawData(),res->data,res->size);
return result;
}
else
{
return QCString();
}
}
ResourceMgr & ResourceMgr::instance ( )
static
void ResourceMgr::registerResources ( const Resource  resources[],
int  numResources 
)

Registers an array of resources

Definition at line 51 of file resourcemgr.cpp.

References p, and ResourceMgr::Private::resources.

{
for (int i=0;i<numResources;i++)
{
p->resources.insert(resources[i].name,&resources[i]);
}
}
bool ResourceMgr::writeCategory ( const char *  categoryName,
const char *  targetDir 
) const

Writes all resource belonging to a given category to a given target directory

Definition at line 59 of file resourcemgr.cpp.

References Resource::category, Resource::data, err(), Resource::name, p, ResourceMgr::Private::resources, and Resource::size.

Referenced by generateTemplateFiles().

{
QDictIterator<Resource> it(p->resources);
const Resource *res;
for (it.toFirst();(res=it.current());++it)
{
if (qstrcmp(res->category,categoryName)==0)
{
QCString pathName = QCString(targetDir)+"/"+res->name;
QFile f(pathName);
if (!f.open(IO_WriteOnly) || f.writeBlock((const char *)res->data,res->size)!=res->size)
{
err("Failed to write resource '%s' to directory '%s'\n",res->name,targetDir);
return FALSE;
}
}
}
return TRUE;
}

Member Data Documentation

Private* ResourceMgr::p
private

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