1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkDeque_DEFINED 18 #define SkDeque_DEFINED 19 20 #include "SkTypes.h" 21 22 class SkDeque : SkNoncopyable { 23 public: 24 explicit SkDeque(size_t elemSize); 25 SkDeque(size_t elemSize, void* storage, size_t storageSize); 26 ~SkDeque(); 27 28 bool empty() const { return 0 == fCount; } 29 int count() const { return fCount; } 30 size_t elemSize() const { return fElemSize; } 31 32 const void* front() const; 33 const void* back() const; 34 35 void* front() { 36 return (void*)((const SkDeque*)this)->front(); 37 } 38 39 void* back() { 40 return (void*)((const SkDeque*)this)->back(); 41 } 42 43 void* push_front(); 44 void* push_back(); 45 46 void pop_front(); 47 void pop_back(); 48 49 private: 50 struct Head; 51 52 public: 53 class Iter { 54 public: 55 Iter(const SkDeque& d); 56 void* next(); 57 58 private: 59 SkDeque::Head* fHead; 60 char* fPos; 61 size_t fElemSize; 62 }; 63 64 private: 65 Head* fFront; 66 Head* fBack; 67 size_t fElemSize; 68 void* fInitialStorage; 69 int fCount; 70 71 friend class Iter; 72 }; 73 74 #endif 75