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