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 18 #include <algorithm> 19 20 #include "ability_slice.h" 21 22 namespace OHOS { ~AbilitySliceStack()23AbilitySliceStack::~AbilitySliceStack() 24 { 25 Clear(); 26 } 27 IsEmpty() const28bool AbilitySliceStack::IsEmpty() const 29 { 30 return slices_.empty(); 31 } 32 Size() const33int AbilitySliceStack::Size() const 34 { 35 return slices_.size(); 36 } 37 Exist(const AbilitySlice * slice) const38bool AbilitySliceStack::Exist(const AbilitySlice *slice) const 39 { 40 return std::find(slices_.begin(), slices_.end(), slice) != slices_.end(); 41 } 42 Remove(AbilitySlice * slice)43void AbilitySliceStack::Remove(AbilitySlice *slice) 44 { 45 slices_.remove(slice); 46 } 47 Top() const48const AbilitySlice *AbilitySliceStack::Top() const 49 { 50 if (slices_.empty()) { 51 return nullptr; 52 } 53 54 return slices_.front(); 55 } 56 Pop()57AbilitySlice *AbilitySliceStack::Pop() 58 { 59 if (slices_.empty()) { 60 return nullptr; 61 } 62 63 AbilitySlice *topSlice = slices_.front(); 64 slices_.pop_front(); 65 return topSlice; 66 } 67 Push(AbilitySlice * slice)68void AbilitySliceStack::Push(AbilitySlice *slice) 69 { 70 slices_.push_front(slice); 71 } 72 GetAllSlices() const73std::list<AbilitySlice *> AbilitySliceStack::GetAllSlices() const 74 { 75 return slices_; 76 } 77 Clear()78void AbilitySliceStack::Clear() 79 { 80 for (auto node : slices_) { 81 delete node; 82 } 83 slices_.clear(); 84 } 85 } 86