void GProfile::ExecuteAllNotifications() { if (!m_pTreeNotify) // this can only happen if you DetatchNotification() return; GListIterator itSections(&m_lstSections); while ( itSections() ) { GProfileSection *pSection = (GProfileSection *)itSections++; GListIterator itNVP(&pSection->m_lstNVP); while (itNVP()) { GProfileEntry *pNVP = (GProfileEntry *)itNVP++; GString strKey(pSection->m_strName); strKey << pNVP->m_strName; strKey.MakeUpper(); fnChangeNotify fn = (fnChangeNotify)m_pTreeNotify->search(strKey); if (fn) { fn(pSection->m_strName, pNVP->m_strName, pNVP->m_strValue); } } } }
// Serialize memory config // Returns the number of bytes written to the destination on success or 0 for failure. long GProfile::WriteCurrentConfigHelper(const char *pzPathAndFileName, GString *pDest, const char *pzSection/*=0*/, bool bWriteXML/*=0*/) { GString strLocalDest; GString *strConfigData = (pDest) ? pDest : &strLocalDest; try { if (bWriteXML) { *strConfigData << "<configuration>"; } GListIterator itSections(&m_lstSections); while ( itSections() ) { GProfileSection *pSection = (GProfileSection *)itSections++; if (pzSection) { if( pSection->m_strName.CompareNoCase(pzSection) != 0) { continue; } } if (bWriteXML) { pSection->ToXML(strConfigData, 1); } else { (*strConfigData) << "[" << pSection->m_strName << "]\r\n"; GListIterator itNVP(&pSection->m_lstNVP); while (itNVP()) { GProfileEntry *pNVP = (GProfileEntry *)itNVP++; (*strConfigData) << pNVP->m_strName << "=" << pNVP->m_strValue << "\r\n"; } if (itSections()) (*strConfigData) << "\r\n\r\n"; } } if (bWriteXML) { *strConfigData << "\r\n</configuration>"; } if (pzPathAndFileName) strConfigData->ToFile(pzPathAndFileName); return (long)strConfigData->Length(); } catch(GException &) { // most likely due to invalid path or file name. return 0; } return 0; // can't get here }
GProfile::NameValuePair *GProfile::FindKey(const char *szKey, GProfile::Section *pSection) { NameValuePair *pRet = 0; if (pSection) { GListIterator itNVP(&pSection->m_lstNVP); while ((itNVP()) && (!pRet)) { NameValuePair *pNVP = (NameValuePair *)itNVP++; if (pNVP->m_strName.CompareNoCase(szKey) == 0) pRet = pNVP; } } return pRet; }
void GProfile::AddSection(GProfileSection *pS, int bIssueChangeNotification/*=1*/) { if (pS) { m_lstSections.AddLast(pS); // issue a ChangeNotification for each entry in this section if (bIssueChangeNotification) { GListIterator itNVP(&pS->m_lstNVP); while ( itNVP() ) { GProfileEntry *pNVP = (GProfileEntry *)itNVP++; ChangeNotify(pS->m_strName, pNVP->m_strName, pNVP->m_strValue); } } } }
void GProfile::Destroy() { GListIterator itSections(&m_lstSections); while (itSections()) { Section *pSection = (Section *)itSections++; GListIterator itNVP(&pSection->m_lstNVP); while (itNVP()) { NameValuePair *pNVP = (NameValuePair *)itNVP++; delete pNVP; } delete pSection; } m_lstSections.RemoveAll(); }
bool GProfile::RemoveEntry(const char *szSectionName, const char *szEntry) { GProfileSection *pSection = FindSection(szSectionName); if (pSection) { GListIterator itNVP(&pSection->m_lstNVP); while (itNVP()) { GProfileEntry *pNVP = (GProfileEntry *)itNVP++; if (pNVP->m_strName.CompareNoCase(szEntry) == 0) { pSection->m_lstNVP.Remove(pNVP); ChangeNotify(szSectionName, szEntry, ""); return 1; } } } return 0; }
void GProfile::Destroy() { GListIterator itSections(&m_lstSections); while (itSections()) { GProfileSection *pSection = (GProfileSection *)itSections++; GListIterator itNVP(&pSection->m_lstNVP); while (itNVP()) { GProfileEntry *pNVP = (GProfileEntry *)itNVP++; delete pNVP; } delete pSection; } m_lstSections.RemoveAll(); }