blob: ebb81519dcebd5439bf6bc264e8f4d8925ebc36d [file] [log] [blame]
Adam Lesinski6a008172016-02-02 17:02:58 -08001/*
2 * Copyright (C) 2016 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_FILTER_CONFIGFILTER_H
18#define AAPT_FILTER_CONFIGFILTER_H
19
Adam Lesinski6a008172016-02-02 17:02:58 -080020#include <set>
21#include <utility>
22
Adam Lesinskice5e56e2016-10-21 17:56:45 -070023#include "ConfigDescription.h"
24
Adam Lesinski6a008172016-02-02 17:02:58 -080025namespace aapt {
26
27/**
28 * Matches ConfigDescriptions based on some pattern.
29 */
30class IConfigFilter {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070031 public:
32 virtual ~IConfigFilter() = default;
Adam Lesinski6a008172016-02-02 17:02:58 -080033
Adam Lesinskicacb28f2016-10-19 12:18:14 -070034 /**
35 * Returns true if the filter matches the configuration, false otherwise.
36 */
Adam Lesinskice5e56e2016-10-21 17:56:45 -070037 virtual bool Match(const ConfigDescription& config) const = 0;
Adam Lesinski6a008172016-02-02 17:02:58 -080038};
39
40/**
Shane Farmer0a5b2012017-06-22 12:24:12 -070041 * Implements config axis matching. An axis is one component of a configuration, like screen density
42 * or locale. If an axis is specified in the filter, and the axis is specified in the configuration
43 * to match, they must be compatible. Otherwise the configuration to match is accepted.
Adam Lesinski6a008172016-02-02 17:02:58 -080044 *
45 * Used when handling "-c" options.
46 */
47class AxisConfigFilter : public IConfigFilter {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070048 public:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070049 void AddConfig(ConfigDescription config);
Adam Lesinski6a008172016-02-02 17:02:58 -080050
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 bool Match(const ConfigDescription& config) const override;
Adam Lesinski6a008172016-02-02 17:02:58 -080052
Adam Lesinskicacb28f2016-10-19 12:18:14 -070053 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054 std::set<std::pair<ConfigDescription, uint32_t>> configs_;
55 uint32_t config_mask_ = 0;
Adam Lesinski6a008172016-02-02 17:02:58 -080056};
57
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058} // namespace aapt
Adam Lesinski6a008172016-02-02 17:02:58 -080059
60#endif /* AAPT_FILTER_CONFIGFILTER_H */