Using a hidden global pointer for functions
This is an example of a coding practice to avoid. There is a global pointer to an object CFGmap which is used by the functions in this cpp file to avoid the need to pass the pointer to this object when the function calls are made:
CFGmap* pComponentMap;
void TRNCdashboardInit(CFGmap* pMap){
COL_FUNCTION(TRNCdashboardInit);
pComponentMap = pMap;
COLvar File;
FILserializeLoadConfig(&File, CDIRcacheDir(CDIRsubDir::ROOT), "ComponentState.json");
COLmap<COLstring, CFGconfig>& Map = pComponentMap->nodeConfigMap();
COLmap<COLstring, CFGconfig>::iterator it;;
for(it = Map.begin(); it != Map.end(); it++){
COL_VAR(it->first);
it->second.m_ErrorCount = File[it->first]["error_count"];
it->second.m_QueueCount = File[it->first]["queue_count"];
}
}
void TRNCdashboardSaveCounts(){
COL_FUNCTION(TRNCdashboardSaveCounts);
COLvar ToSave;
const COLmap<COLstring, CFGconfig>& Map = pComponentMap->nodeConfigMap();
COLmap<COLstring, CFGconfig>::const_iterator it;;
for(it = Map.cbegin(); it != Map.cend(); it++){
COL_VAR(it->first);
ToSave[it->first]["error_count"] = it->second.m_ErrorCount;
ToSave[it->first]["queue_count"] = it->second.m_QueueCount;
}
COL_TRC(ToSave);
FILserializeSaveConfig(ToSave, CDIRcacheDir(CDIRsubDir::ROOT), "ComponentState.json");
}
void TRNCdashboardIncrementErrorCount (const COLstring& ComponentGuid, int Count){
COL_FUNCTION(TRNCdashboardIncrementErrorCount);
CFGconfig* pNode = pComponentMap->node(ComponentGuid);
if(pNode) { pNode->m_ErrorCount = pNode->m_ErrorCount + Count; }
}
What makes this less than ideal?