String File::find(const String& filename, StringList directories) { String filename_new = filename; // empty string cannot be found, so throw Exception. // The code below would return success on empty string, since a path is prepended and thus the location exists if (filename_new.trim().empty()) throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename); //add data dir in OpenMS data path directories.push_back(getOpenMSDataPath()); //add path suffix to all specified directories String path = File::path(filename); if (path != "") { for (StringList::iterator it = directories.begin(); it != directories.end(); ++it) { it->ensureLastChar('/'); *it += path; } filename_new = File::basename(filename); } //look up file for (StringList::const_iterator it = directories.begin(); it != directories.end(); ++it) { String loc = *it; loc.ensureLastChar('/'); loc = loc + filename_new; if (exists(loc)) { return String(QDir::cleanPath(loc.toQString())); } } //if the file was not found, throw an exception throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename); //this is never reached, but needs to be there to avoid compiler warnings return ""; }
String ID3v2::Tag::genre() const { // TODO: In the next major version (TagLib 2.0) a list of multiple genres // should be separated by " / " instead of " ". For the moment to keep // the behavior the same as released versions it is being left with " ". if(d->frameListMap["TCON"].isEmpty() || !dynamic_cast<TextIdentificationFrame *>(d->frameListMap["TCON"].front())) { return String(); } // ID3v2.4 lists genres as the fields in its frames field list. If the field // is simply a number it can be assumed that it is an ID3v1 genre number. // Here was assume that if an ID3v1 string is present that it should be // appended to the genre string. Multiple fields will be appended as the // string is built. TextIdentificationFrame *f = static_cast<TextIdentificationFrame *>( d->frameListMap["TCON"].front()); StringList fields = f->fieldList(); StringList genres; for(StringList::Iterator it = fields.begin(); it != fields.end(); ++it) { if((*it).isEmpty()) continue; bool ok; int number = (*it).toInt(&ok); if(ok && number >= 0 && number <= 255) { *it = ID3v1::genre(number); } if(std::find(genres.begin(), genres.end(), *it) == genres.end()) genres.append(*it); } return genres.toString(); }
bool AbstractFileManager::resolveRelativePath(const String& relativePath, const StringList& rootPaths, String& absolutePath) { StringList::const_iterator rootIt, rootEnd; for (rootIt = rootPaths.begin(), rootEnd = rootPaths.end(); rootIt != rootEnd; ++rootIt) { const String& rootPath = *rootIt; absolutePath = makeAbsolute(relativePath, rootPath); if (exists(absolutePath)) return true; } return false; }
// Unloads all loaded modules void ModuleFactory::unloadAll() { StringList modules = m_dependency.getSortedList(); std::for_each(modules.begin(), modules.end(), boost::bind(&ModuleFactory::unload, this, _1)); // clear dependencies m_dependency.clear(); // stop all left getScheduler()->stop(); }
StringList MessageEncodingRegistry::getCommonEncodings(const StringList& encodingList) const { /// Currently only one encoding available. StringList commonEncodingList; for (StringList::const_iterator i = encodingList.begin(); i != encodingList.end(); ++i) { if (*i == "TightBE1") commonEncodingList.push_back(*i); } return commonEncodingList; }
// Reads a folder and provides a list with filename from the // folder // @param[in] folder - the folder with files // @exception @ref Result const StringList Utils::getFiles(const std::string& folder, bool recursive) { DIR* dir = NULL; BOOST_ASSERT(Utils::fileExist(folder) == true); StringList res; dir = opendir(folder.c_str()); if (dir != NULL) { struct dirent* dir_info = NULL; // Process all files in the subdirectory while ((dir_info = readdir(dir))) { if ((strcmp(dir_info->d_name, ".") != 0) && (strcmp(dir_info->d_name, "..") != 0)) { std::string file_name = folder; file_name += "/"; file_name += dir_info->d_name; struct stat st; if (lstat(file_name.c_str(), &st) < 0) { klk_log(KLKLOG_ERROR, "Error %d in lstat(): %s", errno, strerror(errno)); KLKASSERT(0); continue; } // process only reg file if (S_ISREG(st.st_mode)) { res.push_back(file_name); } else if (S_ISDIR(st.st_mode) && recursive) { StringList files = getFiles(file_name, recursive); std::copy(files.begin(), files.end(), std::back_inserter(res)); } } } closedir(dir); } else { throw Exception(__FILE__, __LINE__, "Error %d in opendir() for %s: %s", errno, folder.c_str(), strerror(errno)); } return res; }
static inline bool stringListContain(StringList& strList, const string& str) { StringList::iterator iter = strList.begin(); for (; iter != strList.end(); iter++) { if (*iter == str) { return true; } } return false; }
// Converts a list to a string with items separated // by the specified separator const std::string Utils::convert2String(const StringList& list, const std::string& sep) { const std::string result = std::accumulate( list.begin(), list.end(), std::string(""), boost::bind<std::string>( StringListAccumulator(), _1, _2, sep)); return result; }
StringList UserTextIdentificationFrame::fieldList() const { StringList l = TextIdentificationFrame::fieldList(); if(!l.isEmpty()) { StringList::Iterator it = l.begin(); l.erase(it); } return l; }
void CCUtils::wipeExternal(StringList paths) { string internalStorage = getInternalStoragePath(); if(internalStorage[internalStorage.length() - 1] != '/') { internalStorage += "/"; } for(StringList::iterator iter = paths.begin(); iter != paths.end(); iter++) { string fullpath = internalStorage + (*iter); if(isPathExistent(fullpath)) { deleteFile(fullpath); } } }
void OutputStream::writeObjectFields( const osg::Object* obj ) { std::string name = obj->libraryName(); name += std::string("::") + obj->className(); ObjectWrapper* wrapper = Registry::instance()->getObjectWrapperManager()->findWrapper( name ); if ( !wrapper ) { OSG_WARN << "OutputStream::writeObject(): Unsupported wrapper class " << name << std::endl; return; } _fields.push_back( name ); const StringList& associates = wrapper->getAssociates(); for ( StringList::const_iterator itr=associates.begin(); itr!=associates.end(); ++itr ) { const std::string& assocName = *itr; ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName); if ( !assocWrapper ) { OSG_WARN << "OutputStream::writeObject(): Unsupported associated class " << assocName << std::endl; continue; } else if ( _useSchemaData ) { if ( _inbuiltSchemaMap.find(assocName)==_inbuiltSchemaMap.end() ) { StringList properties; assocWrapper->writeSchema( properties ); if ( properties.size()>0 ) { std::string propertiesString; for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) { propertiesString += *sitr; propertiesString += ' '; } _inbuiltSchemaMap[assocName] = propertiesString; } } } _fields.push_back( assocWrapper->getName() ); assocWrapper->write( *this, *obj ); if ( getException() ) return; _fields.pop_back(); } _fields.pop_back(); }
static int parseRelations() { depTable.clear(); confTable.clear(); char assistName[MAX_PATH]; sprintf(assistName, "%s\\%s\\%s", WtoA(getMiscPath(PATH_IPS)), BurnDrvGetTextA(DRV_NAME), "assistant.txt"); //parse ips dat and update the treewidget FILE* fp = fopen(assistName, "rt"); if (!fp) { return 1; } char s[1024]; char* p = NULL; string line; size_t nLen = 0; size_t pos = string::npos; while (!feof(fp)) { if (fgets(s, sizeof s, fp) != NULL) { p = s; // skip UTF-8 sig if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0) { p += strlen(UTF8_SIGNATURE); } if (p[0] == '#') { continue; // skip comment } getLine(p); line = p; pos = line.find(">"); if (pos != string::npos) { StringList depStrs = split2Str(line, ">"); string parent = *(depStrs.begin()); lowerString(parent); StringList children = stringSplit(depStrs.back(), ","); lowerTrimmed(children); depTable.insert(make_pair(parent, children)); } else { StringList conflicts = stringSplit(line, ","); lowerTrimmed(conflicts); confTable.push_back(conflicts); } } } return 0; }
int main () { // Create a list of critters. StringList critters; // Insert a few critters. critters.insert (critters.begin (), "antelope"); critters.insert (critters.begin (), "bear"); critters.insert (critters.begin (), "cat"); // Print out the list. std::cout << critters << '\n'; // Change cat to cougar. *std::find (critters.begin (),critters.end (), "cat") = "cougar"; std::cout << critters << '\n'; // Put a zebra at the beginning, an ocelot ahead of antelope, // and a rat at the end. critters.push_front ("zebra"); critters.insert (std::find (critters.begin (), critters.end (), "antelope"), "ocelot"); critters.push_back ("rat"); std::cout << critters << '\n'; // Sort the list (Use list's sort function since the // generic algorithm requires a random access iterator // and list only provides bidirectional) critters.sort (); std::cout << critters << '\n'; // Now let's erase half of the critters. StringList::size_type half = critters.size () / 2; for (StringList::size_type i = 0; i != half; ++i) critters.erase (critters.begin ()); std::cout << critters << '\n'; return 0; }
// Retrives list of possible completions for a n's parameter const cli::ParameterVector ScanStart::getCompletion(const cli::ParameterVector& setparams) { cli::ParameterVector res; if (setparams.empty()) { // possible source names IDevList list = getFactory()->getResources()->getResourceByType(dev::DVB_ALL); for (IDevList::iterator i = list.begin(); i != list.end(); i++) { const std::string source = (*i)->getStringParam(dev::SOURCE); if (!source.empty()) { const std::string source_name = dvb::Utils::getSourceName(getFactory(), source); if (std::find(res.begin(), res.end(), source_name) == res.end()) { res.push_back(source_name); } } } } else if (setparams.size() == 1) { IDevPtr dev = getDev(setparams[0]); // possible frequency table StringList list; if (dev->getStringParam(dev::TYPE) == dev::DVB_T) { list = base::Utils::getFiles(dir::SHARE + "/scan/dvb-t"); } else if (dev->getStringParam(dev::TYPE) == dev::DVB_S) { list = base::Utils::getFiles(dir::SHARE + "/scan/dvb-s"); } for (StringList::iterator i = list.begin(); i != list.end(); i++) { const std::string fname = base::Utils::getFileName(*i); if (std::find(res.begin(), res.end(), fname) == res.end()) { res.push_back(fname); } } } return res; }
void GetRocketRow( StringList &rocketRow, int row_index, const StringList& cols ) const { RowsList::const_iterator r_it = rows.begin(); std::advance( r_it, row_index ); if( r_it == rows.end() ) {; return; } const Row &row = *r_it; for( StringList::const_iterator it = cols.begin(); it != cols.end(); ++it ) { Row::const_iterator v = row.find( (*it).CString() ); rocketRow.push_back( v == row.end() ? "" : v->second.c_str() ); } }
int main (int argc, const char * argv[]) { // insert code here... StringList* tokens = BuildStringList(argv[1]); if (tokens) { for (StringList::const_iterator i=tokens->begin();i!=tokens->end();++i) { if (IsCppKeyword2(*i) != IsCppKeyword(*i) || IsCppKeyword3(*i, strlen(*i))!=IsCppKeyword(*i)) { std::cout << *i << " " << IsCppKeyword2(*i) << IsCppKeyword(*i) << IsCppKeyword3(*i, strlen(*i)) << endl; } } timespec time1, time2; GetTime(time1); int positives = 0; const int max_reps = 1000; for (int repeats = 0;repeats!=max_reps;repeats++) { for (StringList::const_iterator i=tokens->begin();i!=tokens->end();++i) { // if (IsCppKeyword(*i)) if (IsCppKeyword2(*i)) positives++; } } GetTime(time2); cout<<"found " << positives << " of " << tokens->size()*max_reps << endl; cout<<diff(time1,time2).tv_sec<<":"<<diff(time1,time2).tv_nsec<<endl; } // just let the OS sort out the memory leaks... return 0; }
string Slice::JsGenerator::getLocalScope(const string& scope, const string& separator) { assert(!scope.empty()); // // Remove trailing "::" if present. // string fixedScope; if(scope[scope.size() - 1] == ':') { assert(scope[scope.size() - 2] == ':'); fixedScope = scope.substr(0, scope.size() - 2); } else { fixedScope = scope; } if(fixedScope.empty()) { return ""; } const StringList ids = fixIds(splitScopedName(fixedScope)); // // Return local scope for "::A::B::C" as A.B.C // stringstream result; for(StringList::const_iterator i = ids.begin(); i != ids.end(); ++i) { if(i != ids.begin()) { result << separator; } result << *i; } return result.str(); }
void FileDialog::setFilter(const QString& filter) { StringList strs = StringUtil::tokenize(q2u(filter).c_str(), L'|'); m_filters.clear(); for (StringList::iterator it=strs.begin(); it!=strs.end(); ++it) { m_filters.push_back(u2q(*it)); } if (!m_filters.contains("*.*")) { m_filters.push_back("*.*"); } updateWidget(); }
void UserProfileHandler::cleanupUserProfileDirectories() { StringList userProfiles = getUserProfileNames(); StringList::iterator it; for (it = userProfiles.begin(); it != userProfiles.end(); it++) { if (String(*it).endsWith(".new") || String(*it).endsWith(".old")) { Config & config = ConfigManager::getInstance().getCurrentConfig(); File profileDirectory(File::convertPathSeparators(config.getConfigDir() + "profiles/") + (*it)); profileDirectory.remove(); } } }
bool Registry::StringListToValue(const StringList& list, ByteVector& value) { value.clear(); ByteVector::iterator out= value.begin(); for (StringList::const_iterator i= list.begin() ; i!=list.end() ; ++i) { value.reserve(value.size() + (*i).size()+1); copy((*i).begin(), (*i).end(), out); *out++= 0; } *out++= 0; return true; }
int main(int argc, char **argv) { StringList stringList; StringList::iterator pos; stringList.push_back(&a); stringList.push_back(&b); pos = stringList.begin(); stringList.insert(pos, &c); for (pos = stringList.begin(); pos != stringList.end(); ++pos) { cout << *pos << endl; string *s = *pos; cout << s->c_str() << (*pos)->c_str() << endl; } for (pos = stringList.begin(); pos != stringList.end(); ) { cout << *pos << endl; pos = stringList.erase(pos); } }
void LdapTools::readConfigurationSettings() { string base("ou=settings,ou=configuration,ou=virtualization,ou=services,"); base.append(Config::getInstance()->getLdapBaseDn()); SYSLOGLOGGER(logDEBUG) << "readConfigurationSettings " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } // SYSLOGLOGGER(logINFO) << std::endl; //retval->addAttribute(entry->getDN(), attr.getName(), value); if (string::npos != entry->getDN().find("ou=sound")) { if (0 == attr.getName().compare("sstAllowSound")) { Config::getInstance()->setAllowSound(0 == value.compare("TRUE")); } } else if (string::npos != entry->getDN().find("ou=spice")) { if (0 == attr.getName().compare("sstAllowSpice")) { Config::getInstance()->setAllowSpice(0 == value.compare("TRUE")); } else if (0 == attr.getName().compare("sstSpicePortMin")) { Config::getInstance()->setSpicePortMin(atoi(value.c_str())); } else if (0 == attr.getName().compare("sstSpicePortMax")) { Config::getInstance()->setSpicePortMax(atoi(value.c_str())); } } else if (string::npos != entry->getDN().find("ou=usb")) { if (0 == attr.getName().compare("sstAllowUSB")) { Config::getInstance()->setAllowUsb(0 == value.compare("TRUE")); } } } delete entry; entry = entries->getNext(); } } }
int main(){ LDAPConnection *lc=new LDAPConnection("192.168.3.128",389); std::cout << "----------------------doing bind...." << std::endl; try{ lc->bind("uid=admin,dc=home,dc=local" , "secret"); std::cout << lc->getHost() << std::endl; StringList tmp; tmp.add("subschemasubentry"); LDAPSearchResults* entries = lc->search("", LDAPConnection::SEARCH_BASE, "(objectClass=*)", tmp ); LDAPEntry* rootDse = entries->getNext(); std::string schemabase="cn=subschema"; if(rootDse){ const LDAPAttribute* schemaAttr = rootDse->getAttributes()->getAttributeByName("subschemaSubentry"); schemabase = *(schemaAttr->getValues().begin()); } StringList attrs; attrs.add("objectClasses"); attrs.add("attributeTypes"); entries = lc->search(schemabase, LDAPConnection::SEARCH_BASE, "(objectClass=*)", attrs); if (entries != 0){ LDAPEntry* entry = entries->getNext(); if(entry != 0){ const LDAPAttribute* oc = entry->getAttributes()->getAttributeByName("objectClasses"); LDAPSchema schema; schema.setObjectClasses((oc->getValues())); LDAPObjClass test = schema.getObjectClassByName("inetOrgPerson"); std::cout << test.getDesc() << std::endl; // StringList mustAttr = test.getMay(); // for( StringList::const_iterator i = mustAttr.begin(); i != mustAttr.end(); i++ ){ // std::cout << *i << std::endl; // } StringList sup = test.getSup(); for( StringList::const_iterator i = sup.begin(); i != sup.end(); i++ ){ std::cout << *i << std::endl; } } } lc->unbind(); delete lc; }catch (LDAPException e){ std::cout << "---------------- caught Exception ---------"<< std::endl; std::cout << e << std::endl; } }
// Get header info from options and store in map for processing with // metadata. void LasWriter::fillForwardList() { static const StringList header = { "dataformat_id", "major_version", "minor_version", "filesource_id", "global_encoding", "project_id", "system_id", "software_id", "creation_doy", "creation_year" }; static const StringList scale = { "scale_x", "scale_y", "scale_z" }; static const StringList offset = { "offset_x", "offset_y", "offset_z" }; static StringList all; all.insert(all.begin(), header.begin(), header.end()); all.insert(all.begin(), scale.begin(), scale.end()); all.insert(all.begin(), offset.begin(), offset.end()); // Build the forward list, replacing special keywords with the proper // field names. for (auto& name : m_forwardSpec) { if (name == "all") { m_forwards.insert(all.begin(), all.end()); m_forwardVlrs = true; } else if (name == "header") m_forwards.insert(header.begin(), header.end()); else if (name == "scale") m_forwards.insert(scale.begin(), scale.end()); else if (name == "offset") m_forwards.insert(offset.begin(), offset.end()); else if (name == "format") m_forwards.insert("dataformat_id"); else if (name == "vlr") m_forwardVlrs = true; else if (Utils::contains(all, name)) m_forwards.insert(name); else throwError("Error in 'forward' option. Unknown field for " "forwarding: '" + name + "'."); } }
void SessionManager::registerPlugin( Plugin* plugin ) { if( !plugin ) return; m_factory.registerPlugin( plugin ); if( m_parent ) { StringList features = plugin->features(); StringList::const_iterator it = features.begin(); for( ; it != features.end(); ++it ) m_parent->disco()->addFeature( (*it) ); } }
void DiskDir::load() { _files.clear(); _subdirs.clear(); // TODO: cache existing files and keep them unless they do no longer exist StringList li; GetFileList(fullname(), li); for(StringList::iterator it = li.begin(); it != li.end(); ++it) { DiskFile *f = new DiskFile(joinPath(fullname(), it->c_str()).c_str()); _files[f->name()] = f; } li.clear(); GetDirList(fullname(), li, 0); for(StringList::iterator it = li.begin(); it != li.end(); ++it) { // GetDirList() returns relative paths, so need to join Dir *d = createNew(joinPath(fullname(), it->c_str()).c_str()); _subdirs[d->name()] = d; } }
void CsvFile::addRow(const StringList& list) { StringList elements = list; if (itemenclosed_) { for (Size i = 0; i < elements.size(); ++i) { elements[i].quote('"', String::NONE); } } String line; line.concatenate(elements.begin(), elements.end(), itemseperator_); addLine(line); }
bool Slice::findMetaData(const string& prefix, const StringList& metaData, string& value) { for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); i++) { string s = *i; if(s.find(prefix) == 0) { value = s.substr(prefix.size()); return true; } } return false; }
String::Type Frame::checkEncoding(const StringList &fields, String::Type encoding) // static { if(encoding != String::Latin1) return encoding; for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) { if(!(*it).isLatin1()) { debug("Frame::checkEncoding() -- Rendering using UTF8."); return String::UTF8; } } return String::Latin1; }
bool Connector::article(const StringList& keylist, const std::string& data, bool kia) { std::string keystr; StringList real_keylist; for (StringList::const_iterator it = keylist.begin(); it != keylist.end(); ++it) { if (!kia) keystr += std::string("<k>") + *it + "</k>\n"; fill_key(*it); generate_keys(real_keylist); } return generator_.on_have_data(real_keylist, keystr + data); }