// return vector with all section names in it vector<string> CSunParser::GetSectionList(string location) { transform(location.begin(), location.end(), location.begin(), (int (*)(int)) tolower); vector<string> loclist = GetLocationVector(location); vector<string> returnvec; map<string, SSection*>* sectionsptr = §ions; if (loclist[0].compare("") != 0) { string searchpath; for (unsigned int i = 0; i < loclist.size(); i++) { searchpath += loclist[i]; if (sectionsptr->find(loclist[i]) == sectionsptr->end()) { return returnvec; } sectionsptr = §ionsptr->find(loclist[i])->second->sections; searchpath += '\\'; } } map<string,SSection*>::iterator it; for (it = sectionsptr->begin(); it != sectionsptr->end(); it++) { returnvec.push_back(it->first); transform(returnvec.back().begin(), returnvec.back().end(), returnvec.back().begin(), (int (*)(int)) tolower); } return returnvec; }
//return vector with all section names in it std::vector<std::string> TdfParser::GetSectionList(std::string const& location){ std::string lowerd = location; std::transform(lowerd.begin(), lowerd.end(), lowerd.begin(), static_cast<int (*)(int)>(std::tolower)); std::vector<std::string> loclist = GetLocationVector(lowerd); std::vector<std::string> returnvec; std::map<std::string,TdfSection*> *sectionsptr = &root_section.sections; if(loclist[0].compare("")!=0) { std::string searchpath;// = loclist[0]; for(unsigned int i=0; i<loclist.size(); i++){ searchpath += loclist[i]; if(sectionsptr->find(loclist[i]) == sectionsptr->end()){ // handleerror(hWnd, ("Section " + searchpath + " missing in file " + filename).c_str(), "Sun parsing error", MBF_OK); // info->AddLine ("Section " + searchpath + " missing in file " + filename); return returnvec; } sectionsptr = §ionsptr->find(loclist[i])->second->sections; searchpath += '\\'; } } std::map<std::string,TdfSection*>::iterator it; for(it=sectionsptr->begin(); it!=sectionsptr->end(); it++){ returnvec.push_back(it->first); std::transform(returnvec.back().begin(), returnvec.back().end(), returnvec.back().begin(), (int (*)(int))std::tolower); } return returnvec; }
//return a map with all values in section const map<string, string> CSunParser::GetAllValues(string location) { transform(location.begin(), location.end(), location.begin(), (int (*)(int)) tolower); map<string, string> emptymap; string searchpath; vector<string> loclist = GetLocationVector(location); if (sections.find(loclist[0]) == sections.end()) { return emptymap; } SSection* sectionptr = sections[loclist[0]]; searchpath = loclist[0]; for (unsigned int i = 1; i < loclist.size(); i++) { searchpath += '\\'; searchpath += loclist[i]; if (sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()) { return emptymap; } sectionptr = sectionptr->sections[loclist[i]]; } return sectionptr->values; }
//return a map with all values in section const map<string, string> CSunParser::GetAllValues(string location) { ////L("CSunParser::GetAllValues(" << location << ")" << endl); transform(location.begin(), location.end(), location.begin(), (int (*)(int))tolower); map<string, string> emptymap; string searchpath; //for errormessages vector<string> loclist = GetLocationVector(location); if(sections.find(loclist[0]) == sections.end()) { // MessageBox(hWnd, ("Section " + loclist[0] + " missing in file " + filename).c_str(), "Sun parsing error", MB_OK); ////L("Sun Parsing Error: Section " << loclist[0] << " missing in file " << filename << endl); return emptymap; } SSection *sectionptr = sections[loclist[0]]; searchpath = loclist[0]; for(unsigned int i=1; i<loclist.size(); i++) { searchpath += '\\'; searchpath += loclist[i]; if(sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()) { // MessageBox(hWnd, ("Section " + searchpath + " missing in file " + filename).c_str(), "Sun parsing error", MB_OK); ////L("Sun Parsing Error: Section " << searchpath << " missing in file " << filename << endl); return emptymap; } sectionptr = sectionptr->sections[loclist[i]]; } return sectionptr->values; }
//return a map with all values in section const std::map<std::string, std::string> TdfParser::GetAllValues(std::string const& location){ std::string lowerd = location; std::transform(lowerd.begin(), lowerd.end(), lowerd.begin(), static_cast<int (*)(int)>(std::tolower)); std::map<std::string, std::string> emptymap; std::string searchpath; //for errormessages std::vector<std::string> loclist = GetLocationVector(lowerd); if(root_section.sections.find(loclist[0]) == root_section.sections.end()){ // handleerror(hWnd, ("Section " + loclist[0] + " missing in file " + filename).c_str(), "Sun parsing error", MBF_OK); // info->AddLine ("Section " + loclist[0] + " missing in file " + filename); return emptymap; } TdfSection *sectionptr = root_section.sections[loclist[0]]; searchpath = loclist[0]; for(unsigned int i=1; i<loclist.size(); i++){ searchpath += '\\'; searchpath += loclist[i]; if(sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()){ // handleerror(hWnd, ("Section " + searchpath + " missing in file " + filename).c_str(), "Sun parsing error", MBF_OK); //info->AddLine ("Section " + searchpath + " missing in file " + filename); return emptymap; } sectionptr = sectionptr->sections[loclist[i]]; } return sectionptr->values; }
//finds a value in the file , if not found returns false, and errormessages is returned in value //location of value is sent as a string "section\section\value" bool TdfParser::SGetValue(std::string &value, std::string const& location){ std::string lowerd = location; std::transform(lowerd.begin(), lowerd.end(), lowerd.begin(), static_cast<int (*)(int)>(std::tolower)); std::string searchpath; //for errormessages //split the location string std::vector<std::string> loclist = GetLocationVector(lowerd); if(root_section.sections.find(loclist[0]) == root_section.sections.end()){ value = ""; //G->L.print("Section " + loclist[0] + " missing in file " + filename); return false; } TdfSection *sectionptr = root_section.sections[loclist[0]]; searchpath = loclist[0]; for(unsigned int i=1; i<loclist.size()-1; i++){ //const char *arg = loclist[i].c_str(); searchpath += '\\'; searchpath += loclist[i]; if(sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()){ value = ""; //G->L.print("Section " + searchpath + " missing in file " + filename); return false; } sectionptr = sectionptr->sections[loclist[i]]; } searchpath += '\\'; searchpath += loclist[loclist.size()-1]; if(sectionptr->values.find(loclist[loclist.size()-1]) == sectionptr->values.end()){ value = "Value " + searchpath + " missing in file " + filename; return false; } std::string svalue = sectionptr->values[loclist[loclist.size()-1]]; value = svalue; return true; }
bool TdfParser::SectionExist(std::string const& location){ std::string lowerd = location; std::transform(lowerd.begin(), lowerd.end(), lowerd.begin(), static_cast<int (*)(int)>(std::tolower)); std::vector<std::string> loclist = GetLocationVector(lowerd); if(root_section.sections.find(loclist[0]) == root_section.sections.end()){ return false; } TdfSection *sectionptr = root_section.sections[loclist[0]]; for(unsigned int i=1; i<loclist.size(); i++){ if(sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()){ return false; } sectionptr = sectionptr->sections[loclist[i]]; } return true; }
//finds a value in the file , if not found returns false, and errormessages is returned in value //location of value is sent as a string "section\section\value" bool CSunParser::SGetValue(string &value, string location) { ////L("CSunParser::SGetValue(" << value << ", " << location << ")" << endl); transform(location.begin(), location.end(), location.begin(), (int (*)(int))tolower); string searchpath; //for errormessages //split the location string vector<string> loclist = GetLocationVector(location); if(sections.find(loclist[0]) == sections.end()) { value = "Section " + loclist[0] + " missing in file " + filename; return false; } SSection *sectionptr = sections[loclist[0]]; searchpath = loclist[0]; for(unsigned int i=1; i<loclist.size()-1; i++) { //const char *arg = loclist[i].c_str(); searchpath += '\\'; searchpath += loclist[i]; if(sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()) { value = "Section " + searchpath + " missing in file " + filename; return false; } sectionptr = sectionptr->sections[loclist[i]]; } searchpath += '\\'; searchpath += loclist[loclist.size()-1]; if(sectionptr->values.find(loclist[loclist.size()-1]) == sectionptr->values.end()) { value = "Value " + searchpath + " missing in file " + filename; return false; } string svalue = sectionptr->values[loclist[loclist.size()-1]]; value = svalue; return true; }
bool CSunParser::SectionExist(string location) { transform(location.begin(), location.end(), location.begin(), (int (*)(int)) tolower); vector<string> loclist = GetLocationVector(location); if (sections.find(loclist[0]) == sections.end()) { return false; } SSection* sectionptr = sections[loclist[0]]; for (unsigned int i = 1; i < loclist.size(); i++) { if (sectionptr->sections.find(loclist[i]) == sectionptr->sections.end()) { return false; } sectionptr = sectionptr->sections[loclist[i]]; } return true; }
//return vector with all section names in it vector<string> CSunParser::GetSectionList(string location) { ////L("CSunParser::GetSectionList(" << location << ")" << endl); transform(location.begin(), location.end(), location.begin(), (int (*)(int))tolower); vector<string> loclist = GetLocationVector(location); vector<string> returnvec; map<string,SSection*> *sectionsptr = §ions; if(loclist[0].compare("")!=0) { string searchpath;// = loclist[0]; for(unsigned int i=0; i<loclist.size(); i++) { searchpath += loclist[i]; if(sectionsptr->find(loclist[i]) == sectionsptr->end()) { // MessageBox(hWnd, ("Section " + searchpath + " missing in file " + filename).c_str(), "Sun parsing error", MB_OK); ////L("Sun Parsing Error: Section " << searchpath << " missing in file " << filename << endl); return returnvec; } sectionsptr = §ionsptr->find(loclist[i])->second->sections; searchpath += '\\'; } } map<string,SSection*>::iterator it; for(it=sectionsptr->begin(); it!=sectionsptr->end(); it++) { returnvec.push_back(it->first); transform(returnvec.back().begin(), returnvec.back().end(), returnvec.back().begin(), (int (*)(int))tolower); } return returnvec; }
bool TdfParser::SGetValue(std::string &value, std::string const& location) const { std::string lowerd = StringToLower(location); std::string searchpath; // for error-messages // split the location string const std::vector<std::string>& loclist = GetLocationVector(lowerd); sectionsMap_t::const_iterator sit = root_section.sections.find(loclist[0]); if (sit == root_section.sections.end()) { value = "Section " + loclist[0] + " missing in file " + filename; return false; } TdfSection* sectionptr = sit->second; searchpath = loclist[0]; for (unsigned int i=1; i < loclist.size()-1; ++i) { //const char *arg = loclist[i].c_str(); searchpath += '\\'; searchpath += loclist[i]; sit = sectionptr->sections.find(loclist[i]); if (sit == sectionptr->sections.end()) { value = "Section " + searchpath + " missing in file " + filename; return false; } sectionptr = sit->second; } searchpath += '\\'; searchpath += loclist[loclist.size()-1]; valueMap_t::const_iterator vit = sectionptr->values.find(loclist[loclist.size()-1]); if (vit == sectionptr->values.end()) { value = "Value " + searchpath + " missing in file " + filename; return false; } std::string svalue = vit->second; value = svalue; return true; }