• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 SRC_TRACE_BASE_TRIPLEMAP_H
17 #define SRC_TRACE_BASE_TRIPLEMAP_H
18 
19 #include "double_map.h"
20 
21 template <class T1, class T2, class T3, class T4>
22 class TripleMap {
23 public:
TripleMap(T4 invalidValue)24     TripleMap(T4 invalidValue)
25     {
26         invalidValue_ = invalidValue;
27     }
SetInvalidRet(T4 invalidValue)28     void SetInvalidRet(T4 invalidValue)
29     {
30         invalidValue_ = invalidValue;
31     }
Insert(T1 t1,T2 t2,T3 t3,T4 t4)32     void Insert(T1 t1, T2 t2, T3 t3, T4 t4)
33     {
34         auto streamIdHookidMap = internalMap_.find(t1);
35         if (streamIdHookidMap != internalMap_.end()) {
36             (*streamIdHookidMap).second.Insert(t2, t3, t4);
37         } else {
38             DoubleMap<T2, T3, T4> mm(invalidValue_);
39             mm.Insert(t2, t3, t4);
40             internalMap_.emplace(std::make_pair(t1, mm));
41         }
42     }
Find(T1 t1,T2 t2,T3 t3)43     T4 Find(T1 t1, T2 t2, T3 t3)
44     {
45         auto streamIdHookidMap = internalMap_.find(t1);
46         if (streamIdHookidMap != internalMap_.end()) {
47             return (*streamIdHookidMap).second.Find(t2, t3);
48         } else {
49             return invalidValue_;
50         }
51     }
52     MAP_ERASE_WITH_SINGLE_PARME(T1)
MAP_ERASE_WITH_DOUBLE_PARME(T1,T2)53     MAP_ERASE_WITH_DOUBLE_PARME(T1, T2)
54     MAP_ERASE_WITH_TRIPLE_PARME(T1, T2, T3)
55     void Clear()
56     {
57         internalMap_.clear();
58     }
59 
60 private:
61     std::map<T1, DoubleMap<T2, T3, T4>> internalMap_;
62     T4 invalidValue_;
63 };
64 
65 #endif // SRC_TRACE_BASE_TRIPLEMAP_H
66