//
// Created by Ht on 2019/12/26.
//

#ifndef LIBDEVCPP_QCOMMONUTIL_H
#define LIBDEVCPP_QCOMMONUTIL_H


namespace qlibc {

#define FIND_IN_MAP(map, key) \
    ((map).find(key) != (map).end())


#define PUT_IN_MAP(map, key, val, valType) \
    (map).insert(std::pair<std::string, valType>(key,val))

#define MAP_RELEASE(map,key) \
    (map).erase((key))

#define GET_FROM_PMAP( map, key, pvar) \
    auto __##pvar##_it = (map).find(key); \
    auto pvar = (( __##pvar##_it == (map).end())?nullptr:__##pvar##_it->second)

#define GETVAL_FROM_PMAP( map, key, pvar, def) \
    auto __##pvar##_it = (map).find(key); \
    auto pvar = (( __##pvar##_it == (map).end())?def:__##pvar##_it->second)

#define GET_FROM_RMAP( map, key, pvar) \
    auto __##var##_it = (map).find(key); \
    auto* pvar = (( __##var##_it == (map).end())?nullptr:&__##var##_it->second)

#define GET_FROM_PMAP_DEF( map, key, var, def) \
    auto __##var##_it = (map).find(key); \
    auto var = (( __##var##_it == (map).end())?(def):__##var##_it->second)

#define CLEAR_PMAP(map) \
    for(auto __##map##_itor : map) { \
        delete __##map##_itor->second;\
    } \
    map.clear();

#define STR_OF_BOOL(var) \
    ((var)?"true":"false")

#define TREEBASE_OF_PATH(key, pathKey)\
    ""
#define NODE_OF_PATH(key,pathKey)\
    (key)


#define VECTOR_REMOVE(vec, val) \
    (vec).erase(remove((vec).begin(), (vec).end(), (val)), (vec).end())

}


#endif //LIBDEVCPP_QCOMMONUTIL_H
