16f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski/*
26f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Copyright (C) 2015 The Android Open Source Project
36f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
46f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
56f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * you may not use this file except in compliance with the License.
66f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * You may obtain a copy of the License at
76f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
86f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
96f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
106f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Unless required by applicable law or agreed to in writing, software
116f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
126f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * See the License for the specific language governing permissions and
146f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * limitations under the License.
156f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski */
166f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
176f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include "Resource.h"
181ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include "util/StringPiece.h"
196f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
206f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include <map>
216f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include <string>
226f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
236f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskinamespace aapt {
246f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
256f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiStringPiece16 toString(ResourceType type) {
266f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    switch (type) {
276f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kAnim:          return u"anim";
286f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kAnimator:      return u"animator";
296f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kArray:         return u"array";
306f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kAttr:          return u"attr";
311ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski        case ResourceType::kAttrPrivate:   return u"^attr-private";
326f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kBool:          return u"bool";
336f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kColor:         return u"color";
346f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kDimen:         return u"dimen";
356f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kDrawable:      return u"drawable";
366f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kFraction:      return u"fraction";
376f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kId:            return u"id";
386f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kInteger:       return u"integer";
396f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kInterpolator:  return u"interpolator";
406f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kLayout:        return u"layout";
416f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kMenu:          return u"menu";
426f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kMipmap:        return u"mipmap";
436f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kPlurals:       return u"plurals";
446f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kRaw:           return u"raw";
456f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kString:        return u"string";
466f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kStyle:         return u"style";
476f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kStyleable:     return u"styleable";
486f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kTransition:    return u"transition";
496f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case ResourceType::kXml:           return u"xml";
506f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
516f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return {};
526f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
536f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
546f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskistatic const std::map<StringPiece16, ResourceType> sResourceTypeMap {
556f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"anim", ResourceType::kAnim },
566f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"animator", ResourceType::kAnimator },
576f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"array", ResourceType::kArray },
586f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"attr", ResourceType::kAttr },
596f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"^attr-private", ResourceType::kAttrPrivate },
606f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"bool", ResourceType::kBool },
616f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"color", ResourceType::kColor },
626f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"dimen", ResourceType::kDimen },
636f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"drawable", ResourceType::kDrawable },
646f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"fraction", ResourceType::kFraction },
656f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"id", ResourceType::kId },
666f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"integer", ResourceType::kInteger },
676f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"interpolator", ResourceType::kInterpolator },
686f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"layout", ResourceType::kLayout },
696f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"menu", ResourceType::kMenu },
706f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"mipmap", ResourceType::kMipmap },
716f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"plurals", ResourceType::kPlurals },
726f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"raw", ResourceType::kRaw },
736f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"string", ResourceType::kString },
746f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"style", ResourceType::kStyle },
756f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"styleable", ResourceType::kStyleable },
766f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"transition", ResourceType::kTransition },
776f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        { u"xml", ResourceType::kXml },
786f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski};
796f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
806f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskiconst ResourceType* parseResourceType(const StringPiece16& str) {
816f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    auto iter = sResourceTypeMap.find(str);
826f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (iter == std::end(sResourceTypeMap)) {
836f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        return nullptr;
846f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
856f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return &iter->second;
866f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
876f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
88a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinskibool operator<(const ResourceKey& a, const ResourceKey& b) {
89a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski    return std::tie(a.name, a.config) < std::tie(b.name, b.config);
90a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski}
91a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski
92a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinskibool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b) {
93a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski    return std::tie(a.name, a.config) < std::tie(b.name, b.config);
94a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski}
95a6fe345be955368a13aea76aefb4db821aad11dfAdam Lesinski
966f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski} // namespace aapt
97