Ocean
win/Resource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WIN_RESOURCE_H
9 #define META_OCEAN_PLATFORM_WIN_RESOURCE_H
10 
11 #include "ocean/platform/win/Win.h"
13 
14 #include "ocean/base/Frame.h"
15 #include "ocean/base/Singleton.h"
16 
17 #include <vector>
18 
19 namespace Ocean
20 {
21 
22 namespace Platform
23 {
24 
25 namespace Win
26 {
27 
28 /**
29  * This class implements function allowing to operate with resource data.
30  * @ingroup platformwin
31  */
32 class OCEAN_PLATFORM_WIN_EXPORT Resource
33 {
34  public:
35 
36  /**
37  * Definition of a vector holding 8 bit values.
38  */
39  typedef std::vector<unsigned char> Buffer;
40 
41  public:
42 
43  /**
44  * Extracts the specific resource information frosm a given module specified by the id and type of the resource.
45  * @param module The handle of the module from which the resource is requested, nullptr to extract the resource from the module which created the current process
46  * @param resourceId The id of the resource
47  * @param type The type of the resource
48  * @param buffer The resulting resource information
49  * @return True, if succeeded
50  */
51  static bool extractResource(const HMODULE module, const unsigned int resourceId, const std::wstring& type, Buffer& buffer);
52 };
53 
54 /**
55  * This class implements a manager for resource data.
56  * @ingroup platformwin
57  */
58 class OCEAN_PLATFORM_WIN_EXPORT ResourceManager : public Singleton<ResourceManager>
59 {
60  friend class Singleton<ResourceManager>;
61 
62  protected:
63 
64  /**
65  * Definition of a map mapping resource ids to frames.
66  */
67  typedef std::map<unsigned int, FrameRef> FrameMap;
68 
69  public:
70 
71  /**
72  * Returns a specific resource frame.
73  * @param resourceId The id of the resource
74  * @param type The type of the frame, e.g., PNG, BMP, etc.
75  * @param module The handle of the module from which the resource is requested, nullptr to extract the resource from the module which created the current process
76  * @return The resource frame, if any
77  */
78  FrameRef frame(const unsigned int resourceId, const std::wstring& type, const HMODULE module = System::currentLibraryModule());
79 
80  /**
81  * Releases the entire resources of this manager.
82  */
83  void release();
84 
85  protected:
86 
87  /**
88  * Creates a new manager object.
89  */
90  inline ResourceManager();
91 
92  protected:
93 
94  /// The lock of the manager.
96 
97  /// The frames of the manager.
99 };
100 
102 {
103  // nothing to do here
104 }
105 
106 }
107 
108 }
109 
110 }
111 
112 #endif // META_OCEAN_PLATFORM_WIN_RESOURCE_H
This class implements a recursive lock object.
Definition: Lock.h:31
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class implements function allowing to operate with resource data.
Definition: win/Resource.h:33
std::vector< unsigned char > Buffer
Definition of a vector holding 8 bit values.
Definition: win/Resource.h:39
static bool extractResource(const HMODULE module, const unsigned int resourceId, const std::wstring &type, Buffer &buffer)
Extracts the specific resource information frosm a given module specified by the id and type of the r...
This class implements a manager for resource data.
Definition: win/Resource.h:59
std::map< unsigned int, FrameRef > FrameMap
Definition of a map mapping resource ids to frames.
Definition: win/Resource.h:67
FrameRef frame(const unsigned int resourceId, const std::wstring &type, const HMODULE module=System::currentLibraryModule())
Returns a specific resource frame.
void release()
Releases the entire resources of this manager.
ResourceManager()
Creates a new manager object.
Definition: win/Resource.h:101
FrameMap frameMap_
The frames of the manager.
Definition: win/Resource.h:98
Lock lock_
The lock of the manager.
Definition: win/Resource.h:95
static HMODULE currentLibraryModule()
Returns the handle to the calling module (a runtime library).
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15