• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CORE_COMPONENTS_NG_RENDER_ADAPTER_LINEAR_VECTOR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_LINEAR_VECTOR_H
18 
19 #include <vector>
20 
21 #include "base/geometry/size.h"
22 #include "frameworks/base/utils/macros.h"
23 
24 namespace OHOS::Ace::NG {
25 template<typename T>
26 class ACE_EXPORT LinearVector : public std::vector<T> {
27 public:
28     LinearVector() = default;
LinearVector(const size_t n)29     explicit LinearVector(const size_t n) : std::vector<T>(n) {};
LinearVector(const size_t n,T value)30     LinearVector(const size_t n, T value) : std::vector<T>(n, value) {};
31     ~LinearVector() = default;
32 
33     LinearVector operator+(const LinearVector& linearVector) const
34     {
35         LinearVector tempLinearVector = *this;
36         for (size_t i = 0; i < tempLinearVector.size() && i < linearVector.size(); ++i) {
37             tempLinearVector[i] += linearVector[i];
38         }
39         return tempLinearVector;
40     }
41 
42     LinearVector operator-(const LinearVector& linearVector) const
43     {
44         LinearVector tempLinearVector = *this;
45         for (size_t i = 0; i < tempLinearVector.size() && i < linearVector.size(); ++i) {
46             tempLinearVector[i] -= linearVector[i];
47         }
48         return tempLinearVector;
49     }
50 
51     LinearVector operator*(const float scale) const
52     {
53         LinearVector linearVector = *this;
54         for (size_t i = 0; i < linearVector.size(); ++i) {
55             linearVector[i] *= scale;
56         }
57         return linearVector;
58     }
59 
60     bool operator==(const LinearVector& linearVector) const
61     {
62         if (this->size() != linearVector.size()) {
63             return false;
64         }
65         for (size_t i = 0; i < linearVector.size(); ++i) {
66             if (this->at(i) != linearVector[i]) {
67                 return false;
68             }
69         }
70         return true;
71     }
72 };
73 } // namespace OHOS::Ace::NG
74 
75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_LINEAR_VECTOR_H
76