1 /*
2  * Copyright (c) 2020 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 #include "ability_slice_stack.h"
17 #include "ability_slice.h"
18 
19 namespace OHOS {
~AbilitySliceStack()20 AbilitySliceStack::~AbilitySliceStack()
21 {
22     Clear();
23 }
24 
IsEmpty() const25 bool AbilitySliceStack::IsEmpty() const
26 {
27     return slices_.empty();
28 }
29 
Size() const30 int AbilitySliceStack::Size() const
31 {
32     return slices_.size();
33 }
34 
Exist(const AbilitySlice * slice) const35 bool AbilitySliceStack::Exist(const AbilitySlice *slice) const
36 {
37     return std::find(slices_.begin(), slices_.end(), slice) != slices_.end();
38 }
39 
Remove(AbilitySlice * slice)40 void AbilitySliceStack::Remove(AbilitySlice *slice)
41 {
42     slices_.remove(slice);
43 }
44 
Top() const45 const AbilitySlice *AbilitySliceStack::Top() const
46 {
47     if (slices_.empty()) {
48         return nullptr;
49     }
50 
51     return slices_.front();
52 }
53 
Pop()54 AbilitySlice *AbilitySliceStack::Pop()
55 {
56     if (slices_.empty()) {
57         return nullptr;
58     }
59 
60     AbilitySlice *topSlice = slices_.front();
61     slices_.pop_front();
62     return topSlice;
63 }
64 
Push(AbilitySlice * slice)65 void AbilitySliceStack::Push(AbilitySlice *slice)
66 {
67     slices_.push_front(slice);
68 }
69 
GetAllSlices() const70 std::list<AbilitySlice *> AbilitySliceStack::GetAllSlices() const
71 {
72     return slices_;
73 }
74 
Clear()75 void AbilitySliceStack::Clear()
76 {
77     for (auto node : slices_) {
78         delete node;
79     }
80     slices_.clear();
81 }
82 }
83