Doxygen
ResourceMgr类 参考

Singleton for managing resources compiled into an executable 更多...

#include <resourcemgr.h>

class  Private
 

Public 成员函数

void registerResources (std::initializer_list< Resource > resources)
 Registers an array of resources 更多...
 
bool writeCategory (const QCString &categoryName, const QCString &targetDir) const
 Writes all resource belonging to a given category to a given target directory 更多...
 
bool copyResource (const QCString &name, const QCString &targetDir) const
 Copies a registered resource to a given target directory 更多...
 
bool copyResourceAs (const QCString &name, const QCString &targetDir, const QCString &targetName, bool append=false) const
 Copies a registered resource to a given target directory under a given target name 更多...
 
QCString getAsString (const QCString &name) const
 Gets the resource data as a C string 更多...
 

静态 Public 成员函数

static ResourceMgrinstance ()
 Returns the one and only instance of this class 更多...
 

Private 成员函数

const Resourceget (const QCString &name) const
 Returns a pointer to the resource object with the given name. 更多...
 
 ResourceMgr ()
 
 ~ResourceMgr ()
 

Private 属性

std::unique_ptr< Privatep
 

详细描述

Singleton for managing resources compiled into an executable

在文件 resourcemgr.h35 行定义.

构造及析构函数说明

◆ ResourceMgr()

ResourceMgr::ResourceMgr ( )
private

在文件 resourcemgr.cpp38 行定义.

38  : p(std::make_unique<Private>())
39 {
40 }

◆ ~ResourceMgr()

ResourceMgr::~ResourceMgr ( )
private

在文件 resourcemgr.cpp42 行定义.

43 {
44 }

成员函数说明

◆ copyResource()

bool ResourceMgr::copyResource ( const QCString name,
const QCString targetDir 
) const

◆ copyResourceAs()

bool ResourceMgr::copyResourceAs ( const QCString name,
const QCString targetDir,
const QCString targetName,
bool  append = false 
) const

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

在文件 resourcemgr.cpp79 行定义.

80 {
81  std::string pathName = targetDir.str()+"/"+targetName.str();
82  std::ios_base::openmode mode = std::ofstream::out | std::ofstream::binary;
83  if (append) mode |= std::ofstream::app;
84  const Resource *res = get(name);
85  if (res)
86  {
87  switch (res->type)
88  {
89  case Resource::Verbatim:
90  {
91  std::ofstream f(pathName,mode);
92  bool ok=false;
93  if (f.is_open())
94  {
95  f.write(reinterpret_cast<const char *>(res->data),res->size);
96  ok = !f.fail();
97  }
98  if (ok)
99  {
100  return TRUE;
101  }
102  }
103  break;
104  case Resource::Luminance:
105  {
106  QCString n = name;
107  n = n.left(n.length()-4)+".png"; // replace .lum by .png
108  uchar *data = (uchar*)res->data;
109  ushort width = (data[0]<<8)+data[1];
110  ushort height = (data[2]<<8)+data[3];
111  ColoredImgDataItem images[2];
112  images[0].name = n.data();
113  images[0].width = width;
114  images[0].height = height;
115  images[0].content = &data[4];
116  images[0].alpha = 0;
117  images[1].name = 0; // terminator
118  writeColoredImgData(targetDir,images);
119  return TRUE;
120  }
121  break;
122  case Resource::LumAlpha:
123  {
124  QCString n = name;
125  n = n.left(n.length()-5)+".png"; // replace .luma by .png
126  uchar *data = (uchar*)res->data;
127  ushort width = (data[0]<<8)+data[1];
128  ushort height = (data[2]<<8)+data[3];
129  ColoredImgDataItem images[2];
130  images[0].name = n.data();
131  images[0].width = width;
132  images[0].height = height;
133  images[0].content = &data[4];
134  images[0].alpha = &data[4+width*height];
135  images[1].name = 0; // terminator
136  writeColoredImgData(targetDir,images);
137  return TRUE;
138  }
139  break;
140  case Resource::CSS:
141  {
142  std::ofstream t(pathName,mode);
143  if (t.is_open())
144  {
145  QCString buf(res->size+1);
146  memcpy(buf.rawData(),res->data,res->size);
147  buf = replaceColorMarkers(buf);
148  if (name=="navtree.css")
149  {
150  t << substitute(buf,"$width",QCString().setNum(Config_getInt(TREEVIEW_WIDTH))+"px");
151  }
152  else
153  {
154  t << substitute(buf,"$doxygenversion",getDoxygenVersion());
155  }
156  return TRUE;
157  }
158  }
159  break;
160  case Resource::SVG:
161  {
162  std::ofstream t(pathName,mode);
163  if (t.is_open())
164  {
165  QCString buf(res->size+1);
166  memcpy(buf.rawData(),res->data,res->size);
167  t << replaceColorMarkers(buf);
168  return TRUE;
169  }
170  }
171  }
172  }
173  else
174  {
175  err("requested resource '%s' not compiled in!\n",qPrint(name));
176  }
177  return FALSE;
178 }

引用了 ColoredImgDataItem::alpha, Config_getInt, ColoredImgDataItem::content, Resource::CSS, Resource::data, QCString::data(), err(), FALSE, get(), ColoredImgDataItem::height, QCString::left(), QCString::length(), Resource::LumAlpha, Resource::Luminance, ColoredImgDataItem::name, qPrint(), QCString::rawData(), replaceColorMarkers(), Resource::size, QCString::str(), substitute(), Resource::SVG, TRUE, Resource::type, Resource::Verbatim, ColoredImgDataItem::width , 以及 writeColoredImgData().

