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 122 of file resourcemgr.cpp.

123{
124 return copyResourceAs(name,targetDir,name);
125}
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(), generateXML(), HtmlGenerator::init(), 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;
102 case Resource::SVG:
103 {
104 std::ofstream t = Portable::openOutputStream(pathName,append);
105 if (t.is_open())
106 {
107 QCString buf(res->size, QCString::ExplicitSize);
108 memcpy(buf.rawData(),res->data,res->size);
109 t << replaceColorMarkers(buf);
110 return TRUE;
111 }
112 }
113 }
114 }
115 else
116 {
117 err("requested resource '{}' not compiled in!\n",name);
118 }
119 return FALSE;
120}
@ ExplicitSize
Definition qcstring.h:133
const Resource * get(const QCString &name) const
Returns a pointer to the resource object with the given name.
#define err(fmt,...)
Definition message.h:127
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
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:6285

References Resource::data, err, QCString::ExplicitSize, FALSE, get(), Portable::openOutputStream(), QCString::rawData(), replaceColorMarkers(), Resource::size, Resource::SVG, TRUE, Resource::type, and Resource::Verbatim.

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 127 of file resourcemgr.cpp.

128{
129 auto it = p->resources.find(name.str());
130 if (it!=p->resources.end()) return &it->second;
131 return nullptr;
132}
const std::string & str() const
Definition qcstring.h:537

References p, and QCString::str().

Referenced by copyResourceAs(), and getAsString().

◆ getAsString()

◆ 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 '{}' to directory '{}'\n",res.name,targetDir);
72 return FALSE;
73 }
74 }
75 }
76 return TRUE;
77}

References err, FALSE, Portable::openOutputStream(), p, 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: