D
David student
Guest
Hi
Based on the requirement, I need to use a function from the static library into different files of my application.
For this, I am changing the normal function to a static function.
Could someone please help me what I need to consider before changing:
I am changing like as shown below:
- Adding static keyword before the function only in the .h file like as shown below
- Adding static keyword before the other functions those are using in this function like as shown below
- When calling the function, using class instead of using member variable
MlEMR.h file
static bool LogEvent(const mcwstring& strName, const mcwstring& strLabel, const mcwstring& strCategory, const mcwstring& strAction, std::map<mcwstring, mcwstring>& mapEventData);
MlEMR.cpp file
bool MlEMR::LogEvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData)
{
return MlMillinnium::LogEMREvent(strName, strLabel, strCategory, strAction, mapEventData);
}
MlMillinnium.h file
static bool LogEMREvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData);
MlMillinniumLogger m_EMRLogger;
MlMillinnium.cpp file
bool MlMillinnium::LogEMREvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData)
{
//return m_EMRLogger.SendMillinniumEvent(strName, strLabel, strCategory, strAction, mapEventData);
// Changing it like as shown below:
return MlMillinniumLogger::SendMillinniumEvent(strName, strLabel, strCategory, strAction, mapEventData);
}
MlMillinniumLogger.h file
class MlMillinniumLogger
{
public:
static bool SendMillinniumEvent(const mcwstring& strName, const mcwstring& strLabel, const mcwstring& strCategory, const mcwstring& strAction, const std::map<mcwstring, mcwstring>& mapEventData);
};
MlMillinniumLogger.cpp file
bool MlMillinniumLogger::SendMillinniumEvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, const std::map<std::wstring, std::wstring>& mapEventData)
{
if (strName.empty())
{
return false;
}
EMR::Logs::CEvent &event = EMR::Logs::CTrack::Event(strName);
event.Label(strLabel);
event.Category(strCategory);
event.Action(strAction);
for (auto it = mapEventData.begin(); it != mapEventData.end(); ++it)
{
event.Add(it->first, it->second);
}
event.Finish();
return true;
}
Continue reading...
Based on the requirement, I need to use a function from the static library into different files of my application.
For this, I am changing the normal function to a static function.
Could someone please help me what I need to consider before changing:
I am changing like as shown below:
- Adding static keyword before the function only in the .h file like as shown below
- Adding static keyword before the other functions those are using in this function like as shown below
- When calling the function, using class instead of using member variable
MlEMR.h file
static bool LogEvent(const mcwstring& strName, const mcwstring& strLabel, const mcwstring& strCategory, const mcwstring& strAction, std::map<mcwstring, mcwstring>& mapEventData);
MlEMR.cpp file
bool MlEMR::LogEvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData)
{
return MlMillinnium::LogEMREvent(strName, strLabel, strCategory, strAction, mapEventData);
}
MlMillinnium.h file
static bool LogEMREvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData);
MlMillinniumLogger m_EMRLogger;
MlMillinnium.cpp file
bool MlMillinnium::LogEMREvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, std::map<std::wstring, std::wstring>& mapEventData)
{
//return m_EMRLogger.SendMillinniumEvent(strName, strLabel, strCategory, strAction, mapEventData);
// Changing it like as shown below:
return MlMillinniumLogger::SendMillinniumEvent(strName, strLabel, strCategory, strAction, mapEventData);
}
MlMillinniumLogger.h file
class MlMillinniumLogger
{
public:
static bool SendMillinniumEvent(const mcwstring& strName, const mcwstring& strLabel, const mcwstring& strCategory, const mcwstring& strAction, const std::map<mcwstring, mcwstring>& mapEventData);
};
MlMillinniumLogger.cpp file
bool MlMillinniumLogger::SendMillinniumEvent(const std::wstring& strName, const std::wstring& strLabel, const std::wstring& strCategory, const std::wstring& strAction, const std::map<std::wstring, std::wstring>& mapEventData)
{
if (strName.empty())
{
return false;
}
EMR::Logs::CEvent &event = EMR::Logs::CTrack::Event(strName);
event.Label(strLabel);
event.Category(strCategory);
event.Action(strAction);
for (auto it = mapEventData.begin(); it != mapEventData.end(); ++it)
{
event.Add(it->first, it->second);
}
event.Finish();
return true;
}
Continue reading...