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 copyCategory (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.

42 {
43  p = new Private;
44 }
Definition: types.h:26
Private * p
Definition: resourcemgr.h:59
ResourceMgr::~ResourceMgr ( )
private

Definition at line 46 of file resourcemgr.cpp.

47 {
48  delete p;
49 }
Private * p
Definition: resourcemgr.h:59

Member Function Documentation

bool ResourceMgr::copyCategory ( const char *  categoryName,
const char *  targetDir 
) const

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

Definition at line 59 of file resourcemgr.cpp.

60 {
61  QDictIterator<Resource> it(p->resources);
62  const Resource *res;
63  for (it.toFirst();(res=it.current());++it)
64  {
65  if (qstrcmp(res->category,categoryName)==0)
66  {
67  if (!copyResource(res->name,targetDir))
68  {
69  return FALSE;
70  }
71  }
72  }
73  return TRUE;
74 }
const bool FALSE
Definition: qglobal.h:370
bool copyResource(const char *name, const char *targetDir) const
Compiled resource.
Definition: resourcemgr.h:21
QDict< Resource > resources
Definition: resourcemgr.cpp:32
const char * name
Definition: resourcemgr.h:25
Private * p
Definition: resourcemgr.h:59
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
const bool TRUE
Definition: qglobal.h:371
const char * category
Definition: resourcemgr.h:24
bool ResourceMgr::copyResource ( const char *  name,
const char *  targetDir 
) const

Copies a registered resource to a given target directory

Definition at line 159 of file resourcemgr.cpp.

160 {
161  return copyResourceAs(name,targetDir,name);
162 }
static QCString name
Definition: declinfo.cpp:673
bool copyResourceAs(const char *name, const char *targetDir, const char *targetName) const
Definition: resourcemgr.cpp:76
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 76 of file resourcemgr.cpp.

77 {
78  QCString pathName = QCString(targetDir)+"/"+targetName;
79  const Resource *res = get(name);
80  if (res)
81  {
82  switch (res->type)
83  {
84  case Resource::Verbatim:
85  {
86  QFile f(pathName);
87  if (f.open(IO_WriteOnly) && f.writeBlock((const char *)res->data,res->size)==res->size)
88  {
89  return TRUE;
90  }
91  }
92  break;
94  {
95  QCString n = name;
96  n = n.left(n.length()-4)+".png"; // replace .lum by .png
97  uchar *p = (uchar*)res->data;
98  int width = (p[0]<<8)+p[1];
99  int height = (p[2]<<8)+p[3];
100  ColoredImgDataItem images[2];
101  images[0].name = n;
102  images[0].width = width;
103  images[0].height = height;
104  images[0].content = &p[4];
105  images[0].alpha = 0;
106  images[1].name = 0; // terminator
107  writeColoredImgData(targetDir,images);
108  return TRUE;
109  }
110  break;
111  case Resource::LumAlpha:
112  {
113  QCString n = name;
114  n = n.left(n.length()-5)+".png"; // replace .luma by .png
115  uchar *p = (uchar*)res->data;
116  int width = (p[0]<<8)+p[1];
117  int height = (p[2]<<8)+p[3];
118  ColoredImgDataItem images[2];
119  images[0].name = n;
120  images[0].width = width;
121  images[0].height = height;
122  images[0].content = &p[4];
123  images[0].alpha = &p[4+width*height];
124  images[1].name = 0; // terminator
125  writeColoredImgData(targetDir,images);
126  return TRUE;
127  }
128  break;
129  case Resource::CSS:
130  {
131  QFile f(pathName);
132  if (f.open(IO_WriteOnly))
133  {
134  QCString buf(res->size+1);
135  memcpy(buf.rawData(),res->data,res->size);
136  FTextStream t(&f);
137  buf = replaceColorMarkers(buf);
138  if (qstrcmp(name,"navtree.css")==0)
139  {
140  t << substitute(buf,"$width",QCString().setNum(Config_getInt("TREEVIEW_WIDTH"))+"px");
141  }
142  else
143  {
144  t << substitute(buf,"$doxygenversion",versionString);
145  }
146  return TRUE;
147  }
148  }
149  break;
150  }
151  }
152  else
153  {
154  err("requested resource '%s' not compiled in!\n",name);
155  }
156  return FALSE;
157 }
static QCString name
Definition: declinfo.cpp:673
unsigned short width
Definition: util.h:437
uint length() const
Definition: qcstring.h:195
unsigned char * alpha
Definition: util.h:440
#define IO_WriteOnly
Definition: qiodevice.h:62
unsigned char * content
Definition: util.h:439
const bool FALSE
Definition: qglobal.h:370
QCString left(uint len) const
Definition: qcstring.cpp:213
void writeColoredImgData(const char *dir, ColoredImgDataItem data[])
Definition: util.cpp:7889
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
unsigned char uchar
Definition: nybbler.cc:11
Compiled resource.
Definition: resourcemgr.h:21
#define Config_getInt(val)
Definition: config.cpp:661
const char * name
Definition: util.h:436
const unsigned char * data
Definition: resourcemgr.h:26
std::void_t< T > n
char versionString[]
Definition: version.cpp:1
unsigned short height
Definition: util.h:438
int size
Definition: resourcemgr.h:27
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
Private * p
Definition: resourcemgr.h:59
Type type
Definition: resourcemgr.h:28
QCString replaceColorMarkers(const char *str)
Definition: util.cpp:7919
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
const bool TRUE
Definition: qglobal.h:371
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: util.cpp:5088
const Resource * ResourceMgr::get ( const char *  name) const
private

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

Definition at line 164 of file resourcemgr.cpp.

165 {
166  return p->resources.find(name);
167 }
static QCString name
Definition: declinfo.cpp:673
QDict< Resource > resources
Definition: resourcemgr.cpp:32
Private * p
Definition: resourcemgr.h:59
QCString ResourceMgr::getAsString ( const char *  name) const

Gets the resource data as a C string

Definition at line 169 of file resourcemgr.cpp.

170 {
171  const Resource *res = get(name);
172  if (res)
173  {
174  QCString result(res->size+1);
175  memcpy(result.rawData(),res->data,res->size);
176  return result;
177  }
178  else
179  {
180  return QCString();
181  }
182 }
static QCString name
Definition: declinfo.cpp:673
char * rawData() const
Definition: qcstring.h:216
static QCString result
Compiled resource.
Definition: resourcemgr.h:21
const unsigned char * data
Definition: resourcemgr.h:26
int size
Definition: resourcemgr.h:27
ResourceMgr & ResourceMgr::instance ( )
static

Returns the one and only instance of this class

Definition at line 35 of file resourcemgr.cpp.

36 {
37  static ResourceMgr theInstance;
38  return theInstance;
39 }
Singleton for managing resources compiled into an executable.
Definition: resourcemgr.h:32
void ResourceMgr::registerResources ( const Resource  resources[],
int  numResources 
)

Registers an array of resources

Definition at line 51 of file resourcemgr.cpp.

52 {
53  for (int i=0;i<numResources;i++)
54  {
55  p->resources.insert(resources[i].name,&resources[i]);
56  }
57 }
static QCString name
Definition: declinfo.cpp:673
QDict< Resource > resources
Definition: resourcemgr.cpp:32
Private * p
Definition: resourcemgr.h:59

Member Data Documentation

Private* ResourceMgr::p
private

Definition at line 59 of file resourcemgr.h.


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