FontLanguageListCache.h revision 6c4c098cbd37eccef483ab1986127250b4d2ddf2
1/*
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 MINIKIN_FONT_LANGUAGE_LIST_CACHE_H
18#define MINIKIN_FONT_LANGUAGE_LIST_CACHE_H
19
20#include <unordered_map>
21
22#include <minikin/FontFamily.h>
23
24namespace android {
25
26class FontLanguageListCache {
27public:
28    // A special ID for the empty language list.
29    // This value must be 0 since the empty language list is inserted into mLanguageLists by
30    // default.
31    const static uint32_t kEmptyListId = 0;
32
33    // Returns language list ID for the given string representation of FontLanguages.
34    // Caller should acquire a lock before calling the method.
35    static uint32_t getId(const std::string& languages);
36
37    // Caller should acquire a lock before calling the method.
38    static const FontLanguages& getById(uint32_t id);
39
40private:
41    FontLanguageListCache() {}  // Singleton
42    ~FontLanguageListCache() {}
43
44    // Caller should acquire a lock before calling the method.
45    static FontLanguageListCache* getInstance();
46
47    std::vector<FontLanguages> mLanguageLists;
48
49    // A map from string representation of the font language list to the ID.
50    std::unordered_map<std::string, uint32_t> mLanguageListLookupTable;
51};
52
53}  // namespace android
54
55#endif  // MINIKIN_FONT_LANGUAGE_LIST_CACHE_H
56