/* * Only for insertion of new blocks in file */ int FileBlocks::insert(void* object, unsigned blockNumber, unsigned insertionSize){ // if (blockNumber == 0) throw InvalidOperationException(); char * buffer =(char*) find(&blockNumber); if ( buffer != NULL){ //Block Already exists delete[] buffer; return 3; } delete[] buffer; size_t result; reset(); //seeks EOF result = fseek(pFile, 0, SEEK_END); if (result != 0) return 0; if (insertionSize < (blockSize-1)){ buffer = new char[blockSize]; for (unsigned i = 0; i< insertionSize; i++){ buffer[i] = ((char*)object)[i]; } buffer [insertionSize] ='\0'; for (unsigned i = (insertionSize+1); i< blockSize; i++){ buffer[i] = '#'; } } else buffer = (char*) object; //writes the buffer from blocks beginning result = fwrite ( buffer ,1, (blockSize), pFile ); if (result != (blockSize)) return result; updateSpace(blockNumber, insertionSize); delete[] buffer; fflush ( pFile ); //Operation completed with no error return 1; }
MStatus SargassoNode::compute( const MPlug& plug, MDataBlock& block ) { MStatus stat; if(!m_isInitd) return stat; if(plug == constraintRotateX || plug == constraintRotateY || plug == constraintRotateZ || plug == constraintTranslateX || plug == constraintTranslateY || plug == constraintTranslateZ) { // AHelper::Info<MString>("ov child", plug.name()); // AHelper::Info<unsigned>("ov id", plug.parent().logicalIndex()); unsigned iobject = plug.parent().logicalIndex(); if(iobject > m_numObjects-1) { MGlobal::displayInfo("n constraint is out of bound"); return MS::kSuccess; } if(iobject == 0 && plug == constraintRotateX) { MDataHandle hm = block.inputValue(atargetMesh); updateShape(hm.asMesh()); } if(plug == constraintRotateX) updateSpace(block, iobject); MDataHandle hout = block.outputValue(plug, &stat); if(plug == constraintTranslateX) { hout.set(m_solvedT.x); } else if(plug == constraintTranslateY) { hout.set(m_solvedT.y); } else if(plug == constraintTranslateZ) { hout.set(m_solvedT.z); } else if(plug == constraintRotateX) { hout.set(m_rot[0]); } else if(plug == constraintRotateY) { hout.set(m_rot[1]); } else if(plug == constraintRotateZ) { hout.set(m_rot[2]); } block.setClean( plug ); } else return MS::kUnknownParameter; return MS::kSuccess; }
int FileBlocks::remove(void* object){ unsigned* blockNumber = (unsigned*)object; char* buffer = (char*)find(blockNumber); if ( buffer == NULL ) //Block not found return 0; setFree(*blockNumber); updateSpace(*blockNumber, 0); delete[] buffer; return 1; }
/* * Updates existing block, no matter if is a free block * or an ocuppied block. */ int FileBlocks::update(void* object, unsigned blockNumber, unsigned updateSize){ // if (blockNumber == 0) throw InvalidOperationException(); char * buffer =(char*) (find(&blockNumber)); if (!buffer) //Block not found return 0; delete[] buffer; size_t result; unsigned offset = (blockNumber * (blockSize)); reset(); //Seeks blocks beginning result = fseek(pFile, offset, SEEK_SET); if (result != 0) return 0; if (updateSize < (blockSize)) { buffer = new char[blockSize]; for (unsigned i = 0; i < updateSize; i++) { buffer[i] = ((char*) (object))[i]; } buffer[updateSize] = '\0'; for (unsigned i = (updateSize + 1); i < blockSize; i++) { buffer[i] = '#'; } } else buffer = (char*) (object); //writes the buffer from blocks beginning result = fwrite(buffer, 1, (blockSize), pFile); if (result != (blockSize)) return 0; updateSpace(blockNumber, updateSize); delete[] buffer; if (result != blockSize) return 0; return 1; }
void FileBlocks::deserialize(){ unsigned* buffer = new unsigned[(blockSize / 4)]; fread(buffer, 4, ((blockSize/4)-1), f_space); unsigned i = 0; unsigned block = 0; while (buffer[i] <= blockSize){ updateSpace(block,buffer[i]); if(buffer[i] == 4095) setFree(block); block++; i++; } delete[] buffer; rewind(f_space); }