void ApplicationSettings::on_PushButtonDone_pressed(){ //-currentlySelected //setting upconvertToBytesloadRate int uploadRateToSet = convertToBytes(ui->spinBoxUploadRate->value(), currentlySelected); CopyRateController &rc = CopyRateController::instance(); /*----get it into legible form(i.e. every 50ms a part will be sent across network)*/ int convertedRate = uploadRateToSet/20; rc.setUploadRate(convertedRate); //set it in the settings QSettings setting("settings.ini",QSettings::IniFormat); //grouping the settings setting.beginGroup("Network"); QVariant theValue = convertedRate; setting.setValue("uploadRate(Bytes)", theValue); setting.endGroup(); /*----endSetting uploadRate*/ this->close(); }
/** * Output the given list of moviesto the file specified by the outputFile global * variable * @param list The list to output */ void dumpList(MovieNodeType *list) { if (list == NULL) { return; } unsigned char bytes[MAX_BYTES]; fprintf(outputFile, " ------------ LIST ------------\n"); fprintf(outputFile, " -- head: "); convertToBytes((int) list, bytes); dumpBytes(bytes, MAX_BYTES); while (list != NULL) { fprintf(outputFile, " ----------- node addr: "); convertToBytes((int) list, bytes); dumpBytes(bytes, MAX_BYTES); fprintf(outputFile, " ----------- data: "); convertToBytes((int) list->data, bytes); dumpBytes(bytes, MAX_BYTES); fprintf(outputFile, " ----------- -- title: %s\n", list->data->title); fprintf(outputFile, " ----------- -- year: %d\n", list->data->year); fprintf(outputFile, " ----------- -- genre: %s\n", getGenre(list->data->genre)); fprintf(outputFile, " ----------- prev: "); convertToBytes((int) list->prev, bytes); dumpBytes(bytes, MAX_BYTES); fprintf(outputFile, " ----------- next: "); convertToBytes((int) list->next, bytes); dumpBytes(bytes, MAX_BYTES); list = list->next; } fprintf(outputFile, " -------- END OF LIST --------\n"); }
void dumpVar(VarType *var) { unsigned char bytes[MAX_BYTES]; int nBytes; printf(" ---- name: %s\n", var->name); convertToBytes(var->value, bytes); printf(" ---- value: "); nBytes = getNumBytes(var->dType); dumpBytes(bytes, nBytes); if (var->dType == C_INT_PTR) { printf(" ---- ptee: "); convertToBytes((int) *((int*)var->value), bytes); dumpBytes(bytes, MAX_BYTES); } }
void* PageBlock::allocate() { void* mem = nullptr; if (m_currentFreedBlockOffset != 0) { /// allocate from freed blocks/holes uint32_t offset = convertToBytes(m_currentFreedBlockOffset - 1); mem = reinterpret_cast<void*>(m_memory + offset); m_currentFreedBlockOffset = *reinterpret_cast<uint16_t*>(mem); --m_freeBlocksCount; } else { if (m_currentUnallocatedOffset == -1) { return nullptr; } /// allocate from contiguous unallocated area uint32_t offset = convertToBytes(m_currentUnallocatedOffset); mem = reinterpret_cast<void*>(m_memory + offset); ++m_currentUnallocatedOffset; if (convertToBytes(m_currentUnallocatedOffset) >= m_memorySize) { m_currentUnallocatedOffset = -1; } --m_freeBlocksCount; } return mem; }
int ApplicationSettings::convert(int currentValue, Unit from, Unit to){ //convert from anything to bytes. int returnValue = convertToBytes(currentValue, from); //then convert back to unit to if(to == BYTES){ return returnValue; } else if(to == KILOBYTES){ returnValue = returnValue/1000; } else if(to == MEGABYTES){ returnValue = returnValue/1000/1024; } return returnValue; //reason for above((Less code & complexity)) }