How to write a generic function to insert elements into the map container using C++?

  • Thread starter Thread starter bhavya internship
  • Start date Start date
B

bhavya internship

Guest
Hello All,

I am inserting elements into the map container. For this I am using the same statements multiple times in the below function. Is there any way I can write a generic function for this? So that even at the later point of time, when required, I can insert new elements.

bool EMRMgr::GetParams()
{
EmIOStruct emIOstructObj;
WCHAR szValue[MAX_PATH] = { 0 };
DWORD dwDataSize = sizeof(szValue) / sizeof(WCHAR);
long lRes = 0;
McStorageType mcStorageTypeObj = McStorageType::eRegistry;
std::wstring value;

// First time I am using the below statements to insert elements into the map container
mcIOstructObj.lpszValueName = (LPWSTR)ER_ID;
memset(szValue, 0, MAX_PATH);
mcIOstructObj.lpData = (LPBYTE)&szValue[0];
lRes = m_cIOManager.ReadValue(mcStorageTypeObj, mcIOstructObj);
value.clear();
if ((LPWSTR)mcIOstructObj.lpData == nullptr)
{
value.assign(L"");
}
else
{
value.assign((LPWSTR)mcIOstructObj.lpData);
}

m_fileParams.insert({ (std::wstring) ER_ID, value });

// Second time I am using the below statements to insert elements into the map container


mcIOstructObj.lpszValueName = (LPWSTR)CPS;
memset(szValue, 0, MAX_PATH);
mcIOstructObj.lpData = (LPBYTE)&szValue[0];
lRes = m_cIOManager.ReadValue(mcStorageTypeObj, mcIOstructObj);
value.clear();
if ((LPWSTR)mcIOstructObj.lpData == nullptr)
{
value.assign(L"");
}
else
{
value.assign((LPWSTR)mcIOstructObj.lpData);
}
m_fileParams.insert({ (std::wstring) CPS, value });

return true;
}

could anyone please help me on this?

Thanks in advance.

Continue reading...
 
Back
Top