media/omx-plugin/include/ics/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 ssize_t resize(size_t size);
michael@0 68
michael@0 69 /*! append/insert another vector or array */
michael@0 70 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
michael@0 71 ssize_t appendVector(const VectorImpl& vector);
michael@0 72 ssize_t insertArrayAt(const void* array, size_t index, size_t length);
michael@0 73 ssize_t appendArray(const void* array, size_t length);
michael@0 74
michael@0 75 /*! add/insert/replace items */
michael@0 76 ssize_t insertAt(size_t where, size_t numItems = 1);
michael@0 77 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
michael@0 78 void pop();
michael@0 79 void push();
michael@0 80 void push(const void* item);
michael@0 81 ssize_t add();
michael@0 82 ssize_t add(const void* item);
michael@0 83 ssize_t replaceAt(size_t index);
michael@0 84 ssize_t replaceAt(const void* item, size_t index);
michael@0 85
michael@0 86 /*! remove items */
michael@0 87 ssize_t removeItemsAt(size_t index, size_t count = 1);
michael@0 88 void clear();
michael@0 89
michael@0 90 const void* itemLocation(size_t index) const;
michael@0 91 void* editItemLocation(size_t index);
michael@0 92
michael@0 93 typedef int (*compar_t)(const void* lhs, const void* rhs);
michael@0 94 typedef int (*compar_r_t)(const void* lhs, const void* rhs, void* state);
michael@0 95 status_t sort(compar_t cmp);
michael@0 96 status_t sort(compar_r_t cmp, void* state);
michael@0 97
michael@0 98 protected:
michael@0 99 size_t itemSize() const;
michael@0 100 void release_storage();
michael@0 101
michael@0 102 virtual void do_construct(void* storage, size_t num) const = 0;
michael@0 103 virtual void do_destroy(void* storage, size_t num) const = 0;
michael@0 104 virtual void do_copy(void* dest, const void* from, size_t num) const = 0;
michael@0 105 virtual void do_splat(void* dest, const void* item, size_t num) const = 0;
michael@0 106 virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0;
michael@0 107 virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0;
michael@0 108
michael@0 109 private:
michael@0 110 void* _grow(size_t where, size_t amount);
michael@0 111 void _shrink(size_t where, size_t amount);
michael@0 112
michael@0 113 inline void _do_construct(void* storage, size_t num) const;
michael@0 114 inline void _do_destroy(void* storage, size_t num) const;
michael@0 115 inline void _do_copy(void* dest, const void* from, size_t num) const;
michael@0 116 inline void _do_splat(void* dest, const void* item, size_t num) const;
michael@0 117 inline void _do_move_forward(void* dest, const void* from, size_t num) const;
michael@0 118 inline void _do_move_backward(void* dest, const void* from, size_t num) const;
michael@0 119
michael@0 120 // These 2 fields are exposed in the inlines below,
michael@0 121 // so they're set in stone.
michael@0 122 void * mStorage; // base address of the vector
michael@0 123 size_t mCount; // number of items
michael@0 124
michael@0 125 const uint32_t mFlags;
michael@0 126 const size_t mItemSize;
michael@0 127 };
michael@0 128
michael@0 129
michael@0 130
michael@0 131 class SortedVectorImpl : public VectorImpl
michael@0 132 {
michael@0 133 public:
michael@0 134 SortedVectorImpl(size_t itemSize, uint32_t flags);
michael@0 135 SortedVectorImpl(const VectorImpl& rhs);
michael@0 136 virtual ~SortedVectorImpl();
michael@0 137
michael@0 138 SortedVectorImpl& operator = (const SortedVectorImpl& rhs);
michael@0 139
michael@0 140 //! finds the index of an item
michael@0 141 ssize_t indexOf(const void* item) const;
michael@0 142
michael@0 143 //! finds where this item should be inserted
michael@0 144 size_t orderOf(const void* item) const;
michael@0 145
michael@0 146 //! add an item in the right place (or replaces it if there is one)
michael@0 147 ssize_t add(const void* item);
michael@0 148
michael@0 149 //! merges a vector into this one
michael@0 150 ssize_t merge(const VectorImpl& vector);
michael@0 151 ssize_t merge(const SortedVectorImpl& vector);
michael@0 152
michael@0 153 //! removes an item
michael@0 154 ssize_t remove(const void* item);
michael@0 155
michael@0 156 protected:
michael@0 157 virtual int do_compare(const void* lhs, const void* rhs) const = 0;
michael@0 158
michael@0 159 private:
michael@0 160 ssize_t _indexOrderOf(const void* item, size_t* order = 0) const;
michael@0 161
michael@0 162 // these are made private, because they can't be used on a SortedVector
michael@0 163 // (they don't have an implementation either)
michael@0 164 ssize_t add();
michael@0 165 void pop();
michael@0 166 void push();
michael@0 167 void push(const void* item);
michael@0 168 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
michael@0 169 ssize_t appendVector(const VectorImpl& vector);
michael@0 170 ssize_t insertArrayAt(const void* array, size_t index, size_t length);
michael@0 171 ssize_t appendArray(const void* array, size_t length);
michael@0 172 ssize_t insertAt(size_t where, size_t numItems = 1);
michael@0 173 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
michael@0 174 ssize_t replaceAt(size_t index);
michael@0 175 ssize_t replaceAt(const void* item, size_t index);
michael@0 176 };
michael@0 177
michael@0 178 }; // namespace android
michael@0 179
michael@0 180
michael@0 181 // ---------------------------------------------------------------------------
michael@0 182
michael@0 183 #endif // ANDROID_VECTOR_IMPL_H
michael@0 184

mercurial