From 8b52a31ed2c299b759f330c4f976b9c70f5765f4 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 24 Jun 2015 14:03:29 +0300 Subject: first version --- src/common/cgen_map.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 src/common/cgen_map.h (limited to 'src/common/cgen_map.h') diff --git a/src/common/cgen_map.h b/src/common/cgen_map.h new file mode 100755 index 00000000..e224df4b --- /dev/null +++ b/src/common/cgen_map.h @@ -0,0 +1,96 @@ +#ifndef C_GEN_MAP +#define C_GEN_MAP +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +#include +#include +#include + +template +class CGenericMap { +public: + typedef std::map > gen_map_t; + typename gen_map_t::iterator gen_map_iter_t; + typedef void (free_map_object_func_t)(VAL *p); + + + bool Create(void){ + return(true); + } + void Delete(){ + //remove_all(); + } + VAL * remove(KEY key ){ + VAL *lp = lookup(key); + if ( lp ) { + m_map.erase(key); + return (lp); + }else{ + return(0); + } + } + + + void remove_no_lookup(KEY key ){ + m_map.erase(key); + } + + + VAL * lookup(KEY key ){ + typename gen_map_t::iterator iter; + iter = m_map.find(key); + if (iter != m_map.end() ) { + return ( (*iter).second ); + }else{ + return (( VAL*)0); + } + } + void add(KEY key,VAL * val){ + m_map.insert(typename gen_map_t::value_type(key,val)); + } + + + void remove_all(free_map_object_func_t func){ + if ( m_map.empty() ) + return; + + typename gen_map_t::iterator it; + for (it= m_map.begin(); it != m_map.end(); ++it) { + VAL *lp = it->second; + func(lp); + } + m_map.clear(); + } + + void dump_all(FILE *fd){ + typename gen_map_t::iterator it; + for (it= m_map.begin(); it != m_map.end(); ++it) { + VAL *lp = it->second; + lp->Dump(fd); + } + } + + uint64_t count(void){ + return ( m_map.size()); + } + +public: + gen_map_t m_map; +}; + +#endif -- cgit 1.2.3-korg