NamedValues::ValueMap NamedValues::GetValueMap() const { ValueMap vmap; auto ientry = m_impl->m_valueEntries.begin(); for ( ; m_impl->m_valueEntries.end() != ientry; ++ ientry ) { const std::string name = ientry->first; Detail::ConstNamedValueRef valueRef( name, &( ientry->second )); vmap.insert( std::make_pair( name, valueRef.AsString() )); } return vmap; }
void WhileObject::writeMem() { shared_ptr<X86Register> reg = program->getFreeRegister(); reg->setSize(8); // TODO check *type != *tagRef() -- already assigned if (type) { reg->assign( type ); program->addInstruction( "text", make_shared<InstrMov>( reg->ref(), tagRef() ) ); type = NULL; // should not be used once assigned a memory location } if (ref) { reg->assign( ref ); program->addInstruction( "text", make_shared<InstrMov>( reg->ref(), valueRef() ) ); ref = NULL; } initialised = true; }
void WhileObject::pushStack() { if ( initialised ) { program->addInstruction( "text", make_shared<InstrPush>( valueRef() ) ); program->addInstruction( "text", make_shared<InstrPush>( tagRef() ) ); } else { if (w_type->nameStr() == "real") { shared_ptr<X86Register> r = program->getFreeRegister(); r->assign(valueDirect()); program->addInstruction( "text", make_shared<InstrPush>( r->ref() ) ); program->addInstruction( "text", make_shared<InstrPush>( tagDirect() ) ); } else { program->addInstruction( "text", make_shared<InstrPush>( valueDirect() ) ); program->addInstruction( "text", make_shared<InstrPush>( tagDirect() ) ); } } }
shared_ptr<X86Reference> WhileObject::valueDirect() { if (ref) return ref; else return valueRef(); }
double MyMoneyMoney::toDouble() const { return valueRef().get_d(); }
QString MyMoneyMoney::formatMoney(const QString& currency, const int prec, bool showThousandSeparator) const { QString res; QString tmpCurrency = currency; int tmpPrec = prec; mpz_class denom = 1; mpz_class value; // if prec == -1 we want the maximum possible but w/o trailing zeroes if (tmpPrec > -1) { while (tmpPrec--) { denom *= 10; } } else { // fix it to a max of 9 digits on the right side for now denom = 1000000000; } // as long as AlkValue::convertDenominator() does not take an // mpz_class as the denominator, we need to use a signed int // and limit the precision to 9 digits (the max we can // present with 31 bits #if 1 signed int d; if (mpz_fits_sint_p(denom.get_mpz_t())) { d = mpz_get_si(denom.get_mpz_t()); } else { d = 1000000000; } value = static_cast<const MyMoneyMoney>(convertDenominator(d)).valueRef().get_num(); #else value = static_cast<const MyMoneyMoney>(convertDenominator(denom)).valueRef().get_num(); #endif // Once we really support multiple currencies then this method will // be much better than using KGlobal::locale()->formatMoney. bool bNegative = false; mpz_class left = value / static_cast<MyMoneyMoney>(convertDenominator(d)).valueRef().get_den(); mpz_class right = mpz_class((valueRef() - mpq_class(left)) * denom); if (right < 0) { right = -right; bNegative = true; } if (left < 0) { left = -left; bNegative = true; } // convert the integer (left) part to a string res.append(left.get_str().c_str()); // if requested, insert thousand separators every three digits if (showThousandSeparator) { int pos = res.length(); while ((0 < (pos -= 3)) && thousandSeparator() != 0) res.insert(pos, thousandSeparator()); } // take care of the fractional part if (prec > 0 || (prec == -1 && right != 0)) { if (decimalSeparator() != 0) res += decimalSeparator(); QString rs = QString("%1").arg(right.get_str().c_str()); if (prec != -1) rs = rs.rightJustified(prec, '0', true); else { rs = rs.rightJustified(9, '0', true); // no trailing zeroes or decimal separators while (rs.endsWith('0')) rs.truncate(rs.length() - 1); while (rs.endsWith(QChar(decimalSeparator()))) rs.truncate(rs.length() - 1); } res += rs; } signPosition signpos = bNegative ? _negativeMonetarySignPosition : _positiveMonetarySignPosition; QString sign = bNegative ? "-" : ""; switch (signpos) { case ParensAround: res.prepend('('); res.append(')'); break; case BeforeQuantityMoney: res.prepend(sign); break; case AfterQuantityMoney: res.append(sign); break; case BeforeMoney: tmpCurrency.prepend(sign); break; case AfterMoney: tmpCurrency.append(sign); break; } if (!tmpCurrency.isEmpty()) { if (bNegative ? _negativePrefixCurrencySymbol : _positivePrefixCurrencySymbol) { res.prepend(' '); res.prepend(tmpCurrency); } else { res.append(' '); res.append(tmpCurrency); } } return res; }