1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/froyo/utils/VectorImpl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,198 @@ 1.4 +/* 1.5 + * Copyright (C) 2005 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef ANDROID_VECTOR_IMPL_H 1.21 +#define ANDROID_VECTOR_IMPL_H 1.22 + 1.23 +#include <assert.h> 1.24 +#include <stdint.h> 1.25 +#include <sys/types.h> 1.26 +#include <utils/Errors.h> 1.27 + 1.28 +// --------------------------------------------------------------------------- 1.29 +// No user serviceable parts in here... 1.30 +// --------------------------------------------------------------------------- 1.31 + 1.32 +namespace android { 1.33 + 1.34 +/*! 1.35 + * Implementation of the guts of the vector<> class 1.36 + * this ensures backward binary compatibility and 1.37 + * reduces code size. 1.38 + * For performance reasons, we expose mStorage and mCount 1.39 + * so these fields are set in stone. 1.40 + * 1.41 + */ 1.42 + 1.43 +class VectorImpl 1.44 +{ 1.45 +public: 1.46 + enum { // flags passed to the ctor 1.47 + HAS_TRIVIAL_CTOR = 0x00000001, 1.48 + HAS_TRIVIAL_DTOR = 0x00000002, 1.49 + HAS_TRIVIAL_COPY = 0x00000004, 1.50 + }; 1.51 + 1.52 + VectorImpl(size_t itemSize, uint32_t flags); 1.53 + VectorImpl(const VectorImpl& rhs); 1.54 + virtual ~VectorImpl(); 1.55 + 1.56 + /*! must be called from subclasses destructor */ 1.57 + void finish_vector(); 1.58 + 1.59 + VectorImpl& operator = (const VectorImpl& rhs); 1.60 + 1.61 + /*! C-style array access */ 1.62 + inline const void* arrayImpl() const { return mStorage; } 1.63 + void* editArrayImpl(); 1.64 + 1.65 + /*! vector stats */ 1.66 + inline size_t size() const { return mCount; } 1.67 + inline bool isEmpty() const { return mCount == 0; } 1.68 + size_t capacity() const; 1.69 + ssize_t setCapacity(size_t size); 1.70 + 1.71 + /*! append/insert another vector */ 1.72 + ssize_t insertVectorAt(const VectorImpl& vector, size_t index); 1.73 + ssize_t appendVector(const VectorImpl& vector); 1.74 + 1.75 + /*! add/insert/replace items */ 1.76 + ssize_t insertAt(size_t where, size_t numItems = 1); 1.77 + ssize_t insertAt(const void* item, size_t where, size_t numItems = 1); 1.78 + void pop(); 1.79 + void push(); 1.80 + void push(const void* item); 1.81 + ssize_t add(); 1.82 + ssize_t add(const void* item); 1.83 + ssize_t replaceAt(size_t index); 1.84 + ssize_t replaceAt(const void* item, size_t index); 1.85 + 1.86 + /*! remove items */ 1.87 + ssize_t removeItemsAt(size_t index, size_t count = 1); 1.88 + void clear(); 1.89 + 1.90 + const void* itemLocation(size_t index) const; 1.91 + void* editItemLocation(size_t index); 1.92 + 1.93 + typedef int (*compar_t)(const void* lhs, const void* rhs); 1.94 + typedef int (*compar_r_t)(const void* lhs, const void* rhs, void* state); 1.95 + status_t sort(compar_t cmp); 1.96 + status_t sort(compar_r_t cmp, void* state); 1.97 + 1.98 +protected: 1.99 + size_t itemSize() const; 1.100 + void release_storage(); 1.101 + 1.102 + virtual void do_construct(void* storage, size_t num) const = 0; 1.103 + virtual void do_destroy(void* storage, size_t num) const = 0; 1.104 + virtual void do_copy(void* dest, const void* from, size_t num) const = 0; 1.105 + virtual void do_splat(void* dest, const void* item, size_t num) const = 0; 1.106 + virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0; 1.107 + virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0; 1.108 + 1.109 + // take care of FBC... 1.110 + virtual void reservedVectorImpl1(); 1.111 + virtual void reservedVectorImpl2(); 1.112 + virtual void reservedVectorImpl3(); 1.113 + virtual void reservedVectorImpl4(); 1.114 + virtual void reservedVectorImpl5(); 1.115 + virtual void reservedVectorImpl6(); 1.116 + virtual void reservedVectorImpl7(); 1.117 + virtual void reservedVectorImpl8(); 1.118 + 1.119 +private: 1.120 + void* _grow(size_t where, size_t amount); 1.121 + void _shrink(size_t where, size_t amount); 1.122 + 1.123 + inline void _do_construct(void* storage, size_t num) const; 1.124 + inline void _do_destroy(void* storage, size_t num) const; 1.125 + inline void _do_copy(void* dest, const void* from, size_t num) const; 1.126 + inline void _do_splat(void* dest, const void* item, size_t num) const; 1.127 + inline void _do_move_forward(void* dest, const void* from, size_t num) const; 1.128 + inline void _do_move_backward(void* dest, const void* from, size_t num) const; 1.129 + 1.130 + // These 2 fields are exposed in the inlines below, 1.131 + // so they're set in stone. 1.132 + void * mStorage; // base address of the vector 1.133 + size_t mCount; // number of items 1.134 + 1.135 + const uint32_t mFlags; 1.136 + const size_t mItemSize; 1.137 +}; 1.138 + 1.139 + 1.140 + 1.141 +class SortedVectorImpl : public VectorImpl 1.142 +{ 1.143 +public: 1.144 + SortedVectorImpl(size_t itemSize, uint32_t flags); 1.145 + SortedVectorImpl(const VectorImpl& rhs); 1.146 + virtual ~SortedVectorImpl(); 1.147 + 1.148 + SortedVectorImpl& operator = (const SortedVectorImpl& rhs); 1.149 + 1.150 + //! finds the index of an item 1.151 + ssize_t indexOf(const void* item) const; 1.152 + 1.153 + //! finds where this item should be inserted 1.154 + size_t orderOf(const void* item) const; 1.155 + 1.156 + //! add an item in the right place (or replaces it if there is one) 1.157 + ssize_t add(const void* item); 1.158 + 1.159 + //! merges a vector into this one 1.160 + ssize_t merge(const VectorImpl& vector); 1.161 + ssize_t merge(const SortedVectorImpl& vector); 1.162 + 1.163 + //! removes an item 1.164 + ssize_t remove(const void* item); 1.165 + 1.166 +protected: 1.167 + virtual int do_compare(const void* lhs, const void* rhs) const = 0; 1.168 + 1.169 + // take care of FBC... 1.170 + virtual void reservedSortedVectorImpl1(); 1.171 + virtual void reservedSortedVectorImpl2(); 1.172 + virtual void reservedSortedVectorImpl3(); 1.173 + virtual void reservedSortedVectorImpl4(); 1.174 + virtual void reservedSortedVectorImpl5(); 1.175 + virtual void reservedSortedVectorImpl6(); 1.176 + virtual void reservedSortedVectorImpl7(); 1.177 + virtual void reservedSortedVectorImpl8(); 1.178 + 1.179 +private: 1.180 + ssize_t _indexOrderOf(const void* item, size_t* order = 0) const; 1.181 + 1.182 + // these are made private, because they can't be used on a SortedVector 1.183 + // (they don't have an implementation either) 1.184 + ssize_t add(); 1.185 + void pop(); 1.186 + void push(); 1.187 + void push(const void* item); 1.188 + ssize_t insertVectorAt(const VectorImpl& vector, size_t index); 1.189 + ssize_t appendVector(const VectorImpl& vector); 1.190 + ssize_t insertAt(size_t where, size_t numItems = 1); 1.191 + ssize_t insertAt(const void* item, size_t where, size_t numItems = 1); 1.192 + ssize_t replaceAt(size_t index); 1.193 + ssize_t replaceAt(const void* item, size_t index); 1.194 +}; 1.195 + 1.196 +}; // namespace android 1.197 + 1.198 + 1.199 +// --------------------------------------------------------------------------- 1.200 + 1.201 +#endif // ANDROID_VECTOR_IMPL_H