Doxygen
resourcemgr.h
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 #ifndef RESOURCEMGR_H
16 #define RESOURCEMGR_H
17 
18 #include <memory>
19 #include <initializer_list>
20 
21 #include "qcstring.h"
22 
23 /** @brief Compiled resource */
24 struct Resource
25 {
26  enum Type { Verbatim, Luminance, LumAlpha, CSS, SVG };
27  const char *category;
28  const char *name;
29  const unsigned char *data;
30  int size;
31  Type type;
32 };
33 
34 /** @brief Singleton for managing resources compiled into an executable */
36 {
37  public:
38  /** Returns the one and only instance of this class */
39  static ResourceMgr &instance();
40 
41  /** Registers an array of resources */
42  void registerResources(std::initializer_list<Resource> resources);
43 
44  /** Writes all resource belonging to a given category to a given target directory */
45  bool writeCategory(const QCString &categoryName,const QCString &targetDir) const;
46 
47  /** Copies a registered resource to a given target directory */
48  bool copyResource(const QCString &name,const QCString &targetDir) const;
49 
50  /** Copies a registered resource to a given target directory under a given target name */
51  bool copyResourceAs(const QCString &name,const QCString &targetDir,const QCString &targetName, bool append=false) const;
52 
53  /** Gets the resource data as a C string */
54  QCString getAsString(const QCString &name) const;
55 
56  private:
57  /** Returns a pointer to the resource object with the given name. */
58  const Resource *get(const QCString &name) const;
59 
60  ResourceMgr();
61  ~ResourceMgr();
62  class Private;
63  std::unique_ptr<Private> p;
64 };
65 
66 #endif
ResourceMgr::copyResource
bool copyResource(const QCString &name, const QCString &targetDir) const
Copies a registered resource to a given target directory
Definition: resourcemgr.cpp:180
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
ResourceMgr::instance
static ResourceMgr & instance()
Returns the one and only instance of this class
Definition: resourcemgr.cpp:32
Resource::name
const char * name
Definition: resourcemgr.h:41
ResourceMgr::writeCategory
bool writeCategory(const QCString &categoryName, const QCString &targetDir) const
Writes all resource belonging to a given category to a given target directory
Definition: resourcemgr.cpp:54
ResourceMgr::getAsString
QCString getAsString(const QCString &name) const
Gets the resource data as a C string
Definition: resourcemgr.cpp:192
Resource::Verbatim
@ Verbatim
Definition: resourcemgr.h:52
Resource::Luminance
@ Luminance
Definition: resourcemgr.h:52
Resource::category
const char * category
Definition: resourcemgr.h:40
qcstring.h
Resource::Type
Type
Definition: resourcemgr.h:39
Resource::CSS
@ CSS
Definition: resourcemgr.h:52
ResourceMgr::registerResources
void registerResources(std::initializer_list< Resource > resources)
Registers an array of resources
Definition: resourcemgr.cpp:46
ResourceMgr::get
const Resource * get(const QCString &name) const
Returns a pointer to the resource object with the given name.
Definition: resourcemgr.cpp:185
Resource::type
Type type
Definition: resourcemgr.h:44
ResourceMgr::ResourceMgr
ResourceMgr()
Definition: resourcemgr.cpp:38
Resource
Compiled resource
Definition: resourcemgr.h:24
ResourceMgr::p
std::unique_ptr< Private > p
Definition: resourcemgr.h:62
ResourceMgr::Private
Definition: resourcemgr.cpp:26
Resource::size
int size
Definition: resourcemgr.h:43
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
ResourceMgr::~ResourceMgr
~ResourceMgr()
Definition: resourcemgr.cpp:42
Resource::data
const unsigned char * data
Definition: resourcemgr.h:42
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108