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_QUATRAMAP_H 17 #define SRC_TRACE_BASE_QUATRAMAP_H 18 19 #include "triple_map.h" 20 21 template <class T1, class T2, class T3, class T4, class T5> 22 class QuatraMap { 23 public: QuatraMap(T5 invalidValue)24 QuatraMap(T5 invalidValue) 25 { 26 invalidValue_ = invalidValue; 27 } SetInvalidRet(T5 invalidValue)28 void SetInvalidRet(T5 invalidValue) 29 { 30 invalidValue_ = invalidValue; 31 } Insert(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5)32 void Insert(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) 33 { 34 auto streamIdHookidMap = internalMap_.find(t1); 35 if (streamIdHookidMap != internalMap_.end()) { 36 (*streamIdHookidMap).second.Insert(t2, t3, t4, t5); 37 } else { 38 TripleMap<T2, T3, T4, T5> mm(invalidValue_); 39 mm.Insert(t2, t3, t4, t5); 40 internalMap_.emplace(std::make_pair(t1, mm)); 41 } 42 } Find(T1 t1,T2 t2,T3 t3,T4 t4)43 T5 Find(T1 t1, T2 t2, T3 t3, T4 t4) 44 { 45 auto streamIdHookidMap = internalMap_.find(t1); 46 if (streamIdHookidMap != internalMap_.end()) { 47 return (*streamIdHookidMap).second.Find(t2, t3, t4); 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 MAP_ERASE_WITH_QUATRA_PARME(T1, T2, T3, T4) 56 void Clear() 57 { 58 internalMap_.clear(); 59 } 60 61 private: 62 std::map<T1, TripleMap<T2, T3, T4, T5>> internalMap_; 63 T5 invalidValue_; 64 }; 65 66 #endif // SRC_TRACE_BASE_QUATRAMAP_H 67