You.i Engine
YiAsset.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_ASSET_H_
3 #define _YI_ASSET_H_
4 
5 #include "utility/YiRtti.h"
6 #include "utility/YiString.h"
7 
8 #include <memory>
9 
10 class CYIAssetLoadParams;
11 class IYIGPUObject;
12 
32 class CYIAsset : public std::enable_shared_from_this<CYIAsset>
33 {
34  friend class CYIAssetManager;
35  friend class CYIAssetLoader;
36  friend class CYIDecodeTask;
37 
38 public:
42  enum class PathType
43  {
44  Absolute = 0,
45  Relative
46  };
47 
48  virtual ~CYIAsset();
49 
55  const CYIString &GetPath() const;
56 
62 
70  virtual std::pair<size_t, size_t> GetApproximateSize() const;
71 
81  bool SetName(const CYIString &name);
82 
88  const CYIString &GetName() const;
89 
94  bool Load();
95 
100  void Unload();
101 
105  bool IsLoaded() const;
106 
112  bool Equals(const std::shared_ptr<CYIAsset> &pAsset);
113 
120  virtual bool Prepare();
121 
122 protected:
124 
125  CYIAsset();
126 
131  ssize_t GetID() const;
132 
140  void SetPath(const CYIString &path, PathType pathType);
141  void SetApproximateSize(size_t size);
142  void SetLoaded(bool assetLoaded);
143  void SetLoadParameters(std::unique_ptr<CYIAssetLoadParams> pParams);
144 
145  virtual void OnLoad();
146  virtual void OnUnload();
147 
148 private:
153  void SetID(ssize_t id);
154 
155  bool m_isLoaded;
156  ssize_t m_id;
157  size_t m_resourceSize;
158  CYIString m_Name;
159  CYIString m_Path;
160  std::unique_ptr<CYIAssetLoadParams> m_pLoadParams;
161 
164 };
165 
168 #endif // _YI_ASSET_H_
bool IsLoaded() const
virtual void OnUnload()
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:122
virtual std::pair< size_t, size_t > GetApproximateSize() const
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
bool SetName(const CYIString &name)
PathType
Definition: YiAsset.h:42
void SetPath(const CYIString &path, PathType pathType)
friend class CYIDecodeTask
Definition: YiAsset.h:36
CYIAssetLoadParams * GetLoadParameters() const
Base class for decoders which can accept specialized parameter objects.
Definition: YiAssetLoadParams.h:16
ssize_t GetID() const
const CYIString & GetName() const
void SetLoaded(bool assetLoaded)
An interface for managing GPU-bound objects such as shaders and textures.
Definition: YiGPUObject.h:18
bool Equals(const std::shared_ptr< CYIAsset > &pAsset)
virtual ~CYIAsset()
const CYIString & GetPath() const
bool Load()
void SetLoadParameters(std::unique_ptr< CYIAssetLoadParams > pParams)
This class provides a cache that users can use to store various types of assets.
Definition: YiAssetManager.h:46
void SetApproximateSize(size_t size)
int ssize_t
Definition: YiPredefWin32.h:131
static ssize_t INVALID_ID
Definition: YiAsset.h:123
Base class for any asset. An asset provides functions for dynamically loading and unloading itself an...
Definition: YiAsset.h:32
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:257
virtual bool Prepare()
This file contains the classes and macros used to implement RTTI in You.i Engine. ...
virtual void OnLoad()
void Unload()
The asset loader provides an interface for loading asset objects, which in turn wrap resource objects...
Definition: YiAssetLoader.h:40