75 lines
1.6 KiB
C
75 lines
1.6 KiB
C
|
#pragma once
|
||
|
|
||
|
template<class mapKey, class mapValue>
|
||
|
mapValue* getMapValue(std::map<mapKey, mapValue>& mmapData, const mapKey& key, bool bNew)
|
||
|
{
|
||
|
mapValue *pRe = 0;
|
||
|
|
||
|
//std::map<mapKey, mapValue>::iterator it = mmapData.find(key); //pj
|
||
|
auto it = mmapData.find(key);
|
||
|
if (it != mmapData.end())
|
||
|
{
|
||
|
pRe = &it->second;
|
||
|
}
|
||
|
else if(bNew)
|
||
|
{
|
||
|
mapValue valueD;
|
||
|
mmapData[key] = valueD;
|
||
|
|
||
|
pRe = getMapValue(mmapData, key, false);
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
template<class mapKey1, class mapKey2, class mapValue>
|
||
|
mapValue* getMapValue(std::map<mapKey1, std::map<mapKey2, mapValue> >& mmapData, const mapKey1& key1, const mapKey2& key2, bool bNew)
|
||
|
{
|
||
|
mapValue *pRe2 = 0;
|
||
|
|
||
|
{
|
||
|
std::map<mapKey2, mapValue> *pRe1 = getMapValue<mapKey1, std::map<mapKey2, mapValue> >(mmapData, key1, bNew);
|
||
|
|
||
|
if (pRe1)
|
||
|
{
|
||
|
pRe2 = getMapValue<mapKey2, mapValue >(*pRe1, key2, bNew);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return pRe2;
|
||
|
}
|
||
|
|
||
|
|
||
|
template<class mapKey, class mapValue>
|
||
|
const mapValue* getMapValue_Const(std::map<mapKey, mapValue>& mmapData, mapKey key)
|
||
|
{
|
||
|
const mapValue *pRe = 0;
|
||
|
|
||
|
//std::map<mapKey, mapValue>::const_iterator it = mmapData.find(key);
|
||
|
auto it = mmapData.find(key); //pj
|
||
|
if (it != mmapData.end())
|
||
|
{
|
||
|
pRe = &it->second;
|
||
|
}
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
template<class mapKey1, class mapKey2, class mapValue>
|
||
|
const mapValue* getMapValue_Const(std::map<mapKey1, std::map<mapKey2, mapValue> >& mmapData, mapKey1 key1, mapKey2 key2)
|
||
|
{
|
||
|
const mapValue *pRe2 = 0;
|
||
|
|
||
|
{
|
||
|
const std::map<mapKey2, mapValue> *pRe1 = getMapValue_Const<mapKey1, std::map<mapKey2, mapValue> >(mmapData, key1);
|
||
|
|
||
|
if (pRe1)
|
||
|
{
|
||
|
pRe2 = getMapValue_Const<mapKey2, mapValue >(*pRe1, key2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return pRe2;
|
||
|
}
|