static void print_message_to_buffer(const QModelIndex &idx, GtkTextBuffer *buffer) { if (idx.isValid()) { auto message = idx.data().value<QString>().toUtf8(); auto sender = idx.data(static_cast<int>(Media::TextRecording::Role::AuthorDisplayname)).value<QString>().toUtf8(); GtkTextIter iter; /* unless its the very first message, insert a new line */ if (idx.row() != 0) { gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert(buffer, &iter, "\n", -1); } auto format_sender = g_strconcat(sender.constData(), ": ", NULL); gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, format_sender, -1, "bold", NULL); g_free(format_sender); /* if the sender name is too long, insert a new line after it */ if (sender.length() > 20) { gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert(buffer, &iter, "\n", -1); } gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert(buffer, &iter, message.constData(), -1); } else { g_warning("QModelIndex in im model is not valid"); } }
void writeVector(QDataStream& out, char ch, QVector<T> vec) { // Minimum number of bytes to consider compressing const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000; out.device()->write(&ch, 1); out << (int32_t)vec.length(); auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) }; if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) { auto compressedDataWithLength { qCompress(data) }; // qCompress packs a length uint32 at the beginning of the buffer, but the FBX format // does not expect it. This removes it. auto compressedData = QByteArray::fromRawData( compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t)); if (compressedData.size() < data.size()) { out << FBX_PROPERTY_COMPRESSED_FLAG; out << (int32_t)compressedData.size(); out.writeRawData(compressedData.constData(), compressedData.size()); return; } } out << FBX_PROPERTY_UNCOMPRESSED_FLAG; out << (int32_t)0; out.writeRawData(data.constData(), data.size()); }
double Q3CString::toDouble(bool *ok) const { char *end; double val = strtod(constData() ? constData() : "", &end); if (ok) *ok = (constData() && *constData() && (end == 0 || *end == '\0')); return val; }
time_t Path::lastModified() const { struct stat st; if (stat(constData(), &st) == -1) { warning("Stat failed for %s", constData()); return 0; } return st.st_mtime; }
QString DefaultDemangler::demangle(const QString &symbol) const { int status; auto byteArray = symbol.toLatin1(); if (auto output = std::unique_ptr<char[], FreeDeleter>(__cxa_demangle(byteArray.constData(), nullptr, nullptr, &status))) { return QLatin1String(output.get()); } else if (auto output = std::unique_ptr<char[], FreeDeleter>(__unDName(nullptr, byteArray.constData(), 0, 0))) { return QLatin1String(output.get()); } else { return QString(); } }
uint64_t Path::lastModifiedMs() const { struct stat st; if (stat(constData(), &st) == -1) { warning("Stat failed for %s", constData()); return 0; } #ifdef HAVE_STATMTIM return st.st_mtim.tv_sec * static_cast<uint64_t>(1000) + st.st_mtim.tv_nsec / static_cast<uint64_t>(1000000); #else return st.st_mtime * static_cast<uint64_t>(1000); #endif }
bool Path::resolve(ResolveMode mode, const Path &cwd, bool *changed) { if (changed) *changed = false; if (startsWith('~')) { wordexp_t exp_result; wordexp(constData(), &exp_result, 0); operator=(exp_result.we_wordv[0]); wordfree(&exp_result); } if (*this == ".") clear(); if (mode == MakeAbsolute) { if (isAbsolute()) return true; const Path copy = (cwd.isEmpty() ? Path::pwd() : cwd.ensureTrailingSlash()) + *this; if (copy.exists()) { if (changed) *changed = true; operator=(copy); return true; } return false; } if (!cwd.isEmpty() && !isAbsolute()) { Path copy = cwd + '/' + *this; if (copy.resolve(RealPath, Path(), changed)) { operator=(copy); return true; } } { char buffer[PATH_MAX + 2]; if (realpath(constData(), buffer)) { if (isDir()) { const int len = strlen(buffer); assert(buffer[len] != '/'); buffer[len] = '/'; buffer[len + 1] = '\0'; } if (changed && strcmp(buffer, constData())) *changed = true; String::operator=(buffer); return true; } } return false; }
void GLRasterTexture::initializeGL(bool coreProfile) { if(m_data.size() == 0) return; m_program = new QOpenGLShaderProgram; m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, coreProfile ? vertexShaderSourceCore : vertexShaderSource); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, coreProfile ? fragmentShaderSourceCore : fragmentShaderSource); m_program->bindAttributeLocation("vertex", 0); m_program->bindAttributeLocation("texCoord", 1); m_program->link(); m_program->bind(); m_projMatrixLoc = m_program->uniformLocation("projMatrix"); m_mvMatrixLoc = m_program->uniformLocation("mvMatrix"); m_textureSamplerLoc = m_program->uniformLocation("texture"); m_vao.create(); QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao); // Setup our vertex buffer object. m_vbo.create(); m_vbo.bind(); m_vbo.allocate(constData(), m_count * sizeof(GLfloat)); // Store the vertex attribute bindings for the program. setupVertexAttribs(); m_program->setUniformValue(m_textureSamplerLoc, 0); m_program->release(); m_built = true; }
const char * Path::extension() const { const int dot = lastIndexOf('.'); if (dot == -1 || dot + 1 == size()) return 0; return constData() + dot + 1; }
ulong Q3CString::toULong(bool *ok) const { const char *p = constData(); ulong val=0; const ulong max_mult = 429496729; bool is_ok = false; if (!p) goto bye; while (isspace((uchar) *p)) // skip leading space p++; if (*p == '+') p++; if (!isdigit((uchar) *p)) goto bye; while (isdigit((uchar) *p)) { if (val > max_mult || (val == max_mult && (*p-'0') > 5)) goto bye; val = 10*val + (*p++ - '0'); } while (isspace((uchar) *p)) // skip trailing space p++; if (*p == '\0') is_ok = true; bye: if (ok) *ok = is_ok; return is_ok ? val : 0; }
BomAsciiCheckResult checkForBomAndNonAscii(QString const &fileName) { QFile file{fileName}; if (!file.open(QIODevice::ReadOnly)) return {}; auto content = file.readAll(); file.close(); auto result = BomAsciiCheckResult{}; auto dataSize = content.size(); auto dataPtr = reinterpret_cast<unsigned char const *>(content.constData()); auto dataEnd = dataPtr + dataSize; mm_text_io_c::detect_byte_order_marker(dataPtr, dataSize, result.byteOrder, result.bomLength); dataPtr += result.bomLength; while (dataPtr < dataEnd) { if (*dataPtr > 127) { result.containsNonAscii = true; break; } ++dataPtr; } return result; }
Path Path::toTilde() const { const Path home = Path::home(); if (startsWith(home)) return String::format<64>("~/%s", constData() + home.size()); return *this; }
int main (int argc, char *argv[]) { if (!preprocessCommands(&argc, argv, NULL, NULL)) { xexit(0); } printf("Resource Reading...\n"); ResourceSource* res = setupParameters(true, &argc, argv); ConstData constData(*res); Intervals intervals(*res); BeamParams beamParams(*res); FILE* massOut = openOutDataFile(*res, "mass_out"); FILE* crossSectionOut = openOutDataFile(*res, "total_cross_section_out"); printFileHeaders(massOut, crossSectionOut); printf("Main loop...\n"); DataSeparator massSeparator(massOut), csSeparator(crossSectionOut); loopMassMuTan(constData, intervals, beamParams, massSeparator, csSeparator, massOut, crossSectionOut); printf("Resource releasing...\n"); fclose(crossSectionOut); fclose(massOut); delete res; printf("Done...\n"); xexit(0); }
const char * Path::fileName(int *len) const { const int idx = lastIndexOf('/') + 1; if (len) *len = size() - idx; return constData() + idx; }
void GaduRosterService::exportContactList() { if (!m_connection || !m_connection.data()->hasSession()) { putFinished(false); return; } m_synchronizingContacts = contacts(); for (auto &&contact : m_synchronizingContacts) contact.rosterEntry()->setSynchronizingToRemote(); auto contacts = m_gaduListHelper->contactListToByteArray(m_synchronizingContacts); kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "\n%s\n", contacts.constData()); auto accountData = GaduAccountData{account()}; auto writableSessionToken = m_connection.data()->writableSessionToken(); auto ret = gg_userlist100_request(writableSessionToken.rawSession(), GG_USERLIST100_PUT, accountData.userlistVersion(), GG_USERLIST100_FORMAT_TYPE_GG70, contacts.constData()); if (-1 == ret) { markSynchronizingAsSynchronized(); putFinished(false); } }
bool Path::resolve(ResolveMode mode, const Path &cwd) { if (mode == MakeAbsolute) { if (isAbsolute()) return true; const Path copy = (cwd.isEmpty() ? Path::pwd() : cwd) + *this; if (copy.exists()) { operator=(copy); return true; } return false; } else { if (!cwd.isEmpty() && !isAbsolute()) { Path copy = cwd + '/' + *this; if (copy.resolve(RealPath)) { operator=(copy); return true; } } { char buffer[PATH_MAX + 2]; if (realpath(constData(), buffer)) { String::operator=(buffer); return true; } } } return false; }
long Q3CString::toLong(bool *ok) const { const char *p = constData(); long val=0; const long max_mult = 214748364; bool is_ok = false; int neg = 0; if (!p) goto bye; while (isspace((uchar) *p)) // skip leading space p++; if (*p == '-') { p++; neg = 1; } else if (*p == '+') { p++; } if (!isdigit((uchar) *p)) goto bye; while (isdigit((uchar) *p)) { if (val > max_mult || (val == max_mult && (*p-'0') > 7+neg)) goto bye; val = 10*val + (*p++ - '0'); } if (neg) val = -val; while (isspace((uchar) *p)) // skip trailing space p++; if (*p == '\0') is_ok = true; bye: if (ok) *ok = is_ok; return is_ok ? val : 0; }
bool OsmAnd::ImageMapLayerProvider::obtainData( const IMapDataProvider::Request& request_, std::shared_ptr<IMapDataProvider::Data>& outData, std::shared_ptr<Metric>* const pOutMetric /*= nullptr*/) { const auto& request = MapDataProviderHelpers::castRequest<Request>(request_); if (pOutMetric) pOutMetric->reset(); if (!supportsNaturalObtainData()) return MapDataProviderHelpers::nonNaturalObtainData(this, request, outData, pOutMetric); // Obtain image data const auto image = obtainImage(request); if (image.isNull()) { outData.reset(); return true; } // Decode image data std::shared_ptr<SkBitmap> bitmap(new SkBitmap()); SkMemoryStream imageStream(image.constData(), image.length(), false); if (!SkImageDecoder::DecodeStream(&imageStream, bitmap.get(), SkColorType::kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode)) return false; // Return tile outData.reset(new IRasterMapLayerProvider::Data( request.tileId, request.zoom, getAlphaChannelPresence(), getTileDensityFactor(), bitmap)); return true; }
OId Commit::amend(const Tree& tree, const QString& ref, const QString& message, const Signature& author, const Signature& committer) { OId oid; qGitThrow(git_commit_amend(oid.data(), constData(), ref.isEmpty() ? NULL : PathCodec::toLibGit2(ref).constData(), author.data(), committer.data(), NULL, message.isNull() ? NULL : message.toUtf8().constData(), tree.constData())); return oid; }
Matrix<T>& Matrix<T>::operator*=( const qreal& Value ) { Q_ASSERT(constData() && size()); int srcStride1(bytesPerLine()); int srcStride2(bytesPerElement()); if (type() == CV_64F) { Ipp64f* pSrc(reinterpret_cast<Ipp64f*>(data())); const Ipp64f val(static_cast<const Ipp64f>(Value)); IppStatus status(ippmMul_mc_64f(pSrc, srcStride1, srcStride2, val, pSrc, srcStride1, srcStride2, cols(), rows())); Q_ASSERT(status == ippStsNoErr); } else { Q_ASSERT(!"CHECK"); const T mulValue(static_cast<const T>(Value)); for (int rowIndex(0); rowIndex < rows(); rowIndex++) { T* rowPtr(row(rowIndex)); for (int colIndex(0); colIndex < cols(); colIndex++, rowPtr++) { *rowPtr *= mulValue; } } } return *this; }
void SqlQuery::bindValue(int pos, const QVariant& value) { int res = -1; Q_ASSERT(_stmt); if( _stmt ) { switch (value.type()) { case QVariant::Int: case QVariant::Bool: res = sqlite3_bind_int(_stmt, pos, value.toInt()); break; case QVariant::Double: res = sqlite3_bind_double(_stmt, pos, value.toDouble()); break; case QVariant::UInt: case QVariant::LongLong: res = sqlite3_bind_int64(_stmt, pos, value.toLongLong()); break; case QVariant::DateTime: { const QDateTime dateTime = value.toDateTime(); const QString str = dateTime.toString(QLatin1String("yyyy-MM-ddThh:mm:ss.zzz")); res = sqlite3_bind_text16(_stmt, pos, str.utf16(), str.size() * sizeof(ushort), SQLITE_TRANSIENT); break; } case QVariant::Time: { const QTime time = value.toTime(); const QString str = time.toString(QLatin1String("hh:mm:ss.zzz")); res = sqlite3_bind_text16(_stmt, pos, str.utf16(), str.size() * sizeof(ushort), SQLITE_TRANSIENT); break; } case QVariant::String: { if( !value.toString().isNull() ) { // lifetime of string == lifetime of its qvariant const QString *str = static_cast<const QString*>(value.constData()); res = sqlite3_bind_text16(_stmt, pos, str->utf16(), (str->size()) * sizeof(QChar), SQLITE_TRANSIENT); } else { res = sqlite3_bind_null(_stmt, pos); } break; } case QVariant::ByteArray: { auto ba = value.toByteArray(); res = sqlite3_bind_text(_stmt, pos, ba.constData(), ba.size(), SQLITE_TRANSIENT); break; } default: { QString str = value.toString(); // SQLITE_TRANSIENT makes sure that sqlite buffers the data res = sqlite3_bind_text16(_stmt, pos, str.utf16(), (str.size()) * sizeof(QChar), SQLITE_TRANSIENT); break; } } } if (res != SQLITE_OK) { qDebug() << Q_FUNC_INFO << "ERROR" << value << res; } Q_ASSERT( res == SQLITE_OK ); }
int64_t Path::fileSize() const { struct stat st; if (!stat(constData(), &st)) {// && st.st_mode == S_IFREG) return st.st_size; } return -1; }
char * home_path() { auto s = QDir::homePath().toLatin1() ; auto a = static_cast< char * >( std::malloc( s.size() + 1 ) ) ; std::memcpy( a,s.constData(),s.size() ) ; *( a + s.size() ) = '\0' ; return a ; }
Q3CString Q3CString::rightJustify(uint width, char fill, bool truncate) const { Q3CString result; int len = qstrlen(constData()); int padlen = width - len; if (padlen > 0) { result.resize(len+padlen); memset(result.data(), fill, padlen); memcpy(result.data()+padlen, constData(), len); } else { if (truncate) result = left(width); else result = *this; } return result; }
bool Path::isSymLink() const { struct stat st; if (lstat(constData(), &st) == -1) return false; return (st.st_mode & S_IFMT) == S_IFLNK; }
mode_t Path::mode() const { struct stat st; if (stat(constData(), &st) == -1) return 0; return st.st_mode; }
inline static qulonglong hash(const CFileSystemObject& object) { const auto properties = object.properties(); const auto hashData = QByteArray::fromRawData((const char*)&properties.hash, sizeof(properties.hash)) + QByteArray::fromRawData((const char*)&properties.modificationDate, sizeof(properties.modificationDate)) + QByteArray::fromRawData((const char*)&properties.type, sizeof(properties.type)); return fasthash64(hashData.constData(), hashData.size(), 0); }
String Path::readAll(int max) const { FILE *f = fopen(constData(), "r"); if (!f) return String(); const String ret = Rct::readAll(f, max); fclose(f); return ret; }
void RenderWidget::PassEventToImGui(const QEvent* event) { if (!Core::IsRunningAndStarted()) return; switch (event->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: { // As the imgui KeysDown array is only 512 elements wide, and some Qt keys which // we need to track (e.g. alt) are above this value, we mask the lower 9 bits. // Even masked, the key codes are still unique, so conflicts aren't an issue. // The actual text input goes through AddInputCharactersUTF8(). const QKeyEvent* key_event = static_cast<const QKeyEvent*>(event); const bool is_down = event->type() == QEvent::KeyPress; const u32 key = static_cast<u32>(key_event->key() & 0x1FF); auto lock = g_renderer->GetImGuiLock(); if (key < ArraySize(ImGui::GetIO().KeysDown)) ImGui::GetIO().KeysDown[key] = is_down; if (is_down) { auto utf8 = key_event->text().toUtf8(); ImGui::GetIO().AddInputCharactersUTF8(utf8.constData()); } } break; case QEvent::MouseMove: { auto lock = g_renderer->GetImGuiLock(); // Qt multiplies all coordinates by the scaling factor in highdpi mode, giving us "scaled" mouse // coordinates (as if the screen was standard dpi). We need to update the mouse position in // native coordinates, as the UI (and game) is rendered at native resolution. const float scale = devicePixelRatio(); ImGui::GetIO().MousePos.x = static_cast<const QMouseEvent*>(event)->x() * scale; ImGui::GetIO().MousePos.y = static_cast<const QMouseEvent*>(event)->y() * scale; } break; case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: { auto lock = g_renderer->GetImGuiLock(); const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->buttons()); for (size_t i = 0; i < ArraySize(ImGui::GetIO().MouseDown); i++) ImGui::GetIO().MouseDown[i] = (button_mask & (1u << i)) != 0; } break; default: break; } }
void PrintTo(const SourceLocation &sourceLocation, std::ostream *os) { auto filePath = sourceLocation.filePath(); if (filePath.hasContent()) *os << filePath.constData() << ", "; *os << "line: " << sourceLocation.line() << ", column: "<< sourceLocation.column() << ", offset: "<< sourceLocation.offset(); }