blob: 6858c624fc80877d254a358793e656a3493c8150 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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_CONFIG_DESCRIPTION_H
18#define AAPT_CONFIG_DESCRIPTION_H
19
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020#include "util/StringPiece.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080021
22#include <androidfw/ResourceTypes.h>
23#include <ostream>
24
25namespace aapt {
26
27/*
28 * Subclass of ResTable_config that adds convenient
29 * initialization and comparison methods.
30 */
31struct ConfigDescription : public android::ResTable_config {
Adam Lesinski52364f72016-01-11 13:10:24 -080032 /**
33 * Returns an immutable default config.
34 */
35 static const ConfigDescription& defaultConfig();
36
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080037 /*
38 * Parse a string of the form 'fr-sw600dp-land' and fill in the
39 * given ResTable_config with resulting configuration parameters.
40 *
41 * The resulting configuration has the appropriate sdkVersion defined
42 * for backwards compatibility.
43 */
44 static bool parse(const StringPiece& str, ConfigDescription* out = nullptr);
45
46 /**
47 * If the configuration uses an axis that was added after
48 * the original Android release, make sure the SDK version
49 * is set accordingly.
50 */
51 static void applyVersionForCompatibility(ConfigDescription* config);
52
53 ConfigDescription();
Chih-Hung Hsieh9b8528f2016-08-10 14:15:30 -070054 ConfigDescription(const android::ResTable_config& o); // NOLINT(implicit)
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080055 ConfigDescription(const ConfigDescription& o);
56 ConfigDescription(ConfigDescription&& o);
57
58 ConfigDescription& operator=(const android::ResTable_config& o);
59 ConfigDescription& operator=(const ConfigDescription& o);
60 ConfigDescription& operator=(ConfigDescription&& o);
61
62 bool operator<(const ConfigDescription& o) const;
63 bool operator<=(const ConfigDescription& o) const;
64 bool operator==(const ConfigDescription& o) const;
65 bool operator!=(const ConfigDescription& o) const;
66 bool operator>=(const ConfigDescription& o) const;
67 bool operator>(const ConfigDescription& o) const;
Adam Lesinski87675ad2016-07-15 17:03:03 -070068
69 ConfigDescription copyWithoutSdkVersion() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080070};
71
72inline ConfigDescription::ConfigDescription() {
73 memset(this, 0, sizeof(*this));
74 size = sizeof(android::ResTable_config);
75}
76
77inline ConfigDescription::ConfigDescription(const android::ResTable_config& o) {
78 *static_cast<android::ResTable_config*>(this) = o;
79 size = sizeof(android::ResTable_config);
80}
81
82inline ConfigDescription::ConfigDescription(const ConfigDescription& o) {
83 *static_cast<android::ResTable_config*>(this) = o;
84}
85
86inline ConfigDescription::ConfigDescription(ConfigDescription&& o) {
87 *this = o;
88}
89
90inline ConfigDescription& ConfigDescription::operator=(const android::ResTable_config& o) {
91 *static_cast<android::ResTable_config*>(this) = o;
92 size = sizeof(android::ResTable_config);
93 return *this;
94}
95
96inline ConfigDescription& ConfigDescription::operator=(const ConfigDescription& o) {
97 *static_cast<android::ResTable_config*>(this) = o;
98 return *this;
99}
100
101inline ConfigDescription& ConfigDescription::operator=(ConfigDescription&& o) {
102 *this = o;
103 return *this;
104}
105
106inline bool ConfigDescription::operator<(const ConfigDescription& o) const {
107 return compare(o) < 0;
108}
109
110inline bool ConfigDescription::operator<=(const ConfigDescription& o) const {
111 return compare(o) <= 0;
112}
113
114inline bool ConfigDescription::operator==(const ConfigDescription& o) const {
115 return compare(o) == 0;
116}
117
118inline bool ConfigDescription::operator!=(const ConfigDescription& o) const {
119 return compare(o) != 0;
120}
121
122inline bool ConfigDescription::operator>=(const ConfigDescription& o) const {
123 return compare(o) >= 0;
124}
125
126inline bool ConfigDescription::operator>(const ConfigDescription& o) const {
127 return compare(o) > 0;
128}
129
130inline ::std::ostream& operator<<(::std::ostream& out, const ConfigDescription& o) {
131 return out << o.toString().string();
132}
133
134} // namespace aapt
135
136#endif // AAPT_CONFIG_DESCRIPTION_H