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>
21ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski#include <utils/ByteOrder.h>
22f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
23f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinskinamespace android {
24f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
25f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinskistruct TypeVariant {
26c8f71aa67ea599cb80205496cb67e9e7a121299cAdam Lesinski    TypeVariant(const ResTable_type* 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;
33f6113af2d6f6eebee68d3ac510fe96d38a7a39e9John Reck            return *this;
34f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
35f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
36f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        bool operator==(const iterator& rhs) const {
37f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            return mTypeVariant == rhs.mTypeVariant && mIndex == rhs.mIndex;
38f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
39f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
40f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        bool operator!=(const iterator& rhs) const {
41f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            return mTypeVariant != rhs.mTypeVariant || mIndex != rhs.mIndex;
42f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
43f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
44f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        iterator operator++(int) {
45f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            uint32_t prevIndex = mIndex;
46f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            operator++();
47f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            return iterator(mTypeVariant, prevIndex);
48f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
49f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
50f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        const ResTable_entry* operator->() const {
51f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            return operator*();
52f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
53f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
54f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        uint32_t index() const {
55f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            return mIndex;
56f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        }
57f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
58f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        iterator& operator++();
59f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        const ResTable_entry* operator*() const;
60f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
61f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    private:
62f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        friend struct TypeVariant;
63f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        iterator(const TypeVariant* tv, uint32_t index)
64f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski            : mTypeVariant(tv), mIndex(index) {}
65f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        const TypeVariant* mTypeVariant;
66f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        uint32_t mIndex;
67f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    };
68f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
69f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    iterator beginEntries() const {
70f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski        return iterator(this, 0);
71f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    }
72f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
73f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    iterator endEntries() const {
74c8f71aa67ea599cb80205496cb67e9e7a121299cAdam Lesinski        return iterator(this, mLength);
75f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    }
76f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
77f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski    const ResTable_type* data;
78c8f71aa67ea599cb80205496cb67e9e7a121299cAdam Lesinski
79c8f71aa67ea599cb80205496cb67e9e7a121299cAdam Lesinskiprivate:
80c8f71aa67ea599cb80205496cb67e9e7a121299cAdam Lesinski    size_t mLength;
81f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski};
82f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
83f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski} // namespace android
84f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski
85f90f2f8dc36e7243b85e0b6a7fd5a590893c827eAdam Lesinski#endif // __TYPE_WRAPPERS_H
86