SkDeque.h revision 7ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577
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
22class SK_API SkDeque : SkNoncopyable {
23public:
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
49private:
50    struct Head;
51
52public:
53    class F2BIter {
54    public:
55        /**
56         * Creates an uninitialized iterator. Must be reset()
57         */
58        F2BIter();
59
60        F2BIter(const SkDeque& d);
61        void* next();
62
63        void reset(const SkDeque& d);
64
65    private:
66        SkDeque::Head*  fHead;
67        char*           fPos;
68        size_t          fElemSize;
69    };
70
71private:
72    Head*   fFront;
73    Head*   fBack;
74    size_t  fElemSize;
75    void*   fInitialStorage;
76    int     fCount;
77
78    friend class Iter;
79};
80
81#endif
82