• 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_INTERFACE_PROPERTY_MODIFIER_H
17 #define META_INTERFACE_PROPERTY_MODIFIER_H
18 
19 #include <meta/base/interface_macros.h>
20 #include <meta/base/namespace.h>
21 #include <meta/base/types.h>
22 #include <meta/interface/intf_function.h>
23 #include <meta/interface/property/intf_property.h>
24 
25 META_BEGIN_NAMESPACE()
26 
27 /// Result the modifier evaluation functions return
28 enum EvaluationResult : uint8_t {
29     EVAL_CONTINUE = 0,      /// Continue evaluation of the stack
30     EVAL_ERROR = 1,         /// Error happened
31     EVAL_RETURN = 2,        /// Stop stack evaluation and return value
32     EVAL_VALUE_CHANGED = 4, /// This modifier changed the value
33 };
34 
35 inline EvaluationResult operator|(EvaluationResult l, EvaluationResult r)
36 {
37     return EvaluationResult(uint8_t(l) | uint8_t(r));
38 }
39 
40 META_REGISTER_INTERFACE(IModifier, "4a6991b7-c410-4663-99d2-4ff00eb9a9e0")
41 
42 /**
43  * @brief Modifier for property to allow to alter the property's behaviour on evaluation
44  *
45  * Modifiers can be added to property. The ProcessOnGet is called when GetValue is called
46  * for the property. The ProcessOnSet is called when SetValue is called for the property.
47  * In both cases the stack is evaluated and the modifiers are called in the order they are
48  * set for the property (for get from first to last and for set from last to first).
49  * The evaluation functions can alter the value being get/set and/or control the further
50  * evaluation process by terminating it, short circuiting it or simply continuing.
51  */
52 class IModifier : public CORE_NS::IInterface {
53     META_INTERFACE(CORE_NS::IInterface, IModifier)
54 public:
55     /**
56      * @brief Evaluation function for GetValue calls
57      * @param value The top most value in property stack (possibly after other modifiers have altered it).
58      * @return Evaluation result which decides the action for further modifier evaluation
59      */
60     virtual EvaluationResult ProcessOnGet(IAny& value) = 0;
61     /**
62      * @brief Evaluation function for SetValue calls
63      * @param value The value being set for the property
64      * @return Evaluation result which decides the action for further modifier evaluation and setting the value
65      */
66     virtual EvaluationResult ProcessOnSet(IAny& value, const IAny& current) = 0;
67     /// Check if this modifier is compatible with given type id
68     virtual bool IsCompatible(const TypeId& id) const = 0;
69 };
70 
71 META_INTERFACE_TYPE(META_NS::IModifier)
72 
73 META_END_NAMESPACE()
74 
75 #endif
76