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_INTERFACE_RESOURCE_IRESOURCE_H
17 #define META_INTERFACE_RESOURCE_IRESOURCE_H
18
19 #include <core/resources/intf_resource.h>
20
21 #include <meta/base/meta_types.h>
22 #include <meta/base/namespace.h>
23 #include <meta/interface/interface_macros.h>
24 #include <meta/interface/property/construct_property.h>
25
META_BEGIN_NAMESPACE()26 META_BEGIN_NAMESPACE()
27
28 class IDerivedFromResource : public CORE_NS::IInterface {
29 META_INTERFACE(CORE_NS::IInterface, IDerivedFromResource, "ea586292-8c95-482e-af6c-a0611818bbcb")
30 public:
31 virtual bool SetResource(const CORE_NS::IResource::Ptr&) = 0;
32 virtual CORE_NS::ResourceId GetResource() const = 0;
33 virtual CORE_NS::IResource::Ptr CreateResource() const = 0;
34 };
35
36 class IObjectResourceOptions : public CORE_NS::IResourceOptions {
37 META_INTERFACE(CORE_NS::IResourceOptions, IObjectResourceOptions, "3a8559b2-ad80-48f5-8e3b-3340c9048f77")
38 public:
39 virtual void SetBaseResource(CORE_NS::ResourceId) = 0;
40 virtual CORE_NS::ResourceId GetBaseResource() const = 0;
41
42 virtual IProperty::Ptr GetProperty(BASE_NS::string_view name) = 0;
43 template<typename T>
GetProperty(BASE_NS::string_view name)44 Property<T> GetProperty(BASE_NS::string_view name)
45 {
46 return Property<T>(GetProperty(name));
47 }
48
49 virtual void SetProperty(const IProperty::Ptr&) = 0;
50 template<typename T>
SetProperty(BASE_NS::string_view name,const T & value)51 void SetProperty(BASE_NS::string_view name, const T& value)
52 {
53 SetProperty(ConstructProperty<T>(name, value));
54 }
55 };
56
57 META_REGISTER_CLASS(
58 ObjectResourceOptions, "196213b6-eb63-4a29-89be-1ec10ed68596", META_NS::ObjectCategoryBits::NO_CATEGORY)
59
60 META_TYPE(CORE_NS::ResourceId)
61 META_INTERFACE_TYPE(CORE_NS::IResource)
62 META_INTERFACE_TYPE(CORE_NS::ISetResourceId)
63 META_INTERFACE_TYPE(CORE_NS::IResourceOptions)
64 META_INTERFACE_TYPE(META_NS::IDerivedFromResource)
65 META_INTERFACE_TYPE(META_NS::IObjectResourceOptions)
66
67 META_END_NAMESPACE()
68
69 #endif
70