• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  #include <utils/ByteOrder.h>
22  
23  namespace android {
24  
25  struct TypeVariant {
26      explicit TypeVariant(const ResTable_type* data);
27  
28      class iterator {
29      public:
30          iterator& operator=(const iterator& rhs) {
31              mTypeVariant = rhs.mTypeVariant;
32              mIndex = rhs.mIndex;
33              return *this;
34          }
35  
36          bool operator==(const iterator& rhs) const {
37              return mTypeVariant == rhs.mTypeVariant && mIndex == rhs.mIndex;
38          }
39  
40          bool operator!=(const iterator& rhs) const {
41              return mTypeVariant != rhs.mTypeVariant || mIndex != rhs.mIndex;
42          }
43  
44          iterator operator++(int) {
45              uint32_t prevIndex = mIndex;
46              operator++();
47              return iterator(mTypeVariant, prevIndex);
48          }
49  
50          const ResTable_entry* operator->() const {
51              return operator*();
52          }
53  
indexTypeVariant54          uint32_t index() const {
55              return mIndex;
56          }
57  
58          iterator& operator++();
59          const ResTable_entry* operator*() const;
60  
61      private:
62          friend struct TypeVariant;
iteratorTypeVariant63          iterator(const TypeVariant* tv, uint32_t index)
64              : mTypeVariant(tv), mIndex(index) {}
65          const TypeVariant* mTypeVariant;
66          uint32_t mIndex;
67      };
68  
beginEntriesTypeVariant69      iterator beginEntries() const {
70          return iterator(this, 0);
71      }
72  
endEntriesTypeVariant73      iterator endEntries() const {
74          return iterator(this, mLength);
75      }
76  
77      const ResTable_type* data;
78  
79  private:
80      size_t mLength;
81  };
82  
83  } // namespace android
84  
85  #endif // __TYPE_WRAPPERS_H
86