Ocean
apple/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_APPLE_RESOURCE_H
9 #define META_OCEAN_PLATFORM_APPLE_RESOURCE_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Lock.h"
15 #include "ocean/base/Singleton.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Platform
21 {
22 
23 namespace Apple
24 {
25 
26 /**
27  * This class implements functions allowing to operate with resource data.
28  * @ingroup platformapple
29  */
30 class Resource
31 {
32  public:
33 
34  /**
35  * Definition of a vector holding 8 bit values.
36  */
37  typedef std::vector<uint8_t> Buffer;
38 
39  public:
40 
41  /**
42  * Extracts specific resource information specified by the name and type of the resource.
43  * @param bundle The name of the bundle from which the resource will be extracted, an empty string to use the main bundle
44  * @param name The name of the resource
45  * @param type The type of the resource
46  * @param buffer The resulting resource information
47  * @return True, if succeeded
48  */
49  static bool extractResource(const std::wstring& bundle, const std::wstring& name, const std::wstring& type, Buffer& buffer);
50 
51  /**
52  * Determines the path of a specified resource file.
53  * @param name The name of the resource
54  * @param type The type of the resource
55  * @param bundle The name of the bundle from which the resource will be extracted, an empty string to use the main bundle
56  * @return The path of the resource file within the bundle
57  */
58  static std::wstring resourcePath(const std::wstring& name, const std::wstring& type, const std::wstring& bundle = std::wstring());
59 
60  /**
61  * Determines the paths of all resource files with specified type.
62  * @param type The type of the resource
63  * @param directory Optional directory in which the resource files are located
64  * @param bundle The name of the bundle from which the resource will be extracted, an empty string to use the main bundle
65  * @return The path of the resource file within the bundle
66  */
67  static std::vector<std::wstring> resourcePaths(const std::wstring& type, const std::wstring& directory = std::wstring(), const std::wstring& bundle = std::wstring());
68 };
69 
70 /**
71  * This class implements a manager for resource data.
72  * @ingroup platformapple
73  */
74 class ResourceManager : public Singleton<ResourceManager>
75 {
76  friend class Singleton<ResourceManager>;
77 
78  protected:
79 
80  /**
81  * Definition of a pair combining a resource name and a resource type.
82  */
83  typedef std::pair<std::wstring, std::wstring> ResourcePair;
84 
85  /**
86  * Definition of a map mapping resources pair to frames.
87  */
88  typedef std::map<ResourcePair, FrameRef> FrameMap;
89 
90  public:
91 
92  /**
93  * Returns a specific resource frame.
94  * @param name The name of the resource
95  * @param type The type of the resource frame, the file extension: e.g., png, bmp, etc.
96  * @param bundle The name of the bundle from which the resource will be extracted, an empty string to use the main bundle
97  * @return The resource frame, if any
98  */
99  FrameRef frame(const std::wstring& name, const std::wstring& type, const std::wstring& bundle = std::wstring());
100 
101  /**
102  * Releases the entire resources of this manager.
103  */
104  void release();
105 
106  protected:
107 
108  /**
109  * Creates a new manager object.
110  */
111  inline ResourceManager();
112 
113  protected:
114 
115  /// The lock of the manager.
117 
118  /// The frames of the manager.
120 };
121 
123 {
124  // nothing to do here
125 }
126 
127 }
128 
129 }
130 
131 }
132 
133 #endif // META_OCEAN_PLATFORM_APPLE_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 functions allowing to operate with resource data.
Definition: apple/Resource.h:31
static std::vector< std::wstring > resourcePaths(const std::wstring &type, const std::wstring &directory=std::wstring(), const std::wstring &bundle=std::wstring())
Determines the paths of all resource files with specified type.
static std::wstring resourcePath(const std::wstring &name, const std::wstring &type, const std::wstring &bundle=std::wstring())
Determines the path of a specified resource file.
std::vector< uint8_t > Buffer
Definition of a vector holding 8 bit values.
Definition: apple/Resource.h:37
static bool extractResource(const std::wstring &bundle, const std::wstring &name, const std::wstring &type, Buffer &buffer)
Extracts specific resource information specified by the name and type of the resource.
This class implements a manager for resource data.
Definition: apple/Resource.h:75
FrameRef frame(const std::wstring &name, const std::wstring &type, const std::wstring &bundle=std::wstring())
Returns a specific resource frame.
ResourceManager()
Creates a new manager object.
Definition: apple/Resource.h:122
Lock lock_
The lock of the manager.
Definition: apple/Resource.h:116
void release()
Releases the entire resources of this manager.
FrameMap frames_
The frames of the manager.
Definition: apple/Resource.h:119
std::map< ResourcePair, FrameRef > FrameMap
Definition of a map mapping resources pair to frames.
Definition: apple/Resource.h:88
std::pair< std::wstring, std::wstring > ResourcePair
Definition of a pair combining a resource name and a resource type.
Definition: apple/Resource.h:83
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