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 IM_RENDER_FIFO_QUEUE_H
17 #define IM_RENDER_FIFO_QUEUE_H
18 
19 #include "render_queue_itf.h"
20 
21 #include <list>
22 
23 template <typename T> class RenderFifoQueue : public RenderQueueItf<T> {
24 public:
25     ~RenderFifoQueue() = default;
26 
GetSize()27     size_t GetSize() override
28     {
29         return _list.size();
30     }
31 
Push(const T & data)32     bool Push(const T &data) override
33     {
34         _list.emplace_back(data);
35         return true;
36     }
37 
Pop(T & result)38     bool Pop(T &result) override
39     {
40         if (_list.size() == 0) {
41             return false; // empty
42         }
43         result = _list.front();
44         _list.pop_front();
45         return true;
46     }
47 
PopWithCallBack(T & result,std::function<void (T &)> & callback)48     bool PopWithCallBack(T &result, std::function<void(T &)> &callback) override
49     {
50         if (_list.size() == 0) {
51             return false; // empty
52         }
53         result = _list.front();
54         _list.pop_front();
55         callback(result);
56         return true;
57     }
58 
Front(T & result)59     bool Front(T &result) override
60     {
61         if (_list.size() == 0) {
62             return false; // empty
63         }
64         result = _list.front();
65         return true;
66     }
67 
Back(T & result)68     bool Back(T &result) override
69     {
70         if (_list.size() == 0) {
71             return false; // empty
72         }
73         result = _list.back();
74         return true;
75     }
76 
RemoveAll()77     void RemoveAll() override
78     {
79         _list.clear();
80     }
81 
Remove(const std::function<bool (T &)> & checkFunc)82     void Remove(const std::function<bool(T &)> &checkFunc) override
83     {
84         _list.remove_if(checkFunc);
85     }
86 
87 private:
88     std::list<T> _list;
89 };
90 #endif