Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / sksl / SkSLBuiltinMap.cpp
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 #include "src/sksl/SkSLBuiltinMap.h"
9
10 #include "include/core/SkTypes.h"
11 #include "include/private/SkSLProgramElement.h"
12
13 #include <utility>
14
15 namespace SkSL {
16
17 void BuiltinMap::insertOrDie(std::string key, std::unique_ptr<ProgramElement> element) {
18     SkASSERT(!fElements.find(key));
19     fElements.set(std::move(key), BuiltinElement{std::move(element), /*fAlreadyIncluded=*/false});
20 }
21
22 const ProgramElement* BuiltinMap::find(const std::string& key) {
23     BuiltinElement* elem = fElements.find(key);
24     if (!elem) {
25         return fParent ? fParent->find(key) : nullptr;
26     }
27     return elem->fElement.get();
28 }
29
30 // Only returns a builtin element that isn't already marked as included, and then marks it.
31 const ProgramElement* BuiltinMap::findAndInclude(const std::string& key) {
32     BuiltinElement* elem = fElements.find(key);
33     if (!elem) {
34         return fParent ? fParent->findAndInclude(key) : nullptr;
35     }
36     if (elem->fAlreadyIncluded) {
37         return nullptr;
38     }
39     elem->fAlreadyIncluded = true;
40     return elem->fElement.get();
41 }
42
43 void BuiltinMap::resetAlreadyIncluded() {
44     fElements.foreach([](const std::string&, BuiltinElement* elem) {
45         elem->fAlreadyIncluded = false;
46     });
47     if (fParent) {
48         fParent->resetAlreadyIncluded();
49     }
50 }
51
52 void BuiltinMap::foreach(
53         const std::function<void(const std::string&, const ProgramElement&)>& fn) const {
54     fElements.foreach([&](const std::string& name, const BuiltinElement& elem) {
55         fn(name, *elem.fElement);
56     });
57     if (fParent) {
58         fParent->foreach(fn);
59     }
60 }
61
62 } // namespace SkSL