Skip to main content

The ResourceMgr Class Reference

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

Declaration

class ResourceMgr { ... }

Included Headers

#include <src/resourcemgr.h>

Private Constructors Index

ResourceMgr ()

Private Destructor Index

~ResourceMgr ()

Public Member Functions Index

voidregisterResources (std::initializer_list< Resource > resources)

Registers an array of resources. More...

boolwriteCategory (const QCString &categoryName, const QCString &targetDir) const

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

boolcopyResource (const QCString &name, const QCString &targetDir) const

Copies a registered resource to a given target directory. More...

boolcopyResourceAs (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. More...

QCStringgetAsString (const QCString &name) const

Gets the resource data as a C string. More...

Private Member Functions Index

const Resource *get (const QCString &name) const

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

Private Member Attributes Index

std::unique_ptr< Private >p

Public Static Functions Index

static ResourceMgr &instance ()

Returns the one and only instance of this class. More...

Description

Singleton for managing resources compiled into an executable.

Definition at line 36 of file resourcemgr.h.

Private Constructors

ResourceMgr()

ResourceMgr::ResourceMgr ()

Declaration at line 61 of file resourcemgr.h, definition at line 39 of file resourcemgr.cpp.

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

Reference p.

Referenced by instance.

Private Destructor

~ResourceMgr()

ResourceMgr::~ResourceMgr ()

Declaration at line 62 of file resourcemgr.h, definition at line 43 of file resourcemgr.cpp.

Public Member Functions

copyResource()

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

Copies a registered resource to a given target directory.

Declaration at line 49 of file resourcemgr.h, definition at line 122 of file resourcemgr.cpp.

122bool ResourceMgr::copyResource(const QCString &name,const QCString &targetDir) const
123{
124 return copyResourceAs(name,targetDir,name);
125}

Reference 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)

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

Declaration at line 52 of file resourcemgr.h, definition at line 79 of file resourcemgr.cpp.

79bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,const QCString &targetName,bool append) const
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 {
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}

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.

getAsString()

registerResources()

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

Registers an array of resources.

Declaration at line 43 of file resourcemgr.h, definition at line 47 of file resourcemgr.cpp.

47void ResourceMgr::registerResources(std::initializer_list<Resource> resources)
48{
49 for (auto &res : resources)
50 {
51 p->resources.emplace(res.name,res);
52 }
53}

Reference p.

writeCategory()

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

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

Declaration at line 46 of file resourcemgr.h, definition at line 55 of file resourcemgr.cpp.

55bool ResourceMgr::writeCategory(const QCString &categoryName,const QCString &targetDir) const
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.

Private Member Functions

get()

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

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

Declaration at line 59 of file resourcemgr.h, definition at line 127 of file resourcemgr.cpp.

127const Resource *ResourceMgr::get(const QCString &name) const
128{
129 auto it = p->resources.find(name.str());
130 if (it!=p->resources.end()) return &it->second;
131 return nullptr;
132}

References p and QCString::str.

Referenced by copyResourceAs and getAsString.

Private Member Attributes

p

std::unique_ptr<Private> ResourceMgr::p

Definition at line 66 of file resourcemgr.h.

66 std::unique_ptr<Private> p;

Referenced by get, registerResources, ResourceMgr and writeCategory.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.