1f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski/* 2f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * Copyright (C) 2014 The Android Open Source Project 3f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * 4f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 5f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * you may not use this file except in compliance with the License. 6f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * You may obtain a copy of the License at 7f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * 8f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 9f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * 10f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * Unless required by applicable law or agreed to in writing, software 11f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 12f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * See the License for the specific language governing permissions and 14f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski * limitations under the License. 15f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski */ 16f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 17f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski#ifndef __TYPE_WRAPPERS_H 18f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski#define __TYPE_WRAPPERS_H 19f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 20f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski#include <androidfw/ResourceTypes.h> 21f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 22f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinskinamespace android { 23f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 24f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinskistruct TypeVariant { 25f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski TypeVariant(const ResTable_type* data) 26f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski : data(data) {} 27f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 28f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski class iterator { 29f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski public: 30f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator& operator=(const iterator& rhs) { 31f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski mTypeVariant = rhs.mTypeVariant; 32f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski mIndex = rhs.mIndex; 33f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 34f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 35f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski bool operator==(const iterator& rhs) const { 36f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return mTypeVariant == rhs.mTypeVariant && mIndex == rhs.mIndex; 37f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 38f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 39f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski bool operator!=(const iterator& rhs) const { 40f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return mTypeVariant != rhs.mTypeVariant || mIndex != rhs.mIndex; 41f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 42f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 43f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator operator++(int) { 44f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski uint32_t prevIndex = mIndex; 45f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski operator++(); 46f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return iterator(mTypeVariant, prevIndex); 47f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 48f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 49f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski const ResTable_entry* operator->() const { 50f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return operator*(); 51f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 52f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 53f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski uint32_t index() const { 54f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return mIndex; 55f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 56f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 57f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator& operator++(); 58f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski const ResTable_entry* operator*() const; 59f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 60f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski private: 61f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski friend struct TypeVariant; 62f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator(const TypeVariant* tv, uint32_t index) 63f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski : mTypeVariant(tv), mIndex(index) {} 64f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski const TypeVariant* mTypeVariant; 65f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski uint32_t mIndex; 66f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski }; 67f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 68f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator beginEntries() const { 69f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return iterator(this, 0); 70f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 71f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 72f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski iterator endEntries() const { 73f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski return iterator(this, dtohl(data->entryCount)); 74f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski } 75f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 76f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski const ResTable_type* data; 77f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski}; 78f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 79f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski} // namespace android 80f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski 81f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski#endif // __TYPE_WRAPPERS_H 82