• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef META_SRC_RESOURCE_OBJECT_RESOURCE_H
17 #define META_SRC_RESOURCE_OBJECT_RESOURCE_H
18 
19 #include <core/resources/intf_resource_manager.h>
20 
21 #include <meta/ext/implementation_macros.h>
22 #include <meta/ext/object.h>
23 #include <meta/ext/resource/resource.h>
24 #include <meta/interface/resource/intf_object_resource.h>
25 #include <meta/interface/serialization/intf_serializable.h>
26 
META_BEGIN_NAMESPACE()27 META_BEGIN_NAMESPACE()
28 
29 class ObjectResource : public IntroduceInterfaces<MetaObject, Resource, IObjectResource> {
30     META_OBJECT(ObjectResource, ClassId::ObjectResource, IntroduceInterfaces)
31 public:
32     BASE_NS::Uid GetResourceType() const override;
33     void SetResourceType(const ObjectId& id) override;
34 
35     ReturnError Export(IExportContext& c) const override;
36     ReturnError Import(IImportContext& c) override;
37 
38 private:
39     ObjectId type_ = ClassId::ObjectResourceType.Id();
40 };
41 
42 class ObjectResourceType : public IntroduceInterfaces<MetaObject, CORE_NS::IResourceType, IObjectResource> {
43     META_OBJECT(ObjectResourceType, ClassId::ObjectResourceType, IntroduceInterfaces)
44 public:
45     BASE_NS::string GetResourceName() const override;
46     BASE_NS::Uid GetResourceType() const override;
47     CORE_NS::IResource::Ptr LoadResource(const StorageInfo&) const override;
48     bool SaveResource(const CORE_NS::IResource::ConstPtr&, const StorageInfo&) const override;
49     bool ReloadResource(const StorageInfo&, const CORE_NS::IResource::Ptr&) const override;
50 
51     void SetResourceType(const ObjectId& id) override;
52 
53 private:
54     ObjectId type_ = ClassId::ObjectResourceType.Id();
55 };
56 
57 class ObjectResourceOptions
58     : public IntroduceInterfaces<MetaObject, META_NS::IObjectResourceOptions, META_NS::ISerializable> {
59     META_OBJECT(ObjectResourceOptions, ClassId::ObjectResourceOptions, IntroduceInterfaces)
60 public:
61     bool Load(CORE_NS::IFile& options, const CORE_NS::ResourceManagerPtr&, const CORE_NS::ResourceContextPtr&) override;
62     bool Save(CORE_NS::IFile& options, const CORE_NS::ResourceManagerPtr&) const override;
63 
SetBaseResource(CORE_NS::ResourceId id)64     void SetBaseResource(CORE_NS::ResourceId id) override
65     {
66         baseResource_ = BASE_NS::move(id);
67     }
GetBaseResource()68     CORE_NS::ResourceId GetBaseResource() const override
69     {
70         return baseResource_;
71     }
72 
73     IProperty::Ptr GetProperty(BASE_NS::string_view name) override;
74     void SetProperty(const IProperty::Ptr&) override;
75 
76     META_NS::ReturnError Export(META_NS::IExportContext&) const override;
77     META_NS::ReturnError Import(META_NS::IImportContext&) override;
78 
79 private:
80     CORE_NS::ResourceId baseResource_;
81 };
82 
83 META_END_NAMESPACE()
84 
85 #endif
86