media/omx-plugin/include/froyo/utils/VectorImpl.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (C) 2005 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef ANDROID_VECTOR_IMPL_H
michael@0 18 #define ANDROID_VECTOR_IMPL_H
michael@0 19
michael@0 20 #include <assert.h>
michael@0 21 #include <stdint.h>
michael@0 22 #include <sys/types.h>
michael@0 23 #include <utils/Errors.h>
michael@0 24
michael@0 25 // ---------------------------------------------------------------------------
michael@0 26 // No user serviceable parts in here...
michael@0 27 // ---------------------------------------------------------------------------
michael@0 28
michael@0 29 namespace android {
michael@0 30
michael@0 31 /*!
michael@0 32 * Implementation of the guts of the vector<> class
michael@0 33 * this ensures backward binary compatibility and
michael@0 34 * reduces code size.
michael@0 35 * For performance reasons, we expose mStorage and mCount
michael@0 36 * so these fields are set in stone.
michael@0 37 *
michael@0 38 */
michael@0 39
michael@0 40 class VectorImpl
michael@0 41 {
michael@0 42 public:
michael@0 43 enum { // flags passed to the ctor
michael@0 44 HAS_TRIVIAL_CTOR = 0x00000001,
michael@0 45 HAS_TRIVIAL_DTOR = 0x00000002,
michael@0 46 HAS_TRIVIAL_COPY = 0x00000004,
michael@0 47 };
michael@0 48
michael@0 49 VectorImpl(size_t itemSize, uint32_t flags);
michael@0 50 VectorImpl(const VectorImpl& rhs);
michael@0 51 virtual ~VectorImpl();
michael@0 52
michael@0 53 /*! must be called from subclasses destructor */
michael@0 54 void finish_vector();
michael@0 55
michael@0 56 VectorImpl& operator = (const VectorImpl& rhs);
michael@0 57
michael@0 58 /*! C-style array access */
michael@0 59 inline const void* arrayImpl() const { return mStorage; }
michael@0 60 void* editArrayImpl();
michael@0 61
michael@0 62 /*! vector stats */
michael@0 63 inline size_t size() const { return mCount; }
michael@0 64 inline bool isEmpty() const { return mCount == 0; }
michael@0 65 size_t capacity() const;
michael@0 66 ssize_t setCapacity(size_t size);
michael@0 67
michael@0 68 /*! append/insert another vector */
michael@0 69 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
michael@0 70 ssize_t appendVector(const VectorImpl& vector);
michael@0 71
michael@0 72 /*! add/insert/replace items */
michael@0 73 ssize_t insertAt(size_t where, size_t numItems = 1);
michael@0 74 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
michael@0 75 void pop();
michael@0 76 void push();
michael@0 77 void push(const void* item);
michael@0 78 ssize_t add();
michael@0 79 ssize_t add(const void* item);
michael@0 80 ssize_t replaceAt(size_t index);
michael@0 81 ssize_t replaceAt(const void* item, size_t index);
michael@0 82
michael@0 83 /*! remove items */
michael@0 84 ssize_t removeItemsAt(size_t index, size_t count = 1);
michael@0 85 void clear();
michael@0 86
michael@0 87 const void* itemLocation(size_t index) const;
michael@0 88 void* editItemLocation(size_t index);
michael@0 89
michael@0 90 typedef int (*compar_t)(const void* lhs, const void* rhs);
michael@0 91 typedef int (*compar_r_t)(const void* lhs, const void* rhs, void* state);
michael@0 92 status_t sort(compar_t cmp);
michael@0 93 status_t sort(compar_r_t cmp, void* state);
michael@0 94
michael@0 95 protected:
michael@0 96 size_t itemSize() const;
michael@0 97 void release_storage();
michael@0 98
michael@0 99 virtual void do_construct(void* storage, size_t num) const = 0;
michael@0 100 virtual void do_destroy(void* storage, size_t num) const = 0;
michael@0 101 virtual void do_copy(void* dest, const void* from, size_t num) const = 0;
michael@0 102 virtual void do_splat(void* dest, const void* item, size_t num) const = 0;
michael@0 103 virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0;
michael@0 104 virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0;
michael@0 105
michael@0 106 // take care of FBC...
michael@0 107 virtual void reservedVectorImpl1();
michael@0 108 virtual void reservedVectorImpl2();
michael@0 109 virtual void reservedVectorImpl3();
michael@0 110 virtual void reservedVectorImpl4();
michael@0 111 virtual void reservedVectorImpl5();
michael@0 112 virtual void reservedVectorImpl6();
michael@0 113 virtual void reservedVectorImpl7();
michael@0 114 virtual void reservedVectorImpl8();
michael@0 115
michael@0 116 private:
michael@0 117 void* _grow(size_t where, size_t amount);
michael@0 118 void _shrink(size_t where, size_t amount);
michael@0 119
michael@0 120 inline void _do_construct(void* storage, size_t num) const;
michael@0 121 inline void _do_destroy(void* storage, size_t num) const;
michael@0 122 inline void _do_copy(void* dest, const void* from, size_t num) const;
michael@0 123 inline void _do_splat(void* dest, const void* item, size_t num) const;
michael@0 124 inline void _do_move_forward(void* dest, const void* from, size_t num) const;
michael@0 125 inline void _do_move_backward(void* dest, const void* from, size_t num) const;
michael@0 126
michael@0 127 // These 2 fields are exposed in the inlines below,
michael@0 128 // so they're set in stone.
michael@0 129 void * mStorage; // base address of the vector
michael@0 130 size_t mCount; // number of items
michael@0 131
michael@0 132 const uint32_t mFlags;
michael@0 133 const size_t mItemSize;
michael@0 134 };
michael@0 135
michael@0 136
michael@0 137
michael@0 138 class SortedVectorImpl : public VectorImpl
michael@0 139 {
michael@0 140 public:
michael@0 141 SortedVectorImpl(size_t itemSize, uint32_t flags);
michael@0 142 SortedVectorImpl(const VectorImpl& rhs);
michael@0 143 virtual ~SortedVectorImpl();
michael@0 144
michael@0 145 SortedVectorImpl& operator = (const SortedVectorImpl& rhs);
michael@0 146
michael@0 147 //! finds the index of an item
michael@0 148 ssize_t indexOf(const void* item) const;
michael@0 149
michael@0 150 //! finds where this item should be inserted
michael@0 151 size_t orderOf(const void* item) const;
michael@0 152
michael@0 153 //! add an item in the right place (or replaces it if there is one)
michael@0 154 ssize_t add(const void* item);
michael@0 155
michael@0 156 //! merges a vector into this one
michael@0 157 ssize_t merge(const VectorImpl& vector);
michael@0 158 ssize_t merge(const SortedVectorImpl& vector);
michael@0 159
michael@0 160 //! removes an item
michael@0 161 ssize_t remove(const void* item);
michael@0 162
michael@0 163 protected:
michael@0 164 virtual int do_compare(const void* lhs, const void* rhs) const = 0;
michael@0 165
michael@0 166 // take care of FBC...
michael@0 167 virtual void reservedSortedVectorImpl1();
michael@0 168 virtual void reservedSortedVectorImpl2();
michael@0 169 virtual void reservedSortedVectorImpl3();
michael@0 170 virtual void reservedSortedVectorImpl4();
michael@0 171 virtual void reservedSortedVectorImpl5();
michael@0 172 virtual void reservedSortedVectorImpl6();
michael@0 173 virtual void reservedSortedVectorImpl7();
michael@0 174 virtual void reservedSortedVectorImpl8();
michael@0 175
michael@0 176 private:
michael@0 177 ssize_t _indexOrderOf(const void* item, size_t* order = 0) const;
michael@0 178
michael@0 179 // these are made private, because they can't be used on a SortedVector
michael@0 180 // (they don't have an implementation either)
michael@0 181 ssize_t add();
michael@0 182 void pop();
michael@0 183 void push();
michael@0 184 void push(const void* item);
michael@0 185 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
michael@0 186 ssize_t appendVector(const VectorImpl& vector);
michael@0 187 ssize_t insertAt(size_t where, size_t numItems = 1);
michael@0 188 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
michael@0 189 ssize_t replaceAt(size_t index);
michael@0 190 ssize_t replaceAt(const void* item, size_t index);
michael@0 191 };
michael@0 192
michael@0 193 }; // namespace android
michael@0 194
michael@0 195
michael@0 196 // ---------------------------------------------------------------------------
michael@0 197
michael@0 198 #endif // ANDROID_VECTOR_IMPL_H

mercurial