bool testWrappingWriteSizeCounts() { printf("testWrappingWriteSizeCounts\n"); SensorEventQueue* queue = new SensorEventQueue(10); queue->markAsWritten(9); if (!checkSize(queue, 9)) return false; // dequeue from the front queue->dequeue(); queue->dequeue(); if (!checkSize(queue, 7)) return false; if (!checkWritableBufferSize(queue, 100, 1)) return false; // Write all the way to the end. queue->markAsWritten(1); if (!checkSize(queue, 8)) return false; // Now the two free spots in the front are available. if (!checkWritableBufferSize(queue, 100, 2)) return false; // Fill the queue again queue->markAsWritten(2); if (!checkSize(queue, 10)) return false; printf("passed\n"); return true; }
/*! Loads the TGA file to memory (acces data using ITextureFile base class members). */ bool TgaFile::load(const std::string& filename) { // Loads up a targa file. Supported types are 8,24 and 32 // uncompressed images. unsigned char type[4]; unsigned char info[7]; int size = 0; FILE *fp = fopen( filename.c_str(), "rb" ); if( !fp ) return false; fread( &type, sizeof (char), 3, fp ); // Read in colormap info and image type, byte 0 ignored fseek( fp, 12, SEEK_SET); // Seek past the header and useless info fread( &info, sizeof (char), 6, fp ); if( type[1] != 0 || (type[2] != 2 && type[2] != 3) ) { fclose (fp); return false; } m_Width = info[0] + info[1] * 256; m_Height = info[2] + info[3] * 256; m_nBits = info[4]; size = m_Width * m_Height; // Make sure dimension is a power of 2 if( !checkSize(m_Width) || !checkSize(m_Height)) { fclose(fp); return false; } // Make sure we are loading a supported type if( m_nBits != 32 && m_nBits != 24 && m_nBits != 8 ) { fclose(fp); return false; } if( m_nBits == 32 ) m_pData = loadRGBA( fp, size ); else if( m_nBits == 24 ) m_pData = loadRGB( fp, size ); else if( m_nBits == 8 ) m_pData = loadGray( fp, size ); // No image data if( m_pData == NULL ) { fclose(fp); return false; } fclose( fp ); return true; }
/** * @brief createTable creates the database and metadata. * @param registerSize is the size for each registry. * @param columnSizes is the sizes for each column. */ bool writefile::createTable(int* registerSize, array<int>* columnSizes , array<char*>* columnNames , string* pFile){ int offset = 0; string add; string theFileName = createNewFile(*pFile); writefile::writeColumnNames(&theFileName, columnNames); ofstream database (theFileName.c_str() , ios::trunc); //check if buffer = true if(database.is_open()){ //cout << "****Database succesfully created***" << endl; }else{ //cout << "****Database could not be created***" << endl; return false; } //Register size valideichion. if(*registerSize >= K->MAX_REGISTER_SIZE){ cout << "Error: Register size beyond max size" << endl; return false; }else{ database << K->TRIPLE_NULL; add = toChar(*registerSize); checkSize(&add, K->DEFAULT_REGISTER_SIZE); database.write(add.c_str() , K->DEFAULT_REGISTER_SIZE); } //set column sizes on file array<int> tempArr = *columnSizes; for (int i = 0 ; i < tempArr.getLenght() ; i++) { int integerElem = tempArr[i]; add = toChar(integerElem); checkSize(&add,K->DEFAULT_COLUMN_SIZE); database.write(add.c_str() , K->DEFAULT_COLUMN_SIZE); } //sets seek on the end, gets the address then turns it to char //to insert on the beginning. database.seekp(offset, ios::end); int meta = database.tellp(); string metadata = intToChar(meta); checkSize(&metadata, K->METADATA_SIZE); database.seekp(K->ZE_ROW); if (metadata.length() <= 3){ const char *p = metadata.c_str(); while (*p != '\0') database.put( *(p++) ); }else{ //cout << "Invalid metadata size. Yoh ! Pls kontact ur admin...\n"; return false; } database.seekp(K->ZE_ROW , ios::end); database.close(); return true; }
/* ============= loadTGA Loads up a targa file. Supported types are 8,24 and 32 uncompressed images. id is the texture ID to bind too. ============= */ int loadTGA (const char *name, int id) { unsigned char type[4]; unsigned char info[7]; unsigned char *imageData = NULL; int imageWidth, imageHeight; int imageBits, size; FILE *s; if (!(s = fopen (name, "r+bt"))) return TGA_FILE_NOT_FOUND; fread (&type, sizeof (char), 3, s); // read in colormap info and image type, byte 0 ignored fseek (s, 12, SEEK_SET); // seek past the header and useless info fread (&info, sizeof (char), 6, s); if (type[1] != 0 || (type[2] != 2 && type[2] != 3)) returnError (s, TGA_BAD_IMAGE_TYPE); imageWidth = info[0] + info[1] * 256; imageHeight = info[2] + info[3] * 256; imageBits = info[4]; size = imageWidth * imageHeight; /* make sure dimension is a power of 2 */ if (!checkSize (imageWidth) || !checkSize (imageHeight)) returnError (s, TGA_BAD_DIMENSION); /* make sure we are loading a supported type */ if (imageBits != 32 && imageBits != 24 && imageBits != 8) returnError (s, TGA_BAD_BITS); imageData = getData (s, size, imageBits); /* no image data */ if (imageData == NULL) returnError (s, TGA_BAD_DATA); fclose (s); glBindTexture(GL_TEXTURE_2D,id); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D (GL_TEXTURE_2D, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData); /* release data, its been uploaded */ free (imageData); return 1; }
int ePixmap::event(int event, void *data, void *data2) { switch (event) { case evtPaint: { ePtr<eWindowStyle> style; eSize s(size()); getStyle(style); // we don't clear the background before because of performance reasons. // when the pixmap is too small to fit the whole widget area, the widget is // transparent anyway, so the background is already painted. // eWidget::event(event, data, data2); gPainter &painter = *(gPainter*)data2; if (m_pixmap) { int flags = 0; if (m_alphatest == 0) flags = 0; else if (m_alphatest == 1) flags = gPainter::BT_ALPHATEST; else if (m_alphatest == 2) flags = gPainter::BT_ALPHABLEND; if (m_scale) painter.blitScale(m_pixmap, eRect(ePoint(0, 0), s), eRect(), flags); else painter.blit(m_pixmap, ePoint(0, 0), eRect(), flags); } if (m_have_border_color) painter.setForegroundColor(m_border_color); if (m_border_width) { painter.fill(eRect(0, 0, s.width(), m_border_width)); painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width)); painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width)); painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width)); } return 0; } case evtChangedPixmap: checkSize(); invalidate(); return 0; case evtChangedSize: checkSize(); /* fall trough. */ default: return eWidget::event(event, data, data2); } }
void ToolTip::showEvent(QShowEvent *e) { checkSize(); QWidget::showEvent(e); d->preview->setInfo(); WindowEffects::overrideShadow(winId(), true); }
void addFile(const char *filename) { if (maxfiles == 0) initFiles(); checkSize(); files[nfiles++] = strdup(filename); }
void Bitmap::create(int w, int h, bool _alpha) { free(); checkSize(w, h); BITMAPINFO bmi; ZeroMemory(&bmi, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight * 4; DCDisplay dcd; DCCompatible cdc(dcd.hdc); ptr32 = 0; handle = CreateDIBSection(cdc.hdc, &bmi, DIB_RGB_COLORS, &ptr32, NULL, 0x0); if(handle==0) raise_os(_T("Bitmap.create: CreateDIBSection")); if(ptr32==0) { DeleteObject(handle); handle=0; raise(_T("Bitmap.create: CreateDIBSection ptr32=0")); } BEGIN_NO_EXCEPTION width = w; height = h; alpha = _alpha; END_NO_EXCEPTION }
int Span::longestSpan(void) { checkSize(); int min = *std::min_element(m_vector.begin(), m_vector.begin() + mn_currentNumber); int max = *std::max_element(m_vector.begin(), m_vector.begin() + mn_currentNumber); return (max - min); }
int bitAndOctetStringAlignmentTest (Asn1SizeCnst* pSizeList, ASN1UINT itemCount, ASN1BOOL bitStrFlag, ASN1BOOL* pAlignFlag) { ASN1UINT threshold = (bitStrFlag) ? 16 : 2; if (pSizeList == 0 || itemCount > threshold) *pAlignFlag = TRUE; else if (isFixedSize(pSizeList)) *pAlignFlag = FALSE; else { /* Variable length case: check size.. no alignment required if */ /* lower == upper and not extended.. */ ASN1BOOL extended; Asn1SizeCnst* pSize = checkSize (pSizeList, itemCount, &extended); if (pSize != 0) *pAlignFlag = ((pSize->upper != pSize->lower) || pSize->extended); else { /* Note: we never should get here because constraint */ /* violation should have been caught when length was encoded */ /* or decoded.. */ return (ASN_E_CONSVIO); } } return (ASN_OK); }
ASN1BOOL alignCharStr (OOCTXT* pctxt, ASN1UINT len, ASN1UINT nbits, Asn1SizeCnst* pSize) { if (TRUE) { ASN1UINT lower, upper; ASN1BOOL doAlign = (len > 0), extendable; pSize = checkSize (pSize, len, &extendable); if (0 != pSize) { lower = pSize->lower; upper = pSize->upper; } else { lower = 0; upper = ASN1UINT_MAX; } if (!extendable && upper < 65536) { ASN1UINT bitRange = upper * nbits; if (upper == lower) { /* X.691, clause 26.5.6 */ if (bitRange <= 16) doAlign = FALSE; } else { /* X.691, clause 26.5.7 */ if (bitRange < 16) doAlign = FALSE; } } return doAlign; } else return FALSE; }
void ToolTip::setContent(QObject *tipper, const ToolTipContent &data) { //reset our size d->text->setContent(data); if (data.image().isNull()) { d->imageLabel->hide(); } else { d->imageLabel->show(); d->imageLabel->setPixmap(data.image()); } if (data.highlightWindows() && !data.windowsToPreview().isEmpty()) { WindowEffects::highlightWindows(winId(), QList<WId>() << winId() << data.windowsToPreview()); } d->preview->setWindowIds(data.windowsToPreview()); d->preview->setHighlightWindows(data.highlightWindows()); d->autohide = data.autohide(); d->source = tipper; if (isVisible()) { d->preview->setInfo(); //kDebug() << "about to check size"; checkSize(); } }
bool isValidSudoku(vector<vector<char> >& bor) { if (!checkSize(bor)) return false; if (!checkEachRow(bor)) return false; if (!checkEachCol(bor)) return false; if (!checkSubBox(bor)) return false; return true; }
void run() { create(); BSONObjSetDefaultOrder keys; id().getKeysFromObject( BSON( "b" << 1 ), keys ); checkSize( 1, keys ); assertEquals( nullObj(), *keys.begin() ); }
//! @brief Sets the size of the system from the number of vertices in the graph. int XC::BandArpackSOE::setSize(Graph &theGraph) { int result = 0; size= checkSize(theGraph); // determine the number of superdiagonals and subdiagonals theGraph.getBand(numSubD,numSuperD); const int newSize = size * (2*numSubD + numSuperD +1); if(newSize > A.Size()) A.resize(newSize); A.Zero(); factored = false; // invoke setSize() on the XC::Solver EigenSolver *theSolvr = this->getSolver(); int solverOK = theSolvr->setSize(); if(solverOK < 0) { std::cerr << "WARNING: BandArpackSOE::setSize :"; std::cerr << " solver failed setSize()\n"; return solverOK; } return result; }
void run() { create(); BSONObjSetDefaultOrder keys; id().getKeysFromObject( fromjson( "{a:[{b:[2]}]}" ), keys ); checkSize( 1, keys ); assertEquals( BSON( "" << 2 ), *keys.begin() ); }
ArrayData *VectorArray::prepend(CVarRef v, bool copy) { if (UNLIKELY(m_size == m_capacity)) { ZendArray *a = escalateToNonEmptyZendArray(); ArrayData *aa UNUSED = a->prepend(v, false); assert(!aa); return a; } if (UNLIKELY(copy)) { ArrayData *a = UNLIKELY(m_size >= FixedSize && Util::isPowerOfTwo(m_size)) ? // in this case, we would escalate in the capacity check anyway static_cast<ArrayData*>(escalateToNonEmptyZendArray()) : static_cast<ArrayData*>(NEW(VectorArray)(this)); ArrayData *aa UNUSED = a->prepend(v, false); assert(!aa); return a; } checkSize(); for (uint i = m_size; i > 0; i--) { // copying TV's by value, intentionally not refcounting. m_elems[i] = m_elems[i-1]; } tvAsUninitializedVariant(&m_elems[0]).constructValHelper(v); m_size++; // To match PHP-like semantics, the prepend operation resets the array's // internal iterator m_pos = (ssize_t)0; return nullptr; }
ArrayData *VectorArray::lval(int64 k, Variant *&ret, bool copy, bool checkExist /* = false */) { ret = inRange(k, m_size) ? &tvAsVariant(&m_elems[k]) : nullptr; if (ret == nullptr && k != m_size) { ZendArray *a = escalateToZendArray(); a->addLvalImpl(k, &ret, false); return a; } if (LIKELY(!copy)) { if (ret) return nullptr; assert(m_size == k); checkSize(); Variant& v = tvAsUninitializedVariant(&m_elems[k]); v.setUninitNull(); ret = &v; checkInsertIterator((ssize_t)k); m_size++; return nullptr; } if (checkExist && ret && (ret->isReferenced() || ret->isObject())) { return nullptr; } VectorArray *a = NEW(VectorArray)(this); if (ret) { Variant& v = tvAsVariant(&a->m_elems[k]); ret = &v; assert(ret); return a; } assert(m_size == k); a->VectorArray::lvalNew(ret, false); return a; }
void JTextField::contentsModified() { cont_changed = true; notifyStateChanged(); checkSize(); }
bool UndoStack::action(UndoState *state) { redoActions_.clear(); undoActions_.insert(undoActions_.begin(), state); bool needsPopping = checkSize(); // only store maxSize_ amount of actions return needsPopping; }
void CmdQuit::ExecuteIntern() { if (checkSize(1)) { quit(); isQuit = true; } else { isQuit = false; } }
QString PrefsTable::get(int row, int col, const QString& defValue) { checkSize(row, col, defValue); if (m_table[row][col] == "__NOT__SET__") m_table[row].insert(m_table[row].begin()+col, defValue); return (m_table[row][col]); }
//文件切割逻辑 void doIncise() { checkData(); checkSize(); if (mChang) { createFile(); } }
void KMenuBar::resize(int w, int h) { if(block_resize > 0) return; checkSize(w, h); if(size() != QSize(w, h)) QMenuBar::resize(w, h); // kdDebug() << "RS:" << w << ":" << h << ":" << width() << ":" << height() << ":" << minimumWidth() << ":" << minimumHeight() << endl; }
void rpn::multiply() { checkSize(); float num2 = stack.back(); stack.pop_back(); float num1 = stack.back(); stack.pop_back(); stack.push_back(num1 * num2); }
void rpn::add() { checkSize(); float num2 = stack.back(); stack.pop_back(); float num1 = stack.back(); stack.pop_back(); stack.push_back(num1 + num2); }
void* _shmallocFake( size_t size ){ if( ! checkSize( size ) ) return NULL; void* ptr = NULL; try { ptr = myHeap.myHeap.allocate( size ); } catch (boost::interprocess::bad_alloc &ex) { std::cerr << ex.what() << std::endl; } return ptr; }
void rpn::subtract() { checkSize(); float num2 = stack.back(); stack.pop_back(); float num1 = stack.back(); stack.pop_back(); stack.push_back(num1 - num2); }
Descriptor *DescriptorLoop::createDescriptor(int &i, bool returnUnimplemetedDescriptor) { if (!checkSize(Descriptor::getLength(data.getData(i)))) return 0; Descriptor *d=Descriptor::getDescriptor(data+i, domain, returnUnimplemetedDescriptor); if (!d) return 0; i+=d->getLength(); d->CheckParse(); return d; }
void ToolTip::prepareShowing() { // show/hide the preview area d->preview->setVisible(!d->preview->isEmpty()); layout()->activate(); d->preview->setInfo(); //kDebug() << "about to check size"; checkSize(); }