1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_H
17 #define FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_H
18 
19 #include <memory>
20 
21 #include "base/memory/ace_type.h"
22 namespace OHOS::Ace::NG {
23 template<typename T>
24 class ACE_EXPORT Arithmetic {
25 public:
26     Arithmetic() = default;
27     virtual ~Arithmetic() = default;
28 
29     virtual bool IsEqual(const T& value) const = 0;
30 
31     bool operator==(const T& value) const
32     {
33         return IsEqual(value);
34     }
35 
36     bool operator!=(const T& value) const
37     {
38         return !IsEqual(value);
39     }
40 };
41 
42 template<typename T>
43 class ACE_EXPORT AnimatableArithmetic : public Arithmetic<T> {
44 public:
45     AnimatableArithmetic() = default;
46     virtual ~AnimatableArithmetic() = default;
47 
48     virtual T Add(const T& value) const = 0;
49     virtual T Minus(const T& value) const = 0;
50     virtual T Multiply(const float scale) const = 0;
51 
52     T operator+(const T& value) const
53     {
54         return Add(value);
55     }
56     T operator+=(const T& value) const
57     {
58         return Add(value);
59     }
60     T operator-(const T& value) const
61     {
62         return Minus(value);
63     }
64     T operator-=(const T& value) const
65     {
66         return Minus(value);
67     }
68     T operator*(const float scale) const
69     {
70         return Multiply(scale);
71     }
72     T operator*=(const float scale) const
73     {
74         return Multiply(scale);
75     }
76 };
77 
78 class ACE_EXPORT CustomAnimatableArithmetic : public AceType,
79                                               public AnimatableArithmetic<RefPtr<CustomAnimatableArithmetic>> {
80     DECLARE_ACE_TYPE(CustomAnimatableArithmetic, AceType)
81 public:
82     CustomAnimatableArithmetic() = default;
83     ~CustomAnimatableArithmetic() override = default;
84 
Add(const RefPtr<CustomAnimatableArithmetic> & value)85     RefPtr<CustomAnimatableArithmetic> Add(const RefPtr<CustomAnimatableArithmetic>& value) const override
86     {
87         return {};
88     };
Minus(const RefPtr<CustomAnimatableArithmetic> & value)89     RefPtr<CustomAnimatableArithmetic> Minus(const RefPtr<CustomAnimatableArithmetic>& value) const override
90     {
91         return {};
92     }
Multiply(const float scale)93     RefPtr<CustomAnimatableArithmetic> Multiply(const float scale) const override
94     {
95         return {};
96     }
IsEqual(const RefPtr<CustomAnimatableArithmetic> & value)97     bool IsEqual(const RefPtr<CustomAnimatableArithmetic>& value) const override
98     {
99         return true;
100     }
101 };
102 } // namespace OHOS::Ace::NG
103 
104 #endif // FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_H
105