std::streamsize Pathmap::read(InputStream &istream) throw (class Exception) { struct Header header; std::streamsize size = 0; wc3lib::read(istream, header, size); const id requiredFileId = fileId(); if (memcmp(&header.fileId, &requiredFileId, sizeof(header.fileId)) != 0) throw Exception(boost::format(_("Pathmap: Unknown file id \"%1%\". Expected \"%2%\".")) % header.fileId % fileId()); this->m_version = header.version; this->m_width = header.width; this->m_height = header.height; if (!this->m_data.empty()) this->m_data.clear(); for (int32 width = 0; width < header.width; ++width) { for (int32 height = 0; height < header.height; ++height) { byte type; wc3lib::read(istream, type, size); this->m_data[Position(width, height)] = (BOOST_SCOPED_ENUM(Type))(type); } } return size; }
bool DatIndexWriter::write(uint p_amount) { for (uint i = 0; i < p_amount; i++) { ssize_t bytesWritten; // First write categories, one at a time if (m_categoriesWritten < m_index.numCategories()) { auto category = m_index.category(m_categoriesWritten); auto parent = category->parent(); wxScopedCharBuffer nameBuffer = category->name().ToUTF8(); // Fixed-width fields DatIndexCategoryFields fields; fields.parent = (parent ? parent->index() : -1); fields.nameLength = nameBuffer.length(); bytesWritten = m_file.Write(&fields, sizeof(fields)); if (bytesWritten < sizeof(fields)) { return false; } // Name bytesWritten = m_file.Write(nameBuffer, fields.nameLength); if (bytesWritten < fields.nameLength) { return false; } // Increase the counter m_categoriesWritten++; } // Then, write entries one at a time (note the 'else') else if (m_entriesWritten < m_index.numEntries()) { auto entry = m_index.entry(m_entriesWritten); auto category = entry->category(); auto nameBuffer = entry->name().ToUTF8(); // Fixed-width fields DatIndexEntryFields fields; fields.category = category->index(); fields.baseId = entry->baseId(); fields.fileId = entry->fileId(); fields.mftEntry = entry->mftEntry(); fields.fileType = entry->fileType(); fields.nameLength = nameBuffer.length(); bytesWritten = m_file.Write(&fields, sizeof(fields)); if (bytesWritten < sizeof(fields)) { return false; } // Name bytesWritten = m_file.Write(nameBuffer, fields.nameLength); if (bytesWritten < fields.nameLength) { return false; } // Increase the counter m_entriesWritten++; } // Both done = ditch this loop else { break; } } // Remove dirty flag if everything is saved if (this->isDone()) { m_index.setDirty(false); } return true; }
bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record ) { QMutexLocker locker(&_mutex); qlonglong phash = getPHash(record._path); if( checkConnect() ) { QByteArray arr = record._path.toUtf8(); int plen = arr.length(); // _setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata " // "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid) " // "VALUES ( ? , ?, ? , ? , ? , ? , ?, ? , ? , ?, ? )" ); QString etag( record._etag ); if( etag.isEmpty() ) etag = ""; QString fileId( record._fileId); if( fileId.isEmpty() ) fileId = ""; _setFileRecordQuery->bindValue(0, QString::number(phash)); _setFileRecordQuery->bindValue(1, plen); _setFileRecordQuery->bindValue(2, record._path ); _setFileRecordQuery->bindValue(3, record._inode ); _setFileRecordQuery->bindValue(4, record._uid ); _setFileRecordQuery->bindValue(5, record._gid ); _setFileRecordQuery->bindValue(6, record._mode ); _setFileRecordQuery->bindValue(7, QString::number(record._modtime.toTime_t())); _setFileRecordQuery->bindValue(8, QString::number(record._type) ); _setFileRecordQuery->bindValue(9, etag ); _setFileRecordQuery->bindValue(10, fileId ); if( !_setFileRecordQuery->exec() ) { qWarning() << "Error SQL statement setFileRecord: " << _setFileRecordQuery->lastQuery() << " :" << _setFileRecordQuery->lastError().text(); return false; } qDebug() << _setFileRecordQuery->lastQuery() << phash << plen << record._path << record._inode << record._uid << record._gid << record._mode << QString::number(record._modtime.toTime_t()) << QString::number(record._type) << record._etag << record._fileId; _setFileRecordQuery->finish(); return true; } else { qDebug() << "Failed to connect database."; return false; // checkConnect failed. } }
int FindSymbolsJob::execute() { int ret = 2; if (std::shared_ptr<Project> proj = project()) { Set<Symbol> symbols; Location filter; const uint32_t filteredFile = fileFilter(); if (filteredFile) filter = Location(filteredFile, 0, 0); auto inserter = [proj, this, &symbols, &filter, filteredFile](Project::SymbolMatchType type, const String &symbolName, const Set<Location> &locations) { if (filter.fileId()) { auto it = locations.lower_bound(filter); if (it == locations.end() || it->fileId() != filteredFile) return; } if (type == Project::StartsWith) { const size_t paren = symbolName.indexOf('('); if (paren == String::npos || paren != string.size() || RTags::isFunctionVariable(symbolName)) return; } for (const auto &it : locations) { const Symbol sym = proj->findSymbol(it); if (!sym.isNull()) symbols.insert(sym); } }; proj->findSymbols(string, inserter, queryFlags()); if (!symbols.isEmpty()) { const List<RTags::SortedSymbol> sorted = proj->sort(symbols, queryFlags()); const Flags<WriteFlag> writeFlags = fileFilter() ? Unfiltered : NoWriteFlags; const int count = sorted.size(); ret = count ? 0 : 1; for (int i=0; i<count; ++i) { write(sorted.at(i).location, writeFlags); } } } return ret; }
std::streamsize Pathmap::write(OutputStream &ostream) const throw (class Exception) { struct Header header; header.fileId = fileId(); header.height = height(); header.width = width(); header.version = version(); std::streamsize size = 0; wc3lib::write(ostream, header, size); for (int32 width = 0; width < header.width; ++width) { for (int32 height = 0; height < header.height; ++height) { byte type = (byte)this->m_data.find(Position(width, height))->second; wc3lib::write(ostream, type, size); } } return size; }
void ClassifyDocum::calculateWords() //читать класс { cout<<getName()<<" "<<listFiles.size()<<endl; for(size_t i=0; i<listFiles.size();i++) { wifstream fileId(nameDirClass+listFiles[i]+".norm"); wstring strInput; while(fileId>>strInput) { ++fileCountWords[listFiles[i]][strInput]; ++countWordsClass[strInput]; countAllWords++; // TermInDoc.insert(pair<string,wstring>(listFiles[i].c_str(),strInput.c_str())); } fileId.close(); classCountWords.push_back(countWordsClass); // fileCountWords. } for (CountWords::iterator p = countWordsClass.begin(); p != countWordsClass.end(); ++p) { // wcout << p->first << ": " << p->second << '\n'; } }
Source::UP DirSourceFactory::createSource(const IConfigHolder::SP & holder, const ConfigKey & key) const { vespalib::string fileId(key.getDefName()); if (!key.getConfigId().empty()) { fileId += "." + key.getConfigId(); } fileId += ".cfg"; bool found(false); for (const auto & fileName : _fileNames) { if (fileName.compare(fileId) == 0) { found = true; break; } } if ( !found ) { LOG(warning, "Filename '%s' was expected in the spec, but does not exist.", fileId.c_str()); } vespalib::string fName = _dirName; if (!fName.empty()) fName += "/"; fName += fileId; return Source::UP(new FileSource(holder, fName)); }
String Location::context(Flags<ToStringFlag> flags, Hash<Path, String> *cache) const { String copy; String *code = 0; const Path p = path(); auto readAll = [&p, this]() { if (Server::instance()) { if (auto project = Server::instance()->currentProject()) { const Path f = project->sourceFilePath(fileId(), "unsaved"); String contents = f.readAll(); if (!contents.isEmpty()) return contents; } } return p.readAll(); }; if (cache) { String &ref = (*cache)[p]; if (ref.isEmpty()) { ref = readAll(); } code = &ref; } else { copy = readAll(); code = © } String ret; if (!code->isEmpty()) { unsigned int l = line(); if (!l) return String(); const char *ch = code->constData(); while (--l) { ch = strchr(ch, '\n'); if (!ch) return String(); ++ch; } const char *end = strchr(ch, '\n'); if (!end) return String(); ret.assign(ch, end - ch); // error() << "foobar" << ret << bool(flags & NoColor); if (!(flags & NoColor)) { const size_t col = column() - 1; if (col + 1 < ret.size()) { size_t last = col; if (ret.at(last) == '~') ++last; while (ret.size() > last && (isalnum(ret.at(last)) || ret.at(last) == '_')) ++last; static const char *color = "\x1b[32;1m"; // dark yellow static const char *resetColor = "\x1b[0;0m"; // error() << "foobar"<< end << col << ret.size(); ret.insert(last, resetColor); ret.insert(col, color); } // printf("[%s]\n", ret.constData()); } } return ret; }