1 /* 2 * Copyright (C) 2014 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 __TYPE_WRAPPERS_H 18 #define __TYPE_WRAPPERS_H 19 20 #include <androidfw/ResourceTypes.h> 21 22 namespace android { 23 24 struct TypeVariant { 25 TypeVariant(const ResTable_type* data) 26 : data(data) {} 27 28 class iterator { 29 public: 30 iterator& operator=(const iterator& rhs) { 31 mTypeVariant = rhs.mTypeVariant; 32 mIndex = rhs.mIndex; 33 } 34 35 bool operator==(const iterator& rhs) const { 36 return mTypeVariant == rhs.mTypeVariant && mIndex == rhs.mIndex; 37 } 38 39 bool operator!=(const iterator& rhs) const { 40 return mTypeVariant != rhs.mTypeVariant || mIndex != rhs.mIndex; 41 } 42 43 iterator operator++(int) { 44 uint32_t prevIndex = mIndex; 45 operator++(); 46 return iterator(mTypeVariant, prevIndex); 47 } 48 49 const ResTable_entry* operator->() const { 50 return operator*(); 51 } 52 53 uint32_t index() const { 54 return mIndex; 55 } 56 57 iterator& operator++(); 58 const ResTable_entry* operator*() const; 59 60 private: 61 friend struct TypeVariant; 62 iterator(const TypeVariant* tv, uint32_t index) 63 : mTypeVariant(tv), mIndex(index) {} 64 const TypeVariant* mTypeVariant; 65 uint32_t mIndex; 66 }; 67 68 iterator beginEntries() const { 69 return iterator(this, 0); 70 } 71 72 iterator endEntries() const { 73 return iterator(this, dtohl(data->entryCount)); 74 } 75 76 const ResTable_type* data; 77 }; 78 79 } // namespace android 80 81 #endif // __TYPE_WRAPPERS_H 82