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_PROPERTY_H
17 #define META_INTERFACE_PROPERTY_H
18 
19 #include <meta/base/expected.h>
20 #include <meta/base/interface_macros.h>
21 #include <meta/base/namespace.h>
22 #include <meta/base/types.h>
23 #include <meta/interface/intf_any.h>
24 #include <meta/interface/intf_notify_on_change.h>
25 #include <meta/interface/intf_object.h>
26 #include <meta/interface/intf_object_flags.h>
27 
28 META_BEGIN_NAMESPACE()
29 
30 META_REGISTER_INTERFACE(IProperty, "772086d4-b7eb-437e-b71b-83353caaffaf")
31 
32 // Notice that IProperty does not guarantee thread safety, one should use one of the wrapper
33 // types to access the members to guarantee proper locking,
34 
35 class IProperty : public INotifyOnChange {
36     META_INTERFACE(INotifyOnChange, IProperty)
37 public:
38     virtual BASE_NS::string GetName() const = 0;
39     virtual IObject::WeakPtr GetOwner() const = 0;
40 
41     virtual AnyReturnValue SetValue(const IAny& value) = 0;
42     virtual const IAny& GetValue() const = 0;
43     virtual bool IsCompatible(const TypeId& id) const = 0;
44 
45     virtual TypeId GetTypeId() const = 0;
46     // Invoke the OnChanged handlers
47     virtual void NotifyChange() const = 0;
48 
49     virtual void ResetValue() = 0;
50     virtual bool IsDefaultValue() const = 0;
51 
IsValueSet()52     bool IsValueSet() const
53     {
54         return !IsDefaultValue();
55     }
56 };
57 
58 META_END_NAMESPACE()
59 
60 META_INTERFACE_TYPE(META_NS::IProperty)
61 
62 #endif
63