被这些函数引用 copyResource(), HtmlGenerator::init() , 以及 TemplateNodeResource::render().

◆ get()

const Resource * ResourceMgr::get ( const QCString name) const
private

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

在文件 resourcemgr.cpp185 行定义.

186 {
187  auto it = p->resources.find(name.str());
188  if (it!=p->resources.end()) return &it->second;
189  return 0;
190 }

引用了 p , 以及 QCString::str().

被这些函数引用 copyResourceAs() , 以及 getAsString().

◆ getAsString()

QCString ResourceMgr::getAsString ( const QCString name) const

◆ instance()

◆ registerResources()

void ResourceMgr::registerResources ( std::initializer_list< Resource resources)

Registers an array of resources

在文件 resourcemgr.cpp46 行定义.

47 {
48  for (auto &res : resources)
49  {
50  p->resources.insert({res.name,res});
51  }
52 }

引用了 p.

◆ writeCategory()

bool ResourceMgr::writeCategory ( const QCString categoryName,
const QCString targetDir 
) const

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

在文件 resourcemgr.cpp54 行定义.

55 {
56  for (auto &kv : p->resources)
57  {
58  Resource &res = kv.second;
59  if (res.category==categoryName)
60  {
61  std::string pathName = targetDir.str()+"/"+res.name;
62  std::ofstream f(pathName,std::ofstream::out | std::ofstream::binary);
63  bool ok=false;
64  if (f.is_open())
65  {
66  f.write(reinterpret_cast<const char *>(res.data),res.size);
67  ok = !f.fail();
68  }
69  if (!ok)
70  {
71  err("Failed to write resource '%s' to directory '%s'\n",res.name,qPrint(targetDir));
72  return FALSE;
73  }
74  }
75  }
76  return TRUE;
77 }

引用了 Resource::category, Resource::data, err(), FALSE, Resource::name, p, qPrint(), Resource::size, QCString::str() , 以及 TRUE.

被这些函数引用 generateTemplateFiles().

类成员变量说明

◆ p

std::unique_ptr<Private> ResourceMgr::p
private

在文件 resourcemgr.h62 行定义.

被这些函数引用 get(), registerResources() , 以及 writeCategory().


该类的文档由以下文件生成:
writeColoredImgData
void writeColoredImgData(const QCString &dir, ColoredImgDataItem data[])
Writes the intensity only bitmap represented by data as an image to directory dir using the colors de...
Definition: util.cpp:6363
ResourceMgr::copyResourceAs
bool copyResourceAs(const QCString &name, const QCString &targetDir, const QCString &targetName, bool append=false) const
Copies a registered resource to a given target directory under a given target name
Definition: resourcemgr.cpp:79
Resource::name
const char * name
Definition: resourcemgr.h:41
ColoredImgDataItem
Data associated with a HSV colored image.
Definition: util.h:376
replaceColorMarkers
QCString replaceColorMarkers(const QCString &str)
Replaces any markers of the form ##AA in input string str by new markers of the form #AABBCC,...
Definition: util.cpp:6387
QCString::length
uint length() const
Returns the length of the string, not counting the 0-terminator.
Definition: qcstring.h:147
Resource::Verbatim
@ Verbatim
Definition: resourcemgr.h:52
QCString::str
std::string str() const
Definition: qcstring.h:442
Resource::Luminance
@ Luminance
Definition: resourcemgr.h:52
err
void err(const char *fmt,...)
Definition: message.cpp:203
Resource::category
const char * category
Definition: resourcemgr.h:40
ColoredImgDataItem::width
unsigned short width
Definition: util.h:379
Resource::CSS
@ CSS
Definition: resourcemgr.h:52
ColoredImgDataItem::alpha
unsigned char * alpha
Definition: util.h:382
ColoredImgDataItem::name
const char * name
Definition: util.h:378
ResourceMgr::get
const Resource * get(const QCString &name) const
Returns a pointer to the resource object with the given name.
Definition: resourcemgr.cpp:185
Config_getInt
#define Config_getInt(name)
Definition: config.h:34
uchar
unsigned char uchar
Definition: qcstring.h:38
QCString::left
QCString left(size_t len) const
Definition: qcstring.h:212
Resource::type
Type type
Definition: resourcemgr.h:44
ColoredImgDataItem::height
unsigned short height
Definition: util.h:380
Resource
Compiled resource
Definition: resourcemgr.h:24
TRUE
#define TRUE
Definition: qcstring.h:36
ResourceMgr::p
std::unique_ptr< Private > p
Definition: resourcemgr.h:62
ushort
unsigned short ushort
Definition: qcstring.h:39
Resource::size
int size
Definition: resourcemgr.h:43
ColoredImgDataItem::content
unsigned char * content
Definition: util.h:381
substitute
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: qcstring.cpp:465
Resource::LumAlpha
@ LumAlpha
Definition: resourcemgr.h:52
Resource::SVG
@ SVG
Definition: resourcemgr.h:52
ResourceMgr
Singleton for managing resources compiled into an executable
Definition: resourcemgr.h:35
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
Resource::data
const unsigned char * data
Definition: resourcemgr.h:42
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108