• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 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     }
Erase(T1 t1)52     void Erase(T1 t1)
53     {
54         auto streamIdHookidMap = internalMap_.find(t1);
55         if (streamIdHookidMap != internalMap_.end()) {
56             internalMap_.erase(streamIdHookidMap);
57         }
58     }
Erase(T1 t1,T2 t2)59     void Erase(T1 t1, T2 t2)
60     {
61         auto streamIdHookidMap = internalMap_.find(t1);
62         if (streamIdHookidMap != internalMap_.end()) {
63             (*streamIdHookidMap).second.Erase(t2);
64         }
65     }
Erase(T1 t1,T2 t2,T3 t3)66     void Erase(T1 t1, T2 t2, T3 t3)
67     {
68         auto streamIdHookidMap = internalMap_.find(t1);
69         if (streamIdHookidMap != internalMap_.end()) {
70             (*streamIdHookidMap).second.Erase(t2, t3);
71         }
72     }
Clear()73     void Clear()
74     {
75         internalMap_.clear();
76     }
77 
78 private:
79     std::map<T1, DoubleMap<T2, T3, T4>> internalMap_;
80     T4 invalidValue_;
81 };
82 
83 #endif // SRC_TRACE_BASE_TRIPLEMAP_H
84