• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _PANDA_TYPE_SORT_HPP
17 #define _PANDA_TYPE_SORT_HPP
18 
19 #include "runtime/include/mem/panda_containers.h"
20 #include "runtime/include/mem/panda_string.h"
21 
22 namespace panda::verifier {
23 using SortIdx = size_t;
24 
25 class SortNames {
26 public:
SortNames(const PandaString & bot,const PandaString & top)27     SortNames(const PandaString &bot, const PandaString &top)
28     {
29         operator[](bot);
30         operator[](top);
31     }
32     DEFAULT_COPY_SEMANTIC(SortNames);
33     DEFAULT_MOVE_SEMANTIC(SortNames);
34 
35     ~SortNames() = default;
36 
37     const PandaString &operator[](SortIdx sort) const
38     {
39         return SortToName_[sort];
40     }
41 
42     SortIdx operator[](const PandaString &name)
43     {
44         auto s = NameToSort_.find(name);
45         if (s != NameToSort_.end()) {
46             return s->second;
47         }
48         SortIdx sort = SortToName_.size();
49         SortToName_.push_back(name);
50         NameToSort_[name] = sort;
51         return sort;
52     }
53 
54 private:
55     PandaUnorderedMap<PandaString, SortIdx> NameToSort_;
56     PandaVector<PandaString> SortToName_;
57 };
58 }  // namespace panda::verifier
59 
60 #endif  // !_PANDA_TYPE_SORT_HPP
61