1/*
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
20#include "ConfigDescription.h"
21
22#include <set>
23#include <utility>
24
25namespace aapt {
26
27/**
28 * Matches ConfigDescriptions based on some pattern.
29 */
30class IConfigFilter {
31public:
32    virtual ~IConfigFilter() = default;
33
34    /**
35     * Returns true if the filter matches the configuration, false otherwise.
36     */
37    virtual bool match(const ConfigDescription& config) const = 0;
38};
39
40/**
41 * Implements config axis matching. An axis is one component of a configuration, like screen
42 * density or locale. If an axis is specified in the filter, and the axis is specified in
43 * the configuration to match, they must be compatible. Otherwise the configuration to match is
44 * accepted.
45 *
46 * Used when handling "-c" options.
47 */
48class AxisConfigFilter : public IConfigFilter {
49public:
50    void addConfig(ConfigDescription config);
51
52    bool match(const ConfigDescription& config) const override;
53
54private:
55    std::set<std::pair<ConfigDescription, uint32_t>> mConfigs;
56    uint32_t mConfigMask = 0;
57};
58
59} // namespace aapt
60
61#endif /* AAPT_FILTER_CONFIGFILTER_H */
62