1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Reflection/BsRTTIType.h" |
7 | #include "Resources/BsResource.h" |
8 | #include "Resources/BsResourceMetaData.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @cond RTTI */ |
13 | /** @addtogroup RTTI-Impl-Core |
14 | * @{ |
15 | */ |
16 | |
17 | class BS_CORE_EXPORT ResourceRTTI : public RTTIType<Resource, IReflectable, ResourceRTTI> |
18 | { |
19 | private: |
20 | UINT32& getSize(Resource* obj) { return obj->mSize; } |
21 | void setSize(Resource* obj, UINT32& size) { obj->mSize = size; } |
22 | |
23 | SPtr<ResourceMetaData> getMetaData(Resource* obj) { return obj->mMetaData; } |
24 | void setMetaData(Resource* obj, SPtr<ResourceMetaData> value) { obj->mMetaData = value; } |
25 | |
26 | public: |
27 | ResourceRTTI() |
28 | { |
29 | addPlainField("mSize" , 0, &ResourceRTTI::getSize, &ResourceRTTI::setSize); |
30 | addReflectablePtrField("mMetaData" , 1, &ResourceRTTI::getMetaData, &ResourceRTTI::setMetaData); |
31 | } |
32 | |
33 | void onDeserializationStarted(IReflectable* obj, SerializationContext* context) override |
34 | { |
35 | Resource* resource = static_cast<Resource*>(obj); |
36 | |
37 | if(context) |
38 | resource->mKeepSourceData = (context->flags & SF_KeepResourceSourceData) != 0; |
39 | else |
40 | resource->mKeepSourceData = false; |
41 | } |
42 | |
43 | const String& getRTTIName() override |
44 | { |
45 | static String name = "Resource" ; |
46 | return name; |
47 | } |
48 | |
49 | UINT32 getRTTIId() override |
50 | { |
51 | return 100; |
52 | } |
53 | |
54 | SPtr<IReflectable> newRTTIObject() override |
55 | { |
56 | BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class." ); |
57 | return nullptr; |
58 | } |
59 | }; |
60 | |
61 | /** @} */ |
62 | /** @endcond */ |
63 | } |