epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkMemberInfo.h" |
| 11 | |
| 12 | #if SK_USE_CONDENSED_INFO == 1 |
| 13 | |
| 14 | // SkCondensed.cpp is auto-generated |
| 15 | // To generate it, execute SkDisplayType::BuildCondensedInfo() |
| 16 | #ifdef SK_DEBUG |
| 17 | #include "SkCondensedDebug.cpp" |
| 18 | #else |
| 19 | #include "SkCondensedRelease.cpp" |
| 20 | #endif |
| 21 | |
| 22 | static int _searchByName(const unsigned char* lengths, int count, const char* strings, const char target[]) { |
| 23 | int lo = 0; |
| 24 | int hi = count - 1; |
| 25 | while (lo < hi) { |
| 26 | int mid = (hi + lo) >> 1; |
| 27 | if (strcmp(&strings[lengths[mid << 2]], target) < 0) |
| 28 | lo = mid + 1; |
| 29 | else |
| 30 | hi = mid; |
| 31 | } |
| 32 | if (strcmp(&strings[lengths[hi << 2]], target) != 0) |
| 33 | return -1; |
| 34 | return hi; |
| 35 | } |
| 36 | |
| 37 | static int _searchByType(SkDisplayTypes type) { |
| 38 | unsigned char match = (unsigned char) type; |
| 39 | int lo = 0; |
| 40 | int hi = kTypeIDs - 1; |
| 41 | while (lo < hi) { |
| 42 | int mid = (hi + lo) >> 1; |
| 43 | if (gTypeIDs[mid] < match) |
| 44 | lo = mid + 1; |
| 45 | else |
| 46 | hi = mid; |
| 47 | } |
| 48 | if (gTypeIDs[hi] != type) |
| 49 | return -1; |
| 50 | return hi; |
| 51 | } |
| 52 | |
| 53 | const SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* , SkDisplayTypes type, int* infoCountPtr) { |
| 54 | int lookup = _searchByType(type); |
| 55 | if (lookup < 0) |
| 56 | return NULL; |
| 57 | if (infoCountPtr) |
| 58 | *infoCountPtr = gInfoCounts[lookup]; |
| 59 | return gInfoTables[lookup]; |
| 60 | } |
| 61 | |
| 62 | // !!! replace with inline |
| 63 | const SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* , SkDisplayTypes type, const char** matchPtr ) { |
| 64 | const SkMemberInfo* info = SkMemberInfo::Find(type, matchPtr); |
| 65 | SkASSERT(info); |
| 66 | return info; |
| 67 | } |
| 68 | |
| 69 | static const SkMemberInfo* _lookup(int lookup, const char** matchPtr) { |
| 70 | int count = gInfoCounts[lookup]; |
| 71 | const SkMemberInfo* info = gInfoTables[lookup]; |
| 72 | if (info->fType == SkType_BaseClassInfo) { |
| 73 | int baseTypeLookup = info->fOffset; |
| 74 | const SkMemberInfo* result = _lookup(baseTypeLookup, matchPtr); |
| 75 | if (result != NULL) |
| 76 | return result; |
| 77 | if (--count == 0) |
| 78 | return NULL; |
| 79 | info++; |
| 80 | } |
| 81 | SkASSERT(info->fType != SkType_BaseClassInfo); |
| 82 | const char* match = *matchPtr; |
| 83 | const char* strings = gInfoNames[lookup]; |
| 84 | int index = _searchByName(&info->fName, count, strings, match); |
| 85 | if (index < 0) |
| 86 | return NULL; |
| 87 | return &info[index]; |
| 88 | } |
| 89 | |
| 90 | const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, int* index) { |
| 91 | int count = gInfoCounts[lookup]; |
| 92 | const SkMemberInfo* info = gInfoTables[lookup]; |
| 93 | if (info->fType == SkType_BaseClassInfo) { |
| 94 | int baseTypeLookup = info->fOffset; |
| 95 | const SkMemberInfo* result = Find(baseTypeLookup, index); |
| 96 | if (result != NULL) |
| 97 | return result; |
| 98 | if (--count == 0) |
| 99 | return NULL; |
| 100 | info++; |
| 101 | } |
| 102 | SkASSERT(info->fType != SkType_BaseClassInfo); |
| 103 | if (*index >= count) { |
| 104 | *index -= count; |
| 105 | return NULL; |
| 106 | } |
| 107 | return &info[index]; |
| 108 | } |
| 109 | |
| 110 | const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, const char** matchPtr) { |
| 111 | int lookup = _searchByType(type); |
| 112 | SkASSERT(lookup >= 0); |
| 113 | return _lookup(lookup, matchPtr); |
| 114 | } |
| 115 | |
| 116 | const SkMemberInfo* SkMemberInfo::getInherited() const { |
| 117 | int baseTypeLookup = fOffset; |
| 118 | return gInfoTables[baseTypeLookup]; |
| 119 | } |
| 120 | |
| 121 | #endif |
| 122 | |