bool FileHDF5::deleteSection(const std::string &name_or_id) { bool deleted = false; // call deleteSection on sections to trigger recursive call to all sub-sections if (hasSection(name_or_id)) { // get instance of section about to get deleted Section section = getSection(name_or_id); // loop through all child sections and call deleteSection on them for(auto &child : section.sections()) { section.deleteSection(child.id()); } // if hasSection is true then section_group always exists deleted = metadata.removeAllLinks(section.name()); } return deleted; }
/** * Load the ".INI" file from the given input stream. * @param in stream to read file from. * @return Created INI file. * @throw Exception For any error (IO or format). */ File *File::load(io::InStream *in) throw (Exception) { File *file = new File(); Section *sect = file->defaultSection(); io::BufferedInStream bufin(*in); io::Input input(bufin); try { // read all lines int num = 1; while(true) { // read the line bool ended = false; string line; while(true) { line = line + input.scanLine(); num++; if(!line) { ended = true; break; } while(line[line.length() - 1] == '\n' || line[line.length() - 1] == '\r') line = line.substring(0, line.length() - 1); if(line[line.length() - 1] != '\\') break; line = line.substring(0, line.length() - 1); } if(ended) break; // empty line? if(!line) continue; // is it a comment? if(line[0] == ';') continue; // is it a section? if(line[0] == '[') { if(line[line.length() - 1] != ']') throw Exception(_ << num << ": malformed section name"); sect = new Section(line.substring(1, line.length() - 2)); file->sects.put(sect->name(), sect); continue; } // is it a key/value pair? int p = line.indexOf('='); if(p >= 0) { sect->values.put(line.substring(0, p), line.substring(p + 1)); continue; } // syntax error? throw Exception(_ << num << ": garbage here"); } } catch(io::IOException& e) { delete file; throw Exception(e.message()); } return file; }
bool Configfile::deserialize(std::ifstream & fd) { Section * section = NULL; /* default selection! */ if (!select(§ion)) { _errors.push_back("default selection has failed!"); return false; } size_t count = 0; while (fd.good()) { std::string str; /* read one line! */ std::getline(fd, str); size_t lst = str.size() - 1; if (str.size() >= 1 && str[lst] == '\r') //cuida das quebras de linha do tipo \r\n { str.erase(lst,1); --lst; } /* empty line! */ if (str.size() == 0) continue; /* comment! */ if (str[0] == '#') continue; ++count; if (str[0] == '[' && str[lst] == ']') { str.erase(0,1); --lst; str.erase(lst,1); --lst; if (!select(§ion, str)) { _errors.push_back(STG(FMT("erroneous section '%s'") % str)); /* ignore this section */ section = NULL; continue; } } else { std::string::size_type pos = str.find('='); if (pos == std::string::npos) { _errors.push_back(STG(FMT("erroneous separator '%s'") % str)); continue; }; if (section == NULL) { _errors.push_back(STG(FMT("no section for option '%s'") % str)); continue; } std::string opt(str.substr(0,pos)); std::string val(str.substr(pos+1)); if (_ignores.find(opt) != _ignores.end()) continue; if (val == "@") val = ""; if (adjust(section, opt, val)) continue; _errors.push_back(STG(FMT("option '%s' does " "not exist or '%s' is not a valid value (at section '%s')") % opt % val % section->name())); } } // retorna 'true' se arquivo tinha alguma coisa valida. return (count != 0); }