SmartEngine  1.6.0
Resource.h
1 // Copyright (C) Entropy Software LLC - All Rights Reserved
2 
3 #pragma once
4 
5 #include "MemoryBuffer.h"
6 #include "Object.h"
7 
8 namespace SmartEngine
9 {
10 
11 #pragma pack(push, 4)
12 struct ResourceCInfo
16 {
21  const char* resourceName = nullptr;
22 };
23 
24 enum class SerializationResult : byte
25 {
26  Success,
27  UnspecifiedError,
28  EndOfStream,
29  NotSupported,
30  Corrupted,
31  VersionTooLow,
32  InvalidResourceName,
33  InvalidObject,
34  InvalidBuffer,
35  InvalidInput,
36  InputCountMismatch,
37  InputDimensionMismatch,
38  TensorCountMismatch,
39  TensorSizeMismatch,
40  TensorDataSizeMismatch,
41  NodeCountMismatch,
42  NodeNotFound,
43  FileNotFound,
44  SignatureNotValid,
45  LicenseExpired,
47 };
48 #pragma pack(pop)
49 
53 class SMARTENGINE_EXPORT ISerializable : public virtual IObject
54 {
55 public:
56  SMARTENGINE_DECLARE_CLASS(ISerializable)
57 
58 
59  virtual SerializationResult Serialize(IMemoryBuffer* buffer) = 0;
62 
67 };
68 
76 class SMARTENGINE_EXPORT IResource : public virtual IObject, public ISerializable
77 {
78 public:
79  SMARTENGINE_DECLARE_CLASS(IResource)
80 
81 
82  virtual const char* GetResourceName() const = 0;
85 
91 
99  virtual SerializationResult Load(const char* appendName = nullptr) = 0;
100 
108  virtual SerializationResult Save(const char* appendName = nullptr) = 0;
109 };
110 
112 extern "C"
113 {
114  SMARTENGINE_EXPORT SerializationResult Serializable_Serialize(ObjPtr object, ObjPtr buffer);
115  SMARTENGINE_EXPORT SerializationResult Serializable_Deserialize(ObjPtr object, ObjPtr buffer);
116 
117  SMARTENGINE_EXPORT const char* Resource_GetResourceName(ObjPtr object);
118  SMARTENGINE_EXPORT SerializationResult Resource_GetLastLoadResult(ObjPtr object);
119  SMARTENGINE_EXPORT SerializationResult Resource_Load(ObjPtr object, const char* resourceName);
120  SMARTENGINE_EXPORT SerializationResult Resource_Save(ObjPtr object, const char* resourceName);
121 }
122 
124 
125 } // namespace SmartEngine
SmartEngine::ISerializable
Base class for objects that can be loaded from and saved to an in memory buffer.
Definition: Resource.h:54
SmartEngine::IResource::GetLastLoadResult
virtual SerializationResult GetLastLoadResult() const =0
Returns the result of the last call to Load(). Useful for checking loaded data state after creation.
SmartEngine::IResource::Load
virtual SerializationResult Load(const char *appendName=nullptr)=0
Load this object from disk.
SmartEngine
Definition: A2CTrainer.h:10
SmartEngine::IObject
Base class for SmartEngine AI objects. It is not common to deal with this class directly.
Definition: Object.h:19
SmartEngine::ResourceCInfo::resourceName
const char * resourceName
Optional resource name that will be used with Load() and Save() if no other name is provided.
Definition: Resource.h:21
SmartEngine::ISerializable::Deserialize
virtual SerializationResult Deserialize(IMemoryBuffer *buffer)=0
Fill this object with contents from a buffer.
SmartEngine::SerializationResult
SerializationResult
Definition: Resource.h:25
SmartEngine::IResource
Base class for objects that can be loaded from and saved to disk.
Definition: Resource.h:77
SmartEngine::IResource::Save
virtual SerializationResult Save(const char *appendName=nullptr)=0
Save this object to disk.
SmartEngine::SerializationResult::Success
@ Success
SmartEngine::IMemoryBuffer
Simple in memory buffer. Used for serialization, but can be used as a generic buffer too.
Definition: MemoryBuffer.h:15