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_flags.h> 26 #include <meta/interface/intf_owner.h> 27 28 META_BEGIN_NAMESPACE() 29 30 META_REGISTER_INTERFACE(IProperty, "772086d4-b7eb-437e-b71b-83353caaffaf") 31 32 /** 33 * @brief Typeless property interface, values are accessed as IAny. 34 * 35 * @Notice IProperty does not do any locking for its functions, one has to explicitly lock from outside. 36 * Use one of the wrapper types to safely access properties (see Property<>, ArrayProperty<> and associated). 37 */ 38 class IProperty : public INotifyOnChange { 39 META_INTERFACE(INotifyOnChange, IProperty) 40 public: 41 /// Get the property's name 42 virtual BASE_NS::string GetName() const = 0; 43 /// Get the property's owner or nullptr 44 virtual IOwner::WeakPtr GetOwner() const = 0; 45 46 /// Set value, the value is copied from the given IAny if compatible. Returns result. 47 virtual AnyReturnValue SetValue(const IAny& value) = 0; 48 /// Get value, returns invalid any that is not compatible with anything in case of error. 49 virtual const IAny& GetValue() const = 0; 50 /// Check if property value is compatible with given type id. 51 virtual bool IsCompatible(const TypeId& id) const = 0; 52 /// Get the type id of the property value 53 virtual TypeId GetTypeId() const = 0; 54 /// Mark that the property has to be re-evaluated on GetValue and invoke the OnChanged handlers. 55 virtual void NotifyChange() const = 0; 56 /// Reset the property value to value-constructed value of the contained type. See IStackResetable for changing this 57 /// behaviour. 58 virtual void ResetValue() = 0; 59 /// Check if this property has default value (the value has not been set explicitly by user) 60 virtual bool IsDefaultValue() const = 0; 61 /// Check if user has set value for this property IsValueSet()62 bool IsValueSet() const 63 { 64 return !IsDefaultValue(); 65 } 66 }; 67 68 META_END_NAMESPACE() 69 70 META_INTERFACE_TYPE(META_NS::IProperty) 71 72 #endif 73