//------------ // Constructor //------------ XEMModel::XEMModel(XEMModel * iModel) { _deleteData = true; _nbCluster = iModel->getNbCluster(); _nbSample = iModel->getNbSample(); _algoName = iModel->_algoName; XEMModelType * iModelType = iModel->getParameter()->getModelType(); XEMModelName iModelName = iModelType->_nameModel; if ( isBinary(iModelName )) { XEMBinaryData * bD = (XEMBinaryData*)(iModel->getData()); _data = new XEMBinaryData(*bD); } else { XEMGaussianData * gD = (XEMGaussianData*)(iModel->getData()); _data = new XEMGaussianData(*gD); } _tabFik = copyTab(iModel->getTabFik() , _nbSample, _nbCluster); _tabSumF = copyTab(iModel->getTabSumF() , _nbSample); _tabTik = copyTab(iModel->getTabTik() , _nbSample, _nbCluster); _tabZikKnown = copyTab(iModel->getTabZikKnown(), _nbSample,_nbCluster); _tabZiKnown = copyTab(iModel->getTabZiKnown(), _nbSample); _tabCik = copyTab(iModel->getTabCik() , _nbSample, _nbCluster); _tabNk = copyTab(iModel->getTabNk() , _nbCluster); _parameter = (iModel->getParameter())->clone(); _parameter->setModel(this); }
QByteArray Content::asByteArray() const { if (!isBinary()) { return QByteArray(); } return QByteArray::fromBase64(text().trimmed().toLatin1()); }
std::string Expression::orderedString()const { std::string res = m_name; if (isVariable()) return res; std::multiset<std::string> str; if (isBinary()) { for(auto t = begin(); t != end(); ++t) { std::string op = (**t).m_op; if (op.empty()) { op = m_name; } str.insert(op+(**t).orderedString()); } res += "("; for(auto s = str.begin(); s != str.end(); ++s) { res += *s; } res += ")"; } else { res += "("; for(auto t = begin(); t != end(); ++t) { res += (**t).orderedString() + ","; } res += ")"; } return res; }
uint32_t LogBufferElement::getTag() const { return (isBinary() && ((mDropped && mMsg != nullptr) || (!mDropped && mMsgLen >= sizeof(android_event_header_t)))) ? reinterpret_cast<const android_event_header_t*>(mMsg)->tag : 0; }
bool ExprEvaluator::isHigherPriority(oper o1, oper o2){ if(isBinary(o1) && isBinary(o2)) if(o1 == oper::DIVIDE || o1 == oper::MULTIPLY || o2 == oper::BPLUS || o2 == oper::BMINUS) return true; else return false; if(isUnary(o1) && isBinary(o2)) return true; if(isUnary(o2)) return false; if(o1 == oper::SANTINEL && o2 != oper::SANTINEL) return false; if(o2 == oper::SANTINEL) return true; throw new Error(tokenizer.getExpr(), tokenizer.getTokPos(), ":Error comparing operator priorities"); }
bool File::write(std::shared_ptr<Data> data) { if (good() && !isRead() && isBinary()) { handle.write(reinterpret_cast<char *>(data->getBuffer()), data->getSize()); } return false; }
void ExprEvaluator::popOperator() { if(isBinary(operators.back())){ double t1 = pop(operands); double t0 = pop(operands); operands.push_back(mkNode(pop(operators), t0, t1)); } else operands.push_back(mkNode(pop(operators), pop(operands))); }
bool File::write(const std::string &line) { if (good() && !isRead() && !isBinary()) { handle << line << std::endl; } return false; }
bool File::read(std::string &line) { if (good() && isRead() && !isBinary() && !eof()) { std::getline(handle, line); return true; } return false; }
bool Shader::isCompiled() { if (isBinary()) { return true; } return mHlsl != NULL; }
Qt::ItemFlags SqliteTableModel::flags(const QModelIndex& index) const { if(!index.isValid()) return Qt::ItemIsEnabled; Qt::ItemFlags ret = QAbstractTableModel::flags(index); if(!isBinary(index)) ret |= Qt::ItemIsEditable; return ret; }
inline LPCSTR getValue() const { static StringBuffer buf; if(isBinary()) buf.clear().append(binaryValue); else pTree->getProp(name, buf.clear()); return buf.toCharArray(); }
TCHAR* Field::toString() { CL_NS(util)::StringBuffer result; if (isStored()) { result.append( _T("stored") ); } if (isIndexed()) { if (result.length() > 0) result.append( _T(",") ); result.append( _T("indexed") ); } if (isTokenized()) { if (result.length() > 0) result.append( _T(",") ); result.append( _T("tokenized") ); } if (isTermVectorStored()) { if (result.length() > 0) result.append( _T(",") ); result.append( _T("termVector") ); } if (isStoreOffsetWithTermVector()) { if (result.length() > 0) result.appendChar( ',' ); result.append( _T("termVectorOffsets") ); } if (isStorePositionWithTermVector()) { if (result.length() > 0) result.appendChar( ',' ); result.append( _T("termVectorPosition") ); } if (isBinary()) { if (result.length() > 0) result.appendChar( ',' ); result.append( _T("binary") ); } if (getOmitNorms()) { result.append( _T(",omitNorms") ); } result.appendChar('<'); result.append(name()); result.appendChar(':'); if (_stringValue != NULL) result.append(_stringValue); else if ( _readerValue != NULL ) result.append( _T("Reader") ); else if ( _streamValue != NULL ) result.append( _T("Stream") ); else result.append( _T("NULL") ); result.appendChar('>'); return result.toString(); }
bool setValue(LPCSTR newValue) // returns true if value actually updated { ASSERT(!isBinary()); ASSERT(connection != NULL); if(connection->lockWrite()) { pTree->setProp(name, newValue); connection->unlockWrite(); return true; } return false; }
QList<QString> ParserM3u::parse(QString sFilename) { QFile file(sFilename); QString basepath = sFilename.section('/', 0, -2); clearLocations(); //qDebug() << "ParserM3u: Starting to parse."; if (file.open(QIODevice::ReadOnly) && !isBinary(sFilename)) { /* Unfortunately, QT 4.7 does not handle <CR> (=\r or asci value 13) line breaks. * This is important on OS X where iTunes, e.g., exports M3U playlists using <CR> * rather that <LF> * * Using QFile::readAll() we obtain the complete content of the playlist as a ByteArray. * We replace any '\r' with '\n' if applicaple * This ensures that playlists from iTunes on OS X can be parsed */ QByteArray ba = file.readAll(); //detect encoding bool isCRLF_encoded = ba.contains("\r\n"); bool isCR_encoded = ba.contains("\r"); if(isCR_encoded && !isCRLF_encoded) ba.replace('\r','\n'); QTextStream textstream(ba.constData()); if (isUtf8(ba.constData())) { textstream.setCodec("UTF-8"); } else { textstream.setCodec("windows-1252"); } while(!textstream.atEnd()) { QString sLine = getFilepath(&textstream, basepath); if(sLine.isEmpty()) break; //qDebug() << "ParserM3u: parsed: " << (sLine); m_sLocations.append(sLine); } file.close(); if(m_sLocations.count() != 0) return m_sLocations; else return QList<QString>(); // NULL pointer returned when no locations were found } file.close(); return QList<QString>(); //if we get here something went wrong }
int error2(const struct command_t* command){ /*if((isNum(command->token[0]) && isUnary(command->token[1]) && isNum(command->token[2]) && strcmp(command->token[3], "") == 0) || (isNum(command->token[0]) && isBinary(command->token[1]) && strcmp(command->token[2], "") == 0))*/ if(isNum(command->token[0])) if(isUnary(command->token[1])) if(isNum(command->token[2])) if(strcmp(command->token[3], "") == 0) return 1; if(isNum(command->token[0])) if(isBinary(command->token[1])) if(strcmp(command->token[2], "") == 0) return 1; return 0; }
void XEMStrategy::setStrategyInit(XEMStrategyInitName initName, XEMData *& data, int64_t nbNbCluster, int64_t * tabNbCluster, XEMModelType ** tabModelType){ int64_t nbSample = data->_nbSample; int64_t pbDimension = data->_pbDimension; string fileName = ""; XEMParameter ** tabInitParameter = NULL; XEMPartition ** tabInitPartition = NULL; switch (initName){ case RANDOM : case CEM_INIT : case SEM_MAX : case SMALL_EM : _strategyInit->setStrategyInitName(initName); break; case USER : _strategyInit->setStrategyInitName(initName); tabInitParameter = new XEMParameter * [nbNbCluster]; for (int64_t k=0; k<nbNbCluster; k++){ if (isEDDA(tabModelType[0]->_nameModel)){ tabInitParameter[k] = new XEMGaussianGeneralParameter(tabNbCluster[k], pbDimension, tabModelType[0], fileName); } else if (isBinary(tabModelType[0]->_nameModel)){ int64_t * tabNbModality = ((XEMBinaryData*)data)->getTabNbModality(); tabInitParameter[k] = new XEMBinaryEkjhParameter(tabNbCluster[k], pbDimension, tabModelType[0], tabNbModality, fileName); } else if (isHD(tabModelType[0]->_nameModel)){ tabInitParameter[k] = new XEMGaussianHDDAParameter(tabNbCluster[k], pbDimension, tabModelType[0], fileName); } else throw internalMixmodError; } _strategyInit->setTabInitParameter(tabInitParameter, nbNbCluster); break; case USER_PARTITION : _strategyInit->setStrategyInitName(initName); tabInitPartition = new XEMPartition * [nbNbCluster]; for (int64_t k=0; k<nbNbCluster; k++){ XEMNumericPartitionFile partitionFile; partitionFile._fileName = fileName; partitionFile._format = FormatNumeric::defaultFormatNumericFile; partitionFile._type = TypePartition::defaultTypePartition; tabInitPartition[k] = new XEMPartition(nbSample, tabNbCluster[k], partitionFile); } _strategyInit->setTabPartition(tabInitPartition, nbNbCluster); break; } }
QString Content::debugInfo() const { QString info; info += QLatin1String("### Content: ###################\n"); info += QLatin1String("type: #") + type() + QLatin1String("#\n"); if (!src().isNull()) { info += QLatin1String("src: #") + src() + QLatin1String("#\n"); } if (!isBinary()) { info += QLatin1String("content: #") + asString() + QLatin1String("#\n"); } else { info += QLatin1String("binary length: #") + QString::number(asByteArray().size()) + QLatin1String("#\n"); } info += QLatin1String("### Content end ################\n"); return info; }
std::shared_ptr<FileData> File::read(FileReadMode readMode, size_t size) { std::shared_ptr<FileData> out = nullptr; if (good() && isRead() && isBinary()) { if (readMode == FileReadMode::BLOCK) { size = std::min(size, available()); } else if (readMode == FileReadMode::ALL) { size = available(); } out = std::make_shared<FileData>(size, filename); handle.read(reinterpret_cast<char *>(out->getBuffer()), size); } return out; }
Qt::ItemFlags SqliteTableModel::flags(const QModelIndex& index) const { if(!index.isValid()) return Qt::ItemIsEnabled; Qt::ItemFlags ret = QAbstractTableModel::flags(index) | Qt::ItemIsDropEnabled; // Custom display format set? bool custom_display_format = false; if(m_vDisplayFormat.size()) { if(index.column() > 0) custom_display_format = m_vDisplayFormat.at(index.column()-1) != sqlb::escapeIdentifier(headerData(index.column(), Qt::Horizontal).toString()); } if(!isBinary(index) && !custom_display_format) ret |= Qt::ItemIsEditable; return ret; }
//------------------------------------------------------------------------------ std::string WebSocketFrame::toString() const { std::stringstream ss; ss << "Flags:"; ss << " CONT=" << (isContinuation() ? "Y" : "N"); ss << ", TXT=" << (isText() ? "Y" : "N"); ss << ", BIN=" << (isBinary() ? "Y" : "N"); ss << ", CLOSE=" << (isClose() ? "Y" : "N"); ss << ", PING=" << (isPing() ? "Y" : "N"); ss << ", PONG=" << (isPong() ? "Y" : "N"); ss << ", FINAL=" << (isFinal() ? "Y" : "N"); ss << ", RSV1=" << (isRSV1() ? "Y" : "N"); ss << ", RSV2=" << (isRSV2() ? "Y" : "N"); ss << ", RSV3=" << (isRSV3() ? "Y" : "N"); ss << ", nBytes=" << size(); ss << ", bytes=" << getText(); return ss.str(); }
bool GeneratedFile::write(QString *errorMessage) const { // Ensure the directory const QFileInfo info(m_d->path); const QDir dir = info.absoluteDir(); if (!dir.exists()) { if (!dir.mkpath(dir.absolutePath())) { *errorMessage = BaseFileWizard::tr("Unable to create the directory %1.").arg(dir.absolutePath()); return false; } } // Write out QIODevice::OpenMode flags = QIODevice::WriteOnly|QIODevice::Truncate; if (!isBinary()) flags |= QIODevice::Text; Utils::FileSaver saver(m_d->path, flags); saver.write(m_d->contents); return saver.finalize(errorMessage); }
/* Will take in both numbers to validate that the numbers are entered correctly. * Will run the numbers to other functions based on the type specified by user. * Returns a 1 if number entered is found to be an invalid format.*/ int validateToken(char* num) { char tempType; char* tempNum; if (num[0] == '-' && strlen(num) <= 2) { //to have a negative sign means you must have at least a '-', a type (b,o,x,d) return 1; // and at least one digit. } else if (num[0] == '-') { tempType = num[1]; tempNum = strdup(&num[2]); } else if (strlen(num) <= 1) { //string must contain a type and at least one digit return 1; } else { tempType = num[0]; tempNum = strdup(&num[1]); } if (tempType == 'b' || tempType == 'B') //determination of type and whether number entered is valid. { return isBinary(tempNum); } else if (tempType == 'o'|| tempType == 'O') { return isOctal(tempNum); } else if (tempType == 'x' || tempType == 'X') { return isHex(tempNum); } else if (tempType == 'd' || tempType == 'D') { curr_State = mightBeDecFirstNum; return isDecimal(tempNum); } curr_State = undetermined; free(tempNum); return 1; }
QVariant SqliteTableModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() >= m_rowCount) return QVariant(); if(role == Qt::DisplayRole || role == Qt::EditRole) { // If this row is not in the cache yet get it first while(index.row() >= m_data.size() && canFetchMore()) const_cast<SqliteTableModel*>(this)->fetchMore(); // Nothing evil to see here, move along if(role == Qt::DisplayRole && isBinary(index)) return "(BLOB)"; else return m_data.at(index.row()).at(index.column()); } else { return QVariant(); } }
std::string FileEncoding::convertToUTF8(const std::string& raw_bytes, long enc_hint) { DWORD cp = investigate(raw_bytes); codePage_ = CP_UTF8; switch(cp) { case CP_UTF8: { break; } case CP_WINUNICODE: { codePage_ = CP_WINUNICODE; break; } case -1: { codePage_ = enc_hint; break; } default: { if ( enc_hint == CP_UTF8 ) codePage_ = CP_UTF8; else codePage_ = cp; } } if ( isBinary() ) { return ""; } switch ( codePage_ ) { case CP_WINUNICODE : { // jump over BOM std::string s2(raw_bytes); if ( raw_bytes.substr(0,2) == std::string((char*)mol::FileEncoding::UTF16LE_BOM,2) ) s2 = std::string(raw_bytes.data()+2,raw_bytes.size()-2); // it really is a UCS-2 string, so cast to wchar_t (WIN32) std::wstring ws((wchar_t*)(s2.data()),s2.size()/sizeof(wchar_t)); // now convert UTF16-LE to UTF-8 std::string u = mol::toUTF8(ws); return mol::unix2dos(u); } case CP_UTF8 : { std::string s2; if ( raw_bytes.substr(0,3) == std::string((char*)mol::FileEncoding::UTF8_BOM,3) ) s2 = std::string(raw_bytes.c_str()+3,raw_bytes.size()-3); else s2 = raw_bytes; s2 = mol::unix2dos(s2); return s2; } default: { std::string s2(mol::toUTF8(raw_bytes,codePage_)); s2 = mol::unix2dos(s2); return s2; } } return ""; }
// assumption: mMsg == NULL size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent, bool lastSame) { static const char tag[] = "chatty"; if (!__android_log_is_loggable_len(ANDROID_LOG_INFO, tag, strlen(tag), ANDROID_LOG_VERBOSE)) { return 0; } static const char format_uid[] = "uid=%u%s%s %s %u line%s"; parent->wrlock(); const char* name = parent->uidToName(mUid); parent->unlock(); const char* commName = android::tidToName(mTid); if (!commName && (mTid != mPid)) { commName = android::tidToName(mPid); } if (!commName) { parent->wrlock(); commName = parent->pidToName(mPid); parent->unlock(); } if (name && name[0] && commName && (name[0] == commName[0])) { size_t len = strlen(name + 1); if (!strncmp(name + 1, commName + 1, len)) { if (commName[len + 1] == '\0') { free(const_cast<char*>(commName)); commName = nullptr; } else { free(const_cast<char*>(name)); name = nullptr; } } } if (name) { char* buf = nullptr; asprintf(&buf, "(%s)", name); if (buf) { free(const_cast<char*>(name)); name = buf; } } if (commName) { char* buf = nullptr; asprintf(&buf, " %s", commName); if (buf) { free(const_cast<char*>(commName)); commName = buf; } } // identical to below to calculate the buffer size required const char* type = lastSame ? "identical" : "expire"; size_t len = snprintf(nullptr, 0, format_uid, mUid, name ? name : "", commName ? commName : "", type, getDropped(), (getDropped() > 1) ? "s" : ""); size_t hdrLen; if (isBinary()) { hdrLen = sizeof(android_log_event_string_t); } else { hdrLen = 1 + sizeof(tag); } buffer = static_cast<char*>(calloc(1, hdrLen + len + 1)); if (!buffer) { free(const_cast<char*>(name)); free(const_cast<char*>(commName)); return 0; } size_t retval = hdrLen + len; if (isBinary()) { android_log_event_string_t* event = reinterpret_cast<android_log_event_string_t*>(buffer); event->header.tag = htole32(CHATTY_LOG_TAG); event->type = EVENT_TYPE_STRING; event->length = htole32(len); } else { ++retval; buffer[0] = ANDROID_LOG_INFO; strcpy(buffer + 1, tag); } snprintf(buffer + hdrLen, len + 1, format_uid, mUid, name ? name : "", commName ? commName : "", type, getDropped(), (getDropped() > 1) ? "s" : ""); free(const_cast<char*>(name)); free(const_cast<char*>(commName)); return retval; }