numeric_t SplitComponent::setAmount(const numeric_t & amount) { doSetAmount(amount); m_pricePerUnit = getAmount() / getInputsUnitsTotal(); //notify that our cells were 'recomputed' ICell* pCell = NULL; foreach(pCell, m_cells) pCell->notify(); const numeric_t & myAmount = getAmount(); Q_ASSERT(compareNumeric(getTotalValue(this), myAmount)); //cells sum should match return myAmount; }
cv::Mat SmartBlurFilter::computeBlur(cv::Mat inputMat, int threshold) { cv::Mat blurMat; // size base on picture size cv::GaussianBlur(inputMat, blurMat, cv::Size(BLUR_KERNEL, BLUR_KERNEL), 0); //cv::medianBlur(inputMat, blurMat, 5); //cv::blur(inputMat, blurMat, cv::Size(5,5)); for (int j = PADDING; j <hsvMat.rows - PADDING; j++) { for (int i = PADDING; i < hsvMat.cols - PADDING; i++) { int h = hsvMat.at<cv::Vec3b>(j, i)[0]; int s = hsvMat.at<cv::Vec3b>(j, i)[1]; if (h > 90 && h < 130 && s > 30 && s < 180) { // FACE cv::Rect rect(i-HALF_WINDOWSIZE, j-HALF_WINDOWSIZE, WINDOWSIZE, WINDOWSIZE); cv::Mat roiMat = inputMat(rect); float rms = rmsError(roiMat); float amt = getAmount(rms, threshold); inputMat.at<cv::Vec3b>(j,i) = lerpPixel(inputMat.at<cv::Vec3b>(j,i), blurMat.at<cv::Vec3b>(j,i), amt); } } } return inputMat; }
void ConsumerAction(void* info) { struct thInfo* thinfo = (struct thInfo*) info; //Consume delay(100,10); thinfo->persist->itemCount = thinfo->persist->itemCount - 1; fprintf(stderr,"-"); fflush(stderr); setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1); if(getAmount(&thinfo->flags) == 0) { fprintf(stderr,"&(%d)", cCount); fflush(stderr); } }
void ProducerAction(void* info) { struct thInfo* thinfo = (struct thInfo*) info; //Produce delay(100,10); thinfo->persist->itemCount = thinfo->persist->itemCount + 1; fprintf(stderr,"+"); fflush(stderr); setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1); if(getAmount(&thinfo->flags) == 0) { fprintf(stderr,"$(%d)", pCount); fflush(stderr); } }
// Re-apply the changes in selection, colour and amount on a fresh palette void redraw() { pal_preview->setPalette(palette); pal_preview->getPalette().tint(getColour(), getAmount(), pal_preview->getSelectionStart(), pal_preview->getSelectionEnd()); pal_preview->draw(); }
variant_t SplitComponent::getDescription() const { return QString("%1: amount=%2 units=%3 price=%4") .arg(getTitle()) .arg(getAmount()) .arg(getInputsUnitsTotal()) .arg(m_pricePerUnit); }
void* routine(void* info) { struct thInfo* thinfo = (struct thInfo*) info; if(isConsumer(&thinfo->flags)) { CriticalAdd(&cCountLock, &cCount, 1); int r=0; while(r == 0 && getAmount(&thinfo->flags) > 0 ) { r = Consumer(thinfo->persist, ConsumerAction, thinfo); } CriticalAdd(&cCountLock, &cCount, -1); } if(isProducer(&thinfo->flags)) { CriticalAdd(&pCountLock, &pCount, 1); int r=0; while(r == 0 && getAmount(&thinfo->flags) > 0 ) { r = Producer(thinfo->persist, ProducerAction, thinfo); } CriticalAdd(&pCountLock, &pCount, -1); } return NULL; }
// Events void GfxTintDialog::onColourChanged(wxColourPickerEvent& e) { Misc::loadImageFromEntry(gfx_preview->getImage(), entry); wxColour col = cp_colour->GetColour(); gfx_preview->getImage()->tint(getColour(), getAmount(), palette); gfx_preview->updateImageTexture(); gfx_preview->Refresh(); }
int Counters::read(int counterNumber) { if ((counterNumber < 0) || (counterNumber > getAmount())) return -1; return counters[counterNumber - 1]->read(); }
std::size_t NFSv4Protocol::getGroupBegin(std::size_t i) { if(i == PROCEDURES_GROUP) return 0; else if(i == OPERATIONS_GROUP) return ProcEnumNFS4::count_proc; else return getAmount(); }
void GfxTintDialog::onAmountChanged(wxCommandEvent& e) { Misc::loadImageFromEntry(gfx_preview->getImage(), entry); wxColour col = cp_colour->GetColour(); gfx_preview->getImage()->tint(getColour(), getAmount(), palette); gfx_preview->updateImageTexture(); gfx_preview->Refresh(); label_amount->SetLabel(S_FMT("%d%% ", slider_amount->GetValue())); }
void GfxTintDialog::setValues(string col, int val) { wxColour colour(col); cp_colour->SetColour(colour); slider_amount->SetValue(val); label_amount->SetLabel(S_FMT("%d%% ", slider_amount->GetValue())); gfx_preview->getImage()->tint(getColour(), getAmount(), palette); gfx_preview->updateImageTexture(); gfx_preview->Refresh(); }
bool Return::isValid() const { if(!Transaction::isValid()) { return false; } bool valid = (ptrPurchase != NULL && ptrPurchase->getAmount() == getAmount()); valid &= (condition == ptrPurchase->getCondition()); valid &= (ptrPurchase->isBook(ptrBook) && ptrPurchase->isValid()); return valid; }
void TestRecurrentTransaction::testGetAmount() { QFETCH(double, amount); auto account = std::make_shared<PublicAccount>("Test account", .0, ""); auto category = std::make_shared<com::chancho::Category>("Test category", com::chancho::Category::Type::EXPENSE); auto transactionPtr = std::make_shared<com::chancho::Transaction>(account, amount, category); auto recurrentPtr = std::make_shared<com::chancho::RecurrentTransaction>(transactionPtr, std::make_shared<com::chancho::RecurrentTransaction::Recurrence>()); auto qmlTransaction = std::make_shared<com::chancho::tests::PublicRecurrentTransaction>(recurrentPtr); QCOMPARE(amount, qmlTransaction->getAmount()); }
int main ( void ) { // declare and initialize local array char color[MAX_ELEMENTS] = { 'M', 'R', 'O', 'Y', 'L', 'G', 'T', 'B', 'N', 'P', 'K' }; int today[MAX_ELEMENTS] = { 130, 120, 115, 105, 93, 83, 77, 70, 65, 60, 50 }; int group[MAX_ELEMENTS] = { 125, 115, 95, 90, 75, 70, 65, 60, 55, 50, 40 }; int single[MAX_ELEMENTS] = { 125, 127, 110, 100, 88, 78, 72, 65, 60, 55, 45 }; // declare and initialize local variables char runAgain, tempColor, tempType; int mainLoop = 0, tempAmount = 0, subTotal = 0, totalTickets = 0, totalPrice = 0; // welcome user greetingsEarthlings(); while ( mainLoop == 0 ) { runAgain = looper(); if ( runAgain == 'Y' ) { tempColor = getColor( color ); if ( tempColor != 'Q' ) { tempType = getType(); tempAmount = getAmount( tempType ); subTotal = confirmPurchase( tempColor, tempType, tempAmount, today, group, single ); if ( subTotal != 0 ) { totalPrice += subTotal; totalTickets += tempAmount; displayCurrent( &totalTickets, &totalPrice ); } else printf ( "Purchase canceled, returning to main menu.\n\n" ); } else mainLoop = 1; } else if ( runAgain == 'N' ) { mainLoop = 1; } }// end mainLoop printf ( "\nTicket Novice closed by user.\n" ); closeOut( &totalTickets, &totalPrice ); system( "PAUSE" ); return; }// end main
int doWithdraw(Account accountList) { int amounttowithdraw = getAmount(); if (accountList.balance < amounttowithdraw) { eraseDisplay(); displayString(0,"Error, Insufficient Balance"); return -1; } int bills[5] = {0, 0, 0, 0, 0}; billsToOutput(amounttowithdraw, bills); doOutput(bills); return amounttowithdraw; }
double FoodAmount::getAmount(const QSharedPointer<const Unit>& otherUnit) const { if (!otherUnit || !isDefined() || otherUnit->getDimension() == getUnit()->getDimension()) { return Amount<Food, FoodAmount>::getAmount(otherUnit); } else { // Unlike generic Amounts, which cannot meaningfully convert from units in // one dimension to units in another, foods can be specified in multiple // dimensions, allowing for such a conversion. For example, if a food's // entry describes (equivalently) 2 C or 100 g, then it should be possible // to determine how many grams 3 Tbsp of the food weigh. // This is done by first finding the conversion factor from the unit that // the amount is already in to the base unit of the dimension that we // wish to convert to. Then, we do the normal intra-dimension conversion // from the base unit of the target dimension to the ultimately desired unit. FoodAmount baseAmountInSourceDimension = getFood()->getBaseAmount(getUnit()->getDimension()); // baseAmountInSourceDimension must be defined, or something is already // seriously wrong, and there should have been an exception already. FoodAmount baseAmountInTargetDimension = getFood()->getBaseAmount(otherUnit->getDimension()); if (baseAmountInTargetDimension.isDefined()) { double dimensionConversionFactor = baseAmountInTargetDimension.getAmount() / baseAmountInSourceDimension.getAmount(); FoodAmount amountInTargetBaseUnit (getSubstanceNonConst(), getAmount() * dimensionConversionFactor, baseAmountInTargetDimension.getUnit()); return amountInTargetBaseUnit.getAmount(otherUnit); } else { throw std::logic_error("Attempted to get an amount of a food in an inappropriate dimension."); } } }
std::vector<std::string> Resource::printStats() //make a vector of strings of the stats and pass it back { std::vector<std::string> rstr{"Stat:","#vspace10","Value:","#newline"}; std::vector<std::string> istr = {"Name:","#vspace12",getName()}; rstr.insert( rstr.end(), istr.begin(), istr.end() ); rstr.push_back("#newline"); istr = {"Amount:","#vspace12",makeString( getAmount() )}; rstr.insert( rstr.end(), istr.begin(), istr.end() ); rstr.push_back("#newline"); istr = {"Type:","#vspace10",makeString( getType() )}; rstr.insert( rstr.end(), istr.begin(), istr.end() ); rstr.push_back("#newline"); istr = {"X:","#vspace13",makeString( getPosX() )}; rstr.insert( rstr.end(), istr.begin(), istr.end() ); rstr.push_back("#newline"); istr = {"Y:","#vspace13",makeString( getPosY() )}; rstr.insert( rstr.end(), istr.begin(), istr.end() ); rstr.push_back("#newline"); return rstr; }
double FoodAmount::getScaleFactor() const { if (getFood() == NULL) { throw std::logic_error("Attempted to scale the an undefined food."); } // This FoodAmount object represents x amount of food in units of Foo. // In order to scale the nutrients, we need to know what fraction of the entry // for this food this x Foo amount represents. // To determine this, we need to get the base amount for the food entry in terms // of some unit Bar that is of the same dimension as Foo (e.g. Foo and Bar must // both be weights, or both volumes, etc.) // Once the base amount b Bar is determined, then the scale factor y can be computed // as: y = (x Foo) / (b Bar * (Foo/Bar)) // So we approach this by first obtaining baseAmount (b Bar), and then converting // it to be in terms of Foo units by calling baseAmount.getAmount(unit). Then the // division is performed to get the scale factor. const QSharedPointer<const Unit> unit = getUnit(); const QSharedPointer<const Food> food = getFood(); FoodAmount baseAmount = food->getBaseAmount(unit->getDimension()); if (!baseAmount.isDefined()) { throw std::logic_error("Attempted to scale based on a dimension for which " "the food does not have a base amount."); } double scaleFactor = getAmount() / baseAmount.getAmount(unit); if (!bIncludesRefuse) { scaleFactor /= ((100 - getFood()->getPercentRefuse()) / 100); } return scaleFactor; }
void UIReportQuery::slotDetailClicked() { qDebug()<<Q_FUNC_INFO<<tbTransList->currentRow(); QString transType; QString transStatus; QString cardNo; QString amount; QString refNo; QString apprNo; QString operatorNo; int index=tbTransList->currentRow(); if(g_transInfo.auiTransIndex[index]) { // 已撤销 switch(g_transInfo.auiTransIndex[index]) { case SAV_TRANS_NORMAL: transStatus="NORMAL"; break; case SAV_TRANS_NIIVOID: transStatus="VOID"; break; default: transStatus="NULL"; break; } //:- 读取数据保存到NormalTransData memset(&NormalTransData,0,sizeof(NORMAL_TRANS)); int ucResult=xDATA::ReadSubsectionFile(xDATA::DataSaveSaveTrans, index); if(ucResult!=0) { UIMsg::showFileErrMsgWithAutoClose((FileErrIndex)ucResult,g_constantParam.TIMEOUT_ERRMSG); return; } memcpy(&NormalTransData,&g_saveTrans,sizeof(NORMAL_TRANS)); qDebug()<<"step1"; switch(NormalTransData.transType) { case TransMode_CashDeposit: //存钱 transType="Cash Deposit"; break; case TransMode_CashAdvance: //取钱 transType="Cash Advance"; break; case TransMode_AdvanceVoid: //撤销 transType="Cash Advance VOID"; break; case TransMode_DepositVoid: //撤销 transType="Cash Deposit VOID"; break; case TransMode_BalanceInquiry: //查余 transType="Balance Inquiry"; break; case TransMode_CardTransfer: //转账 transType="P2P Transfer"; break; case TransMode_DepositAdjust: //存款调整 transType="Deposit Adjust"; break; case TransMode_AdvanceAdjust: //取款调整 transType="Advance Adjust"; break; default: qDebug()<<"This should not be entered"; break; } qDebug()<<"step2"<<transType; //Card No cardNo=QString::fromAscii((const char *)NormalTransData.aucSourceAcc); // 需要部分隐藏 // Amount unsigned char aucBuf[12]; getAmount(aucBuf, NormalTransData.ulAmount, 2); amount=QString::fromAscii((const char *)aucBuf); // ref & appr refNo=QString::fromAscii((const char *)NormalTransData.aucRefNum); apprNo=QString::fromAscii((const char *)NormalTransData.aucAuthCode); //operator operatorNo=QString::fromAscii((const char *)NormalTransData.aucCashier); // Display the detail UIReportDetail *uiRepDetail=new UIReportDetail(); uiRepDetail->slotSetDetailList(transType,transStatus,cardNo,amount,refNo,apprNo,operatorNo); uiRepDetail->exec(); } }
String toString() const { long len = getLength(); return String( (const char*) getAmount(0, len), len ); }
void fillAmountWith(long startPos, long amount, char fillChar) { ASSERT(0 <= startPos && startPos + amount <= getLength()); memset(getAmount(startPos, amount), fillChar, amount); }
int main(int argc, char* const argv[]) { srand(time(NULL)); int n=10, m=255 & AmountMask, p=GRAIN, c = n*m/4; int gopt; while((gopt = getopt(argc,argv,"n:m:p:c:")) != -1) { switch(gopt) { case 'n': n = atoi(optarg); break; case 'm': m = atoi(optarg); break; case 'p': p = atoi(optarg); break; case 'c': c = atoi(optarg); break; } } if(m > (255 & AmountMask)) { printf("Max m is %d\n", (255 & AmountMask)); } printf("n: %d (thread total nr) m: %d (max production/consumption) p: %d (chance) c: %d (maxItems)\n", n,m,p,c); pthread_t threads[n]; memset(threads, 0, sizeof(threads)); pthread_attr_t pattr; CERRS(pthread_attr_init(&pattr), "pthread attr init failed"); CERRS(pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE), "pthread attr setds failed"); struct thInfo* thinfo; thinfo = (struct thInfo*) malloc(sizeof(struct thInfo)*n); memset(thinfo, 0, n*sizeof(struct thInfo)); struct thInfoPersist* pr = (struct thInfoPersist*)malloc(sizeof(struct thInfoPersist)); CERRS(pthread_mutex_init(&pr->buffer,NULL) != 0, "sem init failed"); CERRS(pthread_cond_init(&pr->notEmpty,NULL) != 0, "cond init failed"); CERRS(pthread_cond_init(&pr->notFull,NULL) != 0, "cond init failed"); CERRS(pthread_mutex_init(&pCountLock,NULL) != 0, "mutex init failed"); CERRS(pthread_mutex_init(&cCountLock,NULL) != 0, "mutex init failed"); pr->maxItems = c; pr->itemCount = 0; int balance = pr->itemCount; cCount=0; pCount=0; for(int i=0; i < n; i++) { setThInfo(&thinfo[i], pr); setAmount(&thinfo[i].flags, rand() % m); if(rand() % (p+GRAIN) > GRAIN ) { printf("Made consumer: "); setConsumer(&thinfo[i].flags, 1); balance = balance - getAmount(&thinfo[i].flags); } else { printf("Made producer: "); setProducer(&thinfo[i].flags, 1); balance = balance + getAmount(&thinfo[i].flags); } printf("am : %u bal: %d IC: %d\n", getAmount(&thinfo[i].flags), balance, pr->itemCount); CERRS(pthread_create(&threads[i], &pattr, &routine, (void*) &thinfo[i]), "pthread creation failed"); } for (int j=0; j < n; j++) { // printf("\n joining. %d p(%d) c(%d)\n", j, pCount, cCount); CERRS(pthread_join(threads[j], NULL), "pthread join failed"); printf("\nnr %d (%s) done\n", j, (isConsumer(&(thinfo[j].flags))) ? "Consumer" : "Producer"); } free(thinfo); free(pr); }
GfxTintDialog::GfxTintDialog(wxWindow* parent, ArchiveEntry* entry, Palette8bit* pal) : wxDialog(parent, -1, "Tint", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) { // Init variables this->entry = entry; this->palette = pal; // Set dialog icon wxIcon icon; icon.CopyFromBitmap(getIcon("t_tint")); SetIcon(icon); // Setup main sizer wxBoxSizer* msizer = new wxBoxSizer(wxVERTICAL); SetSizer(msizer); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); msizer->Add(sizer, 1, wxEXPAND|wxALL, 6); // Add colour chooser wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); sizer->Add(hbox, 0, wxEXPAND|wxALL, 4); cp_colour = new wxColourPickerCtrl(this, -1, wxColour(255, 0, 0)); hbox->Add(new wxStaticText(this, -1, "Colour:"), 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4); hbox->Add(cp_colour, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 8); // Add 'amount' slider hbox = new wxBoxSizer(wxHORIZONTAL); sizer->Add(hbox, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 4); slider_amount = new wxSlider(this, -1, 50, 0, 100); label_amount = new wxStaticText(this, -1, "100%"); hbox->Add(new wxStaticText(this, -1, "Amount:"), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4); hbox->Add(slider_amount, 1, wxEXPAND|wxRIGHT, 4); hbox->Add(label_amount, 0, wxALIGN_CENTER_VERTICAL); // Add preview gfx_preview = new GfxCanvas(this, -1); sizer->Add(gfx_preview, 1, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 4); // Add buttons sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 0, wxEXPAND|wxBOTTOM, 4); // Setup preview gfx_preview->setViewType(GFXVIEW_CENTERED); gfx_preview->setPalette(pal); gfx_preview->SetInitialSize(wxSize(256, 256)); Misc::loadImageFromEntry(gfx_preview->getImage(), entry); wxColour col = cp_colour->GetColour(); gfx_preview->getImage()->tint(getColour(), getAmount(), pal); gfx_preview->updateImageTexture(); // Init layout Layout(); // Bind events cp_colour->Bind(wxEVT_COLOURPICKER_CHANGED, &GfxTintDialog::onColourChanged, this); slider_amount->Bind(wxEVT_SLIDER, &GfxTintDialog::onAmountChanged, this); Bind(wxEVT_SIZE, &GfxTintDialog::onResize, this); // Setup dialog size SetInitialSize(wxSize(-1, -1)); SetMinSize(GetSize()); CenterOnParent(); // Set values label_amount->SetLabel("50% "); }
Item * Item::ItemPickup( Entity *other, qboolean add_to_inventory, qboolean checkautopickup ) { Sentient * sent; Item * item = NULL; str realname; // Query the gameplay manager and see if we should not auto-pickup this item if ( checkautopickup ) { GameplayManager *gpm = GameplayManager::getTheGameplayManager(); if ( gpm->hasProperty(getArchetype(), "noautopickup") ) return NULL; } if ( !Pickupable( other ) ) { return NULL; } sent = ( Sentient * )other; if ( add_to_inventory ) { item = sent->giveItem( model, getAmount(), true ); if ( !item ) return NULL; } else { item = this; } // // make sure to copy over the coolness factor :) // item->coolitem = coolitem; item->cool_dialog = cool_dialog; item->cool_anim = cool_anim; item->coolitemforced = coolitemforced; // // let our sent know they received it // we put this here so we can transfer information from the original item we picked up // if ( !isSubclassOf( Weapon ) || add_to_inventory ) sent->ReceivedItem( item ); realname = GetRandomAlias( "snd_pickup" ); if ( realname.length() > 1 ) sent->Sound( realname, CHAN_ITEM ); if ( !Removable() ) { // leave the item for others to pickup return item; } look_at_me = false; CancelEventsOfType( EV_Item_DropToFloor ); CancelEventsOfType( EV_Item_Respawn ); CancelEventsOfType( EV_FadeOut ); setSolidType( SOLID_NOT ); if ( animate && animate->HasAnim( "pickup" ) ) animate->RandomAnimate( "pickup", EV_Item_PickupDone ); else { if ( !no_remove ) { if ( _missingSkin ) { ChangeSkin( _missingSkin, true ); } else { hideModel(); } if ( !Respawnable() ) PostEvent( EV_Remove, FRAMETIME ); } } if ( Respawnable() ) PostEvent( EV_Item_Respawn, RespawnTime() ); // fire off any pickup_thread's if ( pickup_thread.length() ) { ExecuteThread( pickup_thread ); } if ( item && multiplayerManager.checkFlag( MP_FLAG_INSTANT_ITEMS ) ) { Event *ev; ev = new Event( EV_InventoryItem_Use ); ev->AddEntity( other ); item->ProcessEvent( ev ); } return item; }
void Item::cacheStrings( void ) { G_FindConfigstringIndex( va( "$$PickedUp$$ %d $$Item-%s$$\n", (int)getAmount(), getName().c_str() ), CS_GENERAL_STRINGS, MAX_GENERAL_STRINGS, true ); G_FindConfigstringIndex( va( "$$PickedUp$$ %d $$Item-%s$$s\n", (int)getAmount(), getName().c_str() ), CS_GENERAL_STRINGS, MAX_GENERAL_STRINGS, true ); G_FindConfigstringIndex( va( "$$PickedUpThe$$ $$Item-%s$$\n", getName().c_str() ), CS_GENERAL_STRINGS, MAX_GENERAL_STRINGS, true ); }