Doxygen
Loading...
Searching...
No Matches
ResourceMgr Class Reference

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

#include <src/resourcemgr.h>

Classes

class  Private
 

Public Member Functions

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.
 

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

std::unique_ptr< Privatep
 

Detailed Description

Singleton for managing resources compiled into an executable.

Definition at line 36 of file resourcemgr.h.

Constructor & Destructor Documentation

◆ ResourceMgr()

ResourceMgr::ResourceMgr ( )
private

Definition at line 39 of file resourcemgr.cpp.

39 : p(std::make_unique<Private>())
40{
41}
std::unique_ptr< Private > p
Definition resourcemgr.h:66

References p.

Referenced by instance().

◆ ~ResourceMgr()

ResourceMgr::~ResourceMgr ( )
private

Definition at line 43 of file resourcemgr.cpp.

44{
45}

Member Function Documentation

◆ copyResource()

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

Copies a registered resource to a given target directory.

Definition at line 178 of file resourcemgr.cpp.

179{
180 return copyResourceAs(name,targetDir,name);
181}
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.

References copyResourceAs().

Referenced by CitationManager::generatePage(), FTVHelp::generateTreeViewImages(), generateXML(), HtmlGenerator::init(), HtmlGenerator::writeSearchData(), HtmlGenerator::writeSearchPage(), and HtmlGenerator::writeTabData().

◆ 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.

Definition at line 79 of file resourcemgr.cpp.

80{
81 QCString pathName = targetDir+"/"+targetName;
82 const Resource *res = get(name);
83 if (res)
84 {
85 switch (res->type)
86 {
88 {
89 std::ofstream f = Portable::openOutputStream(pathName,append);
90 bool ok=false;
91 if (f.is_open())
92 {
93 f.write(reinterpret_cast<const char *>(res->data),res->size);
94 ok = !f.fail();
95 }
96 if (ok)
97 {
98 return TRUE;
99 }
100 }
101 break;
103 {
104 QCString n = name;
105 n = n.left(n.length()-4)+".png"; // replace .lum by .png
106 const uint8_t *data = res->data;
107 uint16_t width = (data[0]<<8)+data[1];
108 uint16_t height = (data[2]<<8)+data[3];
109 ColoredImgDataItem images[2];
110 images[0].name = n.data();
111 images[0].width = width;
112 images[0].height = height;
113 images[0].content = &data[4];
114 images[0].alpha = nullptr;
115 images[1].name = nullptr; // terminator
116 writeColoredImgData(targetDir,images);
117 return TRUE;
118 }
119 break;
121 {
122 QCString n = name;
123 n = n.left(n.length()-5)+".png"; // replace .luma by .png
124 const uint8_t *data = res->data;
125 uint16_t width = (data[0]<<8)+data[1];
126 uint16_t height = (data[2]<<8)+data[3];
127 ColoredImgDataItem images[2];
128 images[0].name = n.data();
129 images[0].width = width;
130 images[0].height = height;
131 images[0].content = &data[4];
132 images[0].alpha = &data[4+width*height];
133 images[1].name = nullptr; // terminator
134 writeColoredImgData(targetDir,images);
135 return TRUE;
136 }
137 break;
138 case Resource::CSS:
139 {
140 std::ofstream t = Portable::openOutputStream(pathName,append);
141 if (t.is_open())
142 {
143 QCString buf(res->size, QCString::ExplicitSize);
144 memcpy(buf.rawData(),res->data,res->size);
145 buf = replaceColorMarkers(buf);
146 if (name=="navtree.css")
147 {
148 t << substitute(buf,"$width",QCString().setNum(Config_getInt(TREEVIEW_WIDTH))+"px");
149 }
150 else
151 {
152 t << substitute(buf,"$doxygenversion",getDoxygenVersion());
153 }
154 return TRUE;
155 }
156 }
157 break;
158 case Resource::SVG:
159 {
160 std::ofstream t = Portable::openOutputStream(pathName,append);
161 if (t.is_open())
162 {
163 QCString buf(res->size, QCString::ExplicitSize);
164 memcpy(buf.rawData(),res->data,res->size);
165 t << replaceColorMarkers(buf);
166 return TRUE;
167 }
168 }
169 }
170 }
171 else
172 {
173 err("requested resource '%s' not compiled in!\n",qPrint(name));
174 }
175 return FALSE;
176}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
@ ExplicitSize
Definition qcstring.h:133
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:159
QCString left(size_t len) const
Definition qcstring.h:214
const Resource * get(const QCString &name) const
Returns a pointer to the resource object with the given name.
#define Config_getInt(name)
Definition config.h:34
#define err(fmt,...)
Definition message.h:84
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
const char * qPrint(const char *s)
Definition qcstring.h:672
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
const unsigned char * content
Definition util.h:412
unsigned short height
Definition util.h:411
const unsigned char * alpha
Definition util.h:413
unsigned short width
Definition util.h:410
const char * name
Definition util.h:409
const unsigned char * data
Definition resourcemgr.h:30
Type type
Definition resourcemgr.h:32
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:6119
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:6095

References ColoredImgDataItem::alpha, Config_getInt, ColoredImgDataItem::content, Resource::CSS, QCString::data(), Resource::data, err, QCString::ExplicitSize, FALSE, get(), ColoredImgDataItem::height, QCString::left(), QCString::length(), Resource::LumAlpha, Resource::Luminance, ColoredImgDataItem::name, Portable::openOutputStream(), qPrint(), QCString::rawData(), replaceColorMarkers(), Resource::size, substitute(), Resource::SVG, TRUE, Resource::type, Resource::Verbatim, ColoredImgDataItem::width, and writeColoredImgData().

Referenced by copyResource().

◆ get()

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

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

Definition at line 183 of file resourcemgr.cpp.

184{
185 auto it = p->resources.find(name.str());
186 if (it!=p->resources.end()) return &it->second;
187 return nullptr;
188}
const std::string & str() const
Definition qcstring.h:537

References p, and QCString::str().

Referenced by copyResourceAs(), and getAsString().

◆ getAsString()

QCString ResourceMgr::getAsString ( const QCString & name) const

◆ instance()

◆ registerResources()

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

Registers an array of resources.

Definition at line 47 of file resourcemgr.cpp.

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

References 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.

Definition at line 55 of file resourcemgr.cpp.

56{
57 for (auto &[name,res] : p->resources)
58 {
59 if (res.category==categoryName)
60 {
61 QCString pathName = targetDir+"/"+res.name;
62 std::ofstream f = Portable::openOutputStream(pathName);
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}

References err, FALSE, Portable::openOutputStream(), p, qPrint(), and TRUE.

Member Data Documentation

◆ p

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

Definition at line 66 of file resourcemgr.h.

Referenced by get(), registerResources(), ResourceMgr(), and writeCategory().


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