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_SPLIT_TABLESPLITTER_H
18#define AAPT_SPLIT_TABLESPLITTER_H
19
20#include <set>
21#include <vector>
22#include "android-base/macros.h"
23
24#include "ConfigDescription.h"
25#include "ResourceTable.h"
26#include "filter/ConfigFilter.h"
27#include "process/IResourceTableConsumer.h"
28
29namespace aapt {
30
31struct SplitConstraints {
32  std::set<ConfigDescription> configs;
33};
34
35struct TableSplitterOptions {
36  /**
37   * The preferred densities to keep in the table, stripping out all others.
38   * If empty, no stripping is done.
39   */
40  std::vector<uint16_t> preferred_densities;
41
42  /**
43   * Configuration filter that determines which resource configuration values
44   * end up in the final table.
45   */
46  IConfigFilter* config_filter = nullptr;
47};
48
49class TableSplitter {
50 public:
51  TableSplitter(const std::vector<SplitConstraints>& splits,
52                const TableSplitterOptions& options)
53      : split_constraints_(splits), options_(options) {
54    for (size_t i = 0; i < split_constraints_.size(); i++) {
55      splits_.push_back(util::make_unique<ResourceTable>());
56    }
57  }
58
59  bool VerifySplitConstraints(IAaptContext* context);
60
61  void SplitTable(ResourceTable* original_table);
62
63  std::vector<std::unique_ptr<ResourceTable>>& splits() { return splits_; }
64
65 private:
66  std::vector<SplitConstraints> split_constraints_;
67  std::vector<std::unique_ptr<ResourceTable>> splits_;
68  TableSplitterOptions options_;
69
70  DISALLOW_COPY_AND_ASSIGN(TableSplitter);
71};
72}
73
74#endif /* AAPT_SPLIT_TABLESPLITTER_H */
75