blob: e1575410e38b9fa6a2e3332de2e1a851bfd0422c [file] [log] [blame]
Adam Lesinskide7de472014-11-03 12:03:08 -08001/*
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 AAPT_SYMBOL_H
18#define AAPT_SYMBOL_H
19
20#include <utils/String8.h>
21#include <utils/String16.h>
22
23#include "ConfigDescription.h"
24#include "SourcePos.h"
25
26/**
27 * A resource symbol, not attached to any configuration or context.
28 */
29struct Symbol {
30 inline Symbol();
31 inline Symbol(const android::String16& p, const android::String16& t, const android::String16& n, uint32_t i);
32 inline android::String8 toString() const;
33 inline bool operator<(const Symbol& rhs) const;
34
35 android::String16 package;
36 android::String16 type;
37 android::String16 name;
38 uint32_t id;
39
40};
41
42/**
43 * A specific defintion of a symbol, defined with a configuration and a definition site.
44 */
45struct SymbolDefinition {
46 inline SymbolDefinition();
47 inline SymbolDefinition(const Symbol& s, const ConfigDescription& c, const SourcePos& src);
48 inline bool operator<(const SymbolDefinition& rhs) const;
49
50 Symbol symbol;
51 ConfigDescription config;
52 SourcePos source;
53};
54
55//
56// Implementations
57//
58
59Symbol::Symbol() {
60}
61
62Symbol::Symbol(const android::String16& p, const android::String16& t, const android::String16& n, uint32_t i)
63 : package(p)
64 , type(t)
65 , name(n)
66 , id(i) {
67}
68
69android::String8 Symbol::toString() const {
70 return android::String8::format("%s:%s/%s (0x%08x)",
71 android::String8(package).string(),
72 android::String8(type).string(),
73 android::String8(name).string(),
74 (int) id);
75}
76
77bool Symbol::operator<(const Symbol& rhs) const {
78 return (package < rhs.package) || (type < rhs.type) || (name < rhs.name) || (id < rhs.id);
79}
80
81SymbolDefinition::SymbolDefinition() {
82}
83
84SymbolDefinition::SymbolDefinition(const Symbol& s, const ConfigDescription& c, const SourcePos& src)
85 : symbol(s)
86 , config(c)
87 , source(src) {
88}
89
90bool SymbolDefinition::operator<(const SymbolDefinition& rhs) const {
91 return (symbol < rhs.symbol) || (config < rhs.config) || (source < rhs.source);
92}
93
94#endif // AAPT_SYMBOL_H
95