• 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 UTILS_INCLUDE_RING_ARRAY_H
17 #define UTILS_INCLUDE_RING_ARRAY_H
18 #include <cstdint>
19 #include <variant>
20 
21 namespace OHOS {
22 namespace Rosen {
23 
24 class RingArray {
25 public:
26     RingArray(); // default size of ringArray is 100
27     explicit RingArray(int arrayCapability);
28     ~RingArray();
29 
30     void Init();
31     void ClearArray();
32     bool IsArrayEmpty() const;
33     bool IsArrayFull() const;
34     int ArraySize() const;
35     int ArrayCapability() const;
36     void PushElement(std::variant<int64_t, float, bool> element);
37     bool PopElement(std::variant<int64_t, float, bool> element);
38     std::variant<int64_t, float, bool> GetElement(const int& pos) const;  // count elements from head
39     std::variant<int64_t, float, bool> GetElementR(const int& pos) const; // count elements from tail
40     std::variant<int64_t, float, bool> GetHeadElement() const;
41     std::variant<int64_t, float, bool> GetTailElement() const;
42 
43 private:
44     std::variant<int64_t, float, bool>* ringArray_;
45     int arrayLen_;
46     int arrayCapability_;
47     int arrayHead_;
48     int arrayTail_;
49 };
50 
51 } // namespace Rosen
52 } // namespace OHOS
53 
54 #endif // UTILS_INCLUDE_RING_ARRAY_H