• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SKSL_BUILTINMAP
9 #define SKSL_BUILTINMAP
10 
11 #include "include/private/SkSLString.h"
12 
13 #include <memory>
14 #include <unordered_map>
15 
16 namespace SkSL {
17 
18 class ProgramElement;
19 
20 /**
21  * Represents the builtin elements in the Context.
22  */
23 class BuiltinMap {
24 public:
BuiltinMap(BuiltinMap * parent)25     BuiltinMap(BuiltinMap* parent) : fParent(parent) {}
26 
27     void insertOrDie(std::string key, std::unique_ptr<ProgramElement> element);
28 
29     const ProgramElement* find(const std::string& key);
30 
31     const ProgramElement* findAndInclude(const std::string& key);
32 
33     void resetAlreadyIncluded();
34 
35 private:
36     struct BuiltinElement {
37         std::unique_ptr<ProgramElement> fElement;
38         bool fAlreadyIncluded = false;
39     };
40 
41     std::unordered_map<std::string, BuiltinElement> fElements;
42     BuiltinMap* fParent = nullptr;
43 };
44 
45 } // namespace SkSL
46 
47 #endif
48