Make is_set_bit a universal template function

This commit is contained in:
Nik Bougalis
2014-04-14 21:21:19 -07:00
committed by Vinnie Falco
parent feb88c4f7f
commit 2ed8edc19d
17 changed files with 107 additions and 95 deletions

View File

@@ -41,8 +41,8 @@ public:
explicit
Options (std::uint32_t tx_flags)
: sell (isSetBit (tx_flags, tfSell))
, passive (isSetBit (tx_flags, tfPassive))
: sell (is_bit_set (tx_flags, tfSell))
, passive (is_bit_set (tx_flags, tfPassive))
{
}

View File

@@ -1019,7 +1019,7 @@ Json::Value Ledger::getJson (int options)
{
Json::Value ledger (Json::objectValue);
bool bFull = isSetBit (options, LEDGER_JSON_FULL);
bool bFull = is_bit_set (options, LEDGER_JSON_FULL);
ScopedLockType sl (mLock);
@@ -1057,7 +1057,7 @@ Json::Value Ledger::getJson (int options)
ledger["closed"] = false;
}
if (mTransactionMap && (bFull || isSetBit (options, LEDGER_JSON_DUMP_TXRP)))
if (mTransactionMap && (bFull || is_bit_set (options, LEDGER_JSON_DUMP_TXRP)))
{
Json::Value txns (Json::arrayValue);
SHAMapTreeNode::TNType type;
@@ -1065,7 +1065,7 @@ Json::Value Ledger::getJson (int options)
for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem (type); !!item;
item = mTransactionMap->peekNextItem (item->getTag (), type))
{
if (bFull || isSetBit (options, LEDGER_JSON_EXPAND))
if (bFull || is_bit_set (options, LEDGER_JSON_EXPAND))
{
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
{
@@ -1099,10 +1099,10 @@ Json::Value Ledger::getJson (int options)
ledger["transactions"] = txns;
}
if (mAccountStateMap && (bFull || isSetBit (options, LEDGER_JSON_DUMP_STATE)))
if (mAccountStateMap && (bFull || is_bit_set (options, LEDGER_JSON_DUMP_STATE)))
{
Json::Value& state = (ledger["accountState"] = Json::arrayValue);
if (bFull || isSetBit (options, LEDGER_JSON_EXPAND))
if (bFull || is_bit_set (options, LEDGER_JSON_EXPAND))
visitStateItems(BIND_TYPE(stateItemFullAppender, std::ref(state), P_1));
else
mAccountStateMap->visitLeaves(BIND_TYPE(stateItemTagAppender, std::ref(state), P_1));

View File

@@ -1527,8 +1527,8 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
// YYY Could skip this if rippling in reverse.
if (saBefore > zero // Sender balance was positive.
&& saBalance <= zero // Sender is zero or negative.
&& isSetBit ((uFlags = sleRippleState->getFieldU32 (sfFlags)), !bSenderHigh ? lsfLowReserve : lsfHighReserve) // Sender reserve is set.
&& !isSetBit (uFlags, !bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)
&& is_bit_set ((uFlags = sleRippleState->getFieldU32 (sfFlags)), !bSenderHigh ? lsfLowReserve : lsfHighReserve) // Sender reserve is set.
&& !is_bit_set (uFlags, !bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)
&& !sleRippleState->getFieldAmount (!bSenderHigh ? sfLowLimit : sfHighLimit) // Sender trust limit is 0.
&& !sleRippleState->getFieldU32 (!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) // Sender quality in is 0.
&& !sleRippleState->getFieldU32 (!bSenderHigh ? sfLowQualityOut : sfHighQualityOut)) // Sender quality out is 0.
@@ -1541,7 +1541,7 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
sleRippleState->setFieldU32 (sfFlags, uFlags & (!bSenderHigh ? ~lsfLowReserve : ~lsfHighReserve)); // Clear reserve flag.
bDelete = !saBalance // Balance is zero.
&& !isSetBit (uFlags, bSenderHigh ? lsfLowReserve : lsfHighReserve); // Receiver reserve is clear.
&& !is_bit_set (uFlags, bSenderHigh ? lsfLowReserve : lsfHighReserve); // Receiver reserve is clear.
}
if (bSenderHigh)
@@ -1644,7 +1644,7 @@ TER LedgerEntrySet::accountSend (const uint160& uSenderID, const uint160& uRecei
{
if (sleSender->getFieldAmount (sfBalance) < saAmount)
{
terResult = isSetBit (mParams, tapOPEN_LEDGER) ? telFAILED_PROCESSING : tecFAILED_PROCESSING;
terResult = is_bit_set (mParams, tapOPEN_LEDGER) ? telFAILED_PROCESSING : tecFAILED_PROCESSING;
}
else
{

View File

@@ -153,7 +153,7 @@ bool PathRequest::isValid (RippleLineCache::ref crCache)
}
else
{
bool includeXRP = !isSetBit (asDst->peekSLE ().getFlags(), lsfDisallowXRP);
bool includeXRP = !is_bit_set (asDst->peekSLE ().getFlags(), lsfDisallowXRP);
boost::unordered_set<uint160> usDestCurrID =
usAccountDestCurrencies (raDstAccount, crCache, includeXRP);

View File

@@ -51,14 +51,14 @@ Json::Value PathState::Node::getJson () const
jvNode["type"] = uFlags;
if (isSetBit (uFlags, STPathElement::typeAccount) || !!uAccountID)
jvFlags.append (!!isSetBit (uFlags, STPathElement::typeAccount) == !!uAccountID ? "account" : "-account");
if (is_bit_set (uFlags, STPathElement::typeAccount) || !!uAccountID)
jvFlags.append (!!is_bit_set (uFlags, STPathElement::typeAccount) == !!uAccountID ? "account" : "-account");
if (isSetBit (uFlags, STPathElement::typeCurrency) || !!uCurrencyID)
jvFlags.append (!!isSetBit (uFlags, STPathElement::typeCurrency) == !!uCurrencyID ? "currency" : "-currency");
if (is_bit_set (uFlags, STPathElement::typeCurrency) || !!uCurrencyID)
jvFlags.append (!!is_bit_set (uFlags, STPathElement::typeCurrency) == !!uCurrencyID ? "currency" : "-currency");
if (isSetBit (uFlags, STPathElement::typeIssuer) || !!uIssuerID)
jvFlags.append (!!isSetBit (uFlags, STPathElement::typeIssuer) == !!uIssuerID ? "issuer" : "-issuer");
if (is_bit_set (uFlags, STPathElement::typeIssuer) || !!uIssuerID)
jvFlags.append (!!is_bit_set (uFlags, STPathElement::typeIssuer) == !!uIssuerID ? "issuer" : "-issuer");
jvNode["flags"] = jvFlags;
@@ -182,12 +182,12 @@ TER PathState::pushNode (
const bool bFirst = vpnNodes.empty ();
const Node& pnPrv = bFirst ? Node () : vpnNodes.back ();
// true, iff node is a ripple account. false, iff node is an offer node.
const bool bAccount = isSetBit (iType, STPathElement::typeAccount);
const bool bAccount = is_bit_set (iType, STPathElement::typeAccount);
// true, iff currency supplied.
// Currency is specified for the output of the current node.
const bool bCurrency = isSetBit (iType, STPathElement::typeCurrency);
const bool bCurrency = is_bit_set (iType, STPathElement::typeCurrency);
// Issuer is specified for the output of the current node.
const bool bIssuer = isSetBit (iType, STPathElement::typeIssuer);
const bool bIssuer = is_bit_set (iType, STPathElement::typeIssuer);
TER terResult = tesSUCCESS;
WriteLog (lsTRACE, RippleCalc) << "pushNode> "
@@ -266,7 +266,7 @@ TER PathState::pushNode (
if (tesSUCCESS == terResult && !vpnNodes.empty ())
{
const Node& pnBck = vpnNodes.back ();
bool bBckAccount = isSetBit (pnBck.uFlags, STPathElement::typeAccount);
bool bBckAccount = is_bit_set (pnBck.uFlags, STPathElement::typeAccount);
if (bBckAccount)
{
@@ -305,8 +305,8 @@ TER PathState::pushNode (
terResult = terNO_ACCOUNT;
}
else if ((isSetBit (sleBck->getFieldU32 (sfFlags), lsfRequireAuth)
&& !isSetBit (sleRippleState->getFieldU32 (sfFlags), (bHigh ? lsfHighAuth : lsfLowAuth)))
else if ((is_bit_set (sleBck->getFieldU32 (sfFlags), lsfRequireAuth)
&& !is_bit_set (sleRippleState->getFieldU32 (sfFlags), (bHigh ? lsfHighAuth : lsfLowAuth)))
&& sleRippleState->getFieldAmount(sfBalance) == zero) // CHECKME
{
WriteLog (lsWARNING, RippleCalc) << "pushNode: delay: can't receive IOUs from issuer without auth.";
@@ -687,7 +687,7 @@ void PathState::setCanonical (
const Node& pnCur = psExpanded.vpnNodes[uNode];
const Node& pnNxt = psExpanded.vpnNodes[uNode + 1];
const bool bCurAccount = isSetBit (pnCur.uFlags, STPathElement::typeAccount);
const bool bCurAccount = is_bit_set (pnCur.uFlags, STPathElement::typeAccount);
bool bSkip = false;
@@ -707,8 +707,8 @@ void PathState::setCanonical (
else
{
// Currently at an offer.
const bool bPrvAccount = isSetBit (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = isSetBit (pnNxt.uFlags, STPathElement::typeAccount);
const bool bPrvAccount = is_bit_set (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = is_bit_set (pnNxt.uFlags, STPathElement::typeAccount);
if (bPrvAccount && bNxtAccount // Offer surrounded by accounts.
&& pnPrv.uCurrencyID != pnNxt.uCurrencyID)
@@ -784,9 +784,9 @@ void PathState::checkNoRipple (
terStatus = terNO_LINE;
}
else if (
isSetBit (sleIn->getFieldU32 (sfFlags),
is_bit_set (sleIn->getFieldU32 (sfFlags),
(secondAccount > firstAccount) ? lsfHighNoRipple : lsfLowNoRipple) &&
isSetBit (sleOut->getFieldU32 (sfFlags),
is_bit_set (sleOut->getFieldU32 (sfFlags),
(secondAccount > thirdAccount) ? lsfHighNoRipple : lsfLowNoRipple))
{
WriteLog (lsINFO, RippleCalc) << "Path violates noRipple constraint between " <<
@@ -810,7 +810,7 @@ void PathState::checkNoRipple (uint160 const& uDstAccountID, uint160 const& uSrc
{
// There's just one link in the path
// We only need to check source-node-dest
if (isSetBit (vpnNodes[0].uFlags, STPathElement::typeAccount) &&
if (is_bit_set (vpnNodes[0].uFlags, STPathElement::typeAccount) &&
(vpnNodes[0].uAccountID != uSrcAccountID) &&
(vpnNodes[0].uAccountID != uDstAccountID))
{
@@ -824,8 +824,8 @@ void PathState::checkNoRipple (uint160 const& uDstAccountID, uint160 const& uSrc
}
// Check source <-> first <-> second
if (isSetBit (vpnNodes[0].uFlags, STPathElement::typeAccount) &&
isSetBit (vpnNodes[1].uFlags, STPathElement::typeAccount) &&
if (is_bit_set (vpnNodes[0].uFlags, STPathElement::typeAccount) &&
is_bit_set (vpnNodes[1].uFlags, STPathElement::typeAccount) &&
(vpnNodes[0].uAccountID != uSrcAccountID))
{
if ((vpnNodes[0].uCurrencyID != vpnNodes[1].uCurrencyID))
@@ -844,8 +844,8 @@ void PathState::checkNoRipple (uint160 const& uDstAccountID, uint160 const& uSrc
// Check second_from_last <-> last <-> destination
size_t s = vpnNodes.size() - 2;
if (isSetBit (vpnNodes[s].uFlags, STPathElement::typeAccount) &&
isSetBit (vpnNodes[s+1].uFlags, STPathElement::typeAccount) &&
if (is_bit_set (vpnNodes[s].uFlags, STPathElement::typeAccount) &&
is_bit_set (vpnNodes[s+1].uFlags, STPathElement::typeAccount) &&
(uDstAccountID != vpnNodes[s+1].uAccountID))
{
if ((vpnNodes[s].uCurrencyID != vpnNodes[s+1].uCurrencyID))
@@ -868,9 +868,9 @@ void PathState::checkNoRipple (uint160 const& uDstAccountID, uint160 const& uSrc
for (int i = 1; i < (vpnNodes.size() - 1); ++i)
{
if (isSetBit (vpnNodes[i-1].uFlags, STPathElement::typeAccount) &&
isSetBit (vpnNodes[i].uFlags, STPathElement::typeAccount) &&
isSetBit (vpnNodes[i+1].uFlags, STPathElement::typeAccount))
if (is_bit_set (vpnNodes[i-1].uFlags, STPathElement::typeAccount) &&
is_bit_set (vpnNodes[i].uFlags, STPathElement::typeAccount) &&
is_bit_set (vpnNodes[i+1].uFlags, STPathElement::typeAccount))
{ // two consecutive account-to-account links
uint160 const& currencyID = vpnNodes[i].uCurrencyID;

View File

@@ -588,7 +588,7 @@ bool Pathfinder::isNoRipple (const uint160& setByID, const uint160& setOnID, con
{
SLE::pointer sleRipple = mLedger->getSLEi (Ledger::getRippleStateIndex (setByID, setOnID, currencyID));
return sleRipple &&
isSetBit (sleRipple->getFieldU32 (sfFlags), (setByID > setOnID) ? lsfHighNoRipple : lsfLowNoRipple);
is_bit_set (sleRipple->getFieldU32 (sfFlags), (setByID > setOnID) ? lsfHighNoRipple : lsfLowNoRipple);
}
// Does this path end on an account-to-account link whose last account
@@ -601,7 +601,7 @@ bool Pathfinder::isNoRippleOut (const STPath& currentPath)
// Last link must be an account
STPathElement const& endElement = *(currentPath.end() - 1);
if (!isSetBit(endElement.getNodeType(), STPathElement::typeAccount))
if (!is_bit_set(endElement.getNodeType(), STPathElement::typeAccount))
return false;
// What account are we leaving?
@@ -640,7 +640,7 @@ void Pathfinder::addLink(
SLE::pointer sleEnd = mLedger->getSLEi(Ledger::getAccountRootIndex(uEndAccount));
if (sleEnd)
{
bool const bRequireAuth = isSetBit(sleEnd->getFieldU32(sfFlags), lsfRequireAuth);
bool const bRequireAuth = is_bit_set(sleEnd->getFieldU32(sfFlags), lsfRequireAuth);
bool const bIsEndCurrency = (uEndCurrency == mDstAmount.getCurrency());
bool const bIsNoRippleOut = isNoRippleOut (currentPath);

View File

@@ -1150,8 +1150,8 @@ TER RippleCalc::calcNodeAccountRev (const unsigned int uNode, PathState& psCur,
PathState::Node& pnNxt = psCur.vpnNodes[uNode == uLast ? uLast : uNode + 1];
// Current is allowed to redeem to next.
const bool bPrvAccount = !uNode || isSetBit (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = uNode == uLast || isSetBit (pnNxt.uFlags, STPathElement::typeAccount);
const bool bPrvAccount = !uNode || is_bit_set (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = uNode == uLast || is_bit_set (pnNxt.uFlags, STPathElement::typeAccount);
const uint160& uCurAccountID = pnCur.uAccountID;
const uint160& uPrvAccountID = bPrvAccount ? pnPrv.uAccountID : uCurAccountID;
@@ -1513,8 +1513,8 @@ TER RippleCalc::calcNodeAccountFwd (
PathState::Node& pnCur = psCur.vpnNodes[uNode];
PathState::Node& pnNxt = psCur.vpnNodes[uNode == uLast ? uLast : uNode + 1];
const bool bPrvAccount = isSetBit (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = isSetBit (pnNxt.uFlags, STPathElement::typeAccount);
const bool bPrvAccount = is_bit_set (pnPrv.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = is_bit_set (pnNxt.uFlags, STPathElement::typeAccount);
const uint160& uCurAccountID = pnCur.uAccountID;
const uint160& uPrvAccountID = bPrvAccount ? pnPrv.uAccountID : uCurAccountID;
@@ -1840,7 +1840,7 @@ TER RippleCalc::calcNodeAccountFwd (
TER RippleCalc::calcNodeFwd (const unsigned int uNode, PathState& psCur, const bool bMultiQuality)
{
const PathState::Node& pnCur = psCur.vpnNodes[uNode];
const bool bCurAccount = isSetBit (pnCur.uFlags, STPathElement::typeAccount);
const bool bCurAccount = is_bit_set (pnCur.uFlags, STPathElement::typeAccount);
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("calcNodeFwd> uNode=%d") % uNode);
@@ -1875,7 +1875,7 @@ TER RippleCalc::calcNodeFwd (const unsigned int uNode, PathState& psCur, const b
TER RippleCalc::calcNodeRev (const unsigned int uNode, PathState& psCur, const bool bMultiQuality)
{
PathState::Node& pnCur = psCur.vpnNodes[uNode];
bool const bCurAccount = isSetBit (pnCur.uFlags, STPathElement::typeAccount);
bool const bCurAccount = is_bit_set (pnCur.uFlags, STPathElement::typeAccount);
TER terResult;
// Do current node reverse.

View File

@@ -59,22 +59,22 @@ public:
// True, Provided auth to peer.
bool getAuth () const
{
return isSetBit (mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth);
return is_bit_set (mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth);
}
bool getAuthPeer () const
{
return isSetBit (mFlags, !mViewLowest ? lsfLowAuth : lsfHighAuth);
return is_bit_set (mFlags, !mViewLowest ? lsfLowAuth : lsfHighAuth);
}
bool getNoRipple () const
{
return isSetBit (mFlags, mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
return is_bit_set (mFlags, mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
}
bool getNoRipplePeer () const
{
return isSetBit (mFlags, !mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
return is_bit_set (mFlags, !mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
}
const STAmount& getBalance () const

View File

@@ -53,20 +53,20 @@ TER AccountSetTransactor::doApply ()
return temINVALID_FLAG;
}
if (bSetRequireAuth && !isSetBit (uFlagsIn, lsfRequireAuth))
if (bSetRequireAuth && !is_bit_set (uFlagsIn, lsfRequireAuth))
{
if (!mEngine->view().dirIsEmpty (Ledger::getOwnerDirIndex (mTxnAccountID)))
{
m_journal.trace << "Retry: Owner directory not empty.";
return isSetBit(mParams, tapRETRY) ? terOWNERS : tecOWNERS;
return is_bit_set(mParams, tapRETRY) ? terOWNERS : tecOWNERS;
}
m_journal.trace << "Set RequireAuth.";
uFlagsOut |= lsfRequireAuth;
}
if (bClearRequireAuth && isSetBit (uFlagsIn, lsfRequireAuth))
if (bClearRequireAuth && is_bit_set (uFlagsIn, lsfRequireAuth))
{
m_journal.trace << "Clear RequireAuth.";
uFlagsOut &= ~lsfRequireAuth;
@@ -82,13 +82,13 @@ TER AccountSetTransactor::doApply ()
return temINVALID_FLAG;
}
if (bSetRequireDest && !isSetBit (uFlagsIn, lsfRequireDestTag))
if (bSetRequireDest && !is_bit_set (uFlagsIn, lsfRequireDestTag))
{
m_journal.trace << "Set lsfRequireDestTag.";
uFlagsOut |= lsfRequireDestTag;
}
if (bClearRequireDest && isSetBit (uFlagsIn, lsfRequireDestTag))
if (bClearRequireDest && is_bit_set (uFlagsIn, lsfRequireDestTag))
{
m_journal.trace << "Clear lsfRequireDestTag.";
uFlagsOut &= ~lsfRequireDestTag;
@@ -104,13 +104,13 @@ TER AccountSetTransactor::doApply ()
return temINVALID_FLAG;
}
if (bSetDisallowXRP && !isSetBit (uFlagsIn, lsfDisallowXRP))
if (bSetDisallowXRP && !is_bit_set (uFlagsIn, lsfDisallowXRP))
{
m_journal.trace << "Set lsfDisallowXRP.";
uFlagsOut |= lsfDisallowXRP;
}
if (bClearDisallowXRP && isSetBit (uFlagsIn, lsfDisallowXRP))
if (bClearDisallowXRP && is_bit_set (uFlagsIn, lsfDisallowXRP))
{
m_journal.trace << "Clear lsfDisallowXRP.";
uFlagsOut &= ~lsfDisallowXRP;
@@ -126,7 +126,7 @@ TER AccountSetTransactor::doApply ()
return temINVALID_FLAG;
}
if ((uSetFlag == asfDisableMaster) && !isSetBit (uFlagsIn, lsfDisableMaster))
if ((uSetFlag == asfDisableMaster) && !is_bit_set (uFlagsIn, lsfDisableMaster))
{
if (!mTxnAccount->isFieldPresent (sfRegularKey))
return tecNO_REGULAR_KEY;
@@ -135,7 +135,7 @@ TER AccountSetTransactor::doApply ()
uFlagsOut |= lsfDisableMaster;
}
if ((uClearFlag == asfDisableMaster) && isSetBit (uFlagsIn, lsfDisableMaster))
if ((uClearFlag == asfDisableMaster) && is_bit_set (uFlagsIn, lsfDisableMaster))
{
m_journal.trace << "Clear lsfDisableMaster.";
uFlagsOut &= ~lsfDisableMaster;

View File

@@ -80,7 +80,7 @@ TER ChangeTransactor::preCheck ()
return temBAD_SRC_ACCOUNT;
}
if (isSetBit (mParams, tapOPEN_LEDGER))
if (is_bit_set (mParams, tapOPEN_LEDGER))
{
m_journal.warning << "Change transaction against open ledger";
return temINVALID;

View File

@@ -731,10 +731,10 @@ TER OfferCreateTransactor::doApply ()
"OfferCreate> " << mTxn.getJson (0);
std::uint32_t const uTxFlags = mTxn.getFlags ();
bool const bPassive = isSetBit (uTxFlags, tfPassive);
bool const bImmediateOrCancel = isSetBit (uTxFlags, tfImmediateOrCancel);
bool const bFillOrKill = isSetBit (uTxFlags, tfFillOrKill);
bool const bSell = isSetBit (uTxFlags, tfSell);
bool const bPassive = is_bit_set (uTxFlags, tfPassive);
bool const bImmediateOrCancel = is_bit_set (uTxFlags, tfImmediateOrCancel);
bool const bFillOrKill = is_bit_set (uTxFlags, tfFillOrKill);
bool const bSell = is_bit_set (uTxFlags, tfSell);
STAmount saTakerPays = mTxn.getFieldAmount (sfTakerPays);
STAmount saTakerGets = mTxn.getFieldAmount (sfTakerGets);
@@ -906,9 +906,9 @@ TER OfferCreateTransactor::doApply ()
"delay: can't receive IOUs from non-existent issuer: " <<
RippleAddress::createHumanAccountID (uPaysIssuerID);
terResult = isSetBit (mParams, tapRETRY) ? terNO_ACCOUNT : tecNO_ISSUER;
terResult = is_bit_set (mParams, tapRETRY) ? terNO_ACCOUNT : tecNO_ISSUER;
}
else if (isSetBit (sleTakerPays->getFieldU32 (sfFlags), lsfRequireAuth))
else if (is_bit_set (sleTakerPays->getFieldU32 (sfFlags), lsfRequireAuth))
{
SLE::pointer sleRippleState (mEngine->entryCache (
ltRIPPLE_STATE,
@@ -923,16 +923,16 @@ TER OfferCreateTransactor::doApply ()
if (!sleRippleState)
{
terResult = isSetBit (mParams, tapRETRY)
terResult = is_bit_set (mParams, tapRETRY)
? terNO_LINE
: tecNO_LINE;
}
else if (!isSetBit (sleRippleState->getFieldU32 (sfFlags), (canonical_gt ? lsfHighAuth : lsfLowAuth)))
else if (!is_bit_set (sleRippleState->getFieldU32 (sfFlags), (canonical_gt ? lsfHighAuth : lsfLowAuth)))
{
m_journal.debug <<
"delay: can't receive IOUs from issuer without auth.";
terResult = isSetBit (mParams, tapRETRY) ? terNO_AUTH : tecNO_AUTH;
terResult = is_bit_set (mParams, tapRETRY) ? terNO_AUTH : tecNO_AUTH;
}
}
}
@@ -940,7 +940,7 @@ TER OfferCreateTransactor::doApply ()
STAmount saPaid;
STAmount saGot;
bool bUnfunded = false;
const bool bOpenLedger = isSetBit (mParams, tapOPEN_LEDGER);
const bool bOpenLedger = is_bit_set (mParams, tapOPEN_LEDGER);
if ((tesSUCCESS == terResult) && !bExpired)
{

View File

@@ -23,9 +23,9 @@ TER PaymentTransactor::doApply ()
{
// Ripple if source or destination is non-native or if there are paths.
std::uint32_t const uTxFlags = mTxn.getFlags ();
bool const bPartialPayment = isSetBit (uTxFlags, tfPartialPayment);
bool const bLimitQuality = isSetBit (uTxFlags, tfLimitQuality);
bool const bNoRippleDirect = isSetBit (uTxFlags, tfNoRippleDirect);
bool const bPartialPayment = is_bit_set (uTxFlags, tfPartialPayment);
bool const bLimitQuality = is_bit_set (uTxFlags, tfLimitQuality);
bool const bNoRippleDirect = is_bit_set (uTxFlags, tfNoRippleDirect);
bool const bPaths = mTxn.isFieldPresent (sfPaths);
bool const bMax = mTxn.isFieldPresent (sfSendMax);
uint160 const uDstAccountID = mTxn.getFieldAccount160 (sfDestination);
@@ -154,7 +154,7 @@ TER PaymentTransactor::doApply ()
// Another transaction could create the account and then this transaction would succeed.
return tecNO_DST;
}
else if (isSetBit (mParams, tapOPEN_LEDGER) && bPartialPayment)
else if (is_bit_set (mParams, tapOPEN_LEDGER) && bPartialPayment)
{
// Make retry work smaller, by rejecting this.
m_journal.trace <<
@@ -211,7 +211,7 @@ TER PaymentTransactor::doApply ()
try
{
bool const openLedger = isSetBit (mParams, tapOPEN_LEDGER);
bool const openLedger = is_bit_set (mParams, tapOPEN_LEDGER);
bool const tooManyPaths = spsPaths.size () > MaxPathSize;
terResult = openLedger && tooManyPaths
@@ -230,7 +230,7 @@ TER PaymentTransactor::doApply ()
bLimitQuality,
bNoRippleDirect, // Always compute for finalizing ledger.
false, // Not standalone, delete unfundeds.
isSetBit (mParams, tapOPEN_LEDGER));
is_bit_set (mParams, tapOPEN_LEDGER));
if (isTerRetry(terResult))
terResult = tecPATH_DRY;

View File

@@ -92,7 +92,7 @@ Transactor::Transactor (
void Transactor::calculateFee ()
{
mFeeDue = STAmount (mEngine->getLedger ()->scaleFeeLoad (
calculateBaseFee (), isSetBit (mParams, tapADMIN)));
calculateBaseFee (), is_bit_set (mParams, tapADMIN)));
}
std::uint64_t Transactor::calculateBaseFee ()
@@ -108,7 +108,7 @@ TER Transactor::payFee ()
return temBAD_AMOUNT;
// Only check fee is sufficient when the ledger is open.
if (isSetBit (mParams, tapOPEN_LEDGER) && saPaid < mFeeDue)
if (is_bit_set (mParams, tapOPEN_LEDGER) && saPaid < mFeeDue)
{
m_journal.trace << "Insufficient fee paid: " <<
saPaid.getText () << "/" << mFeeDue.getText ();
@@ -239,7 +239,7 @@ TER Transactor::preCheck ()
// Consistency: really signed.
if (!mTxn.isKnownGood ())
{
if (mTxn.isKnownBad () || (!isSetBit (mParams, tapNO_CHECK_SIGN) && !mTxn.checkSign (mSigningPubKey)))
if (mTxn.isKnownBad () || (!is_bit_set (mParams, tapNO_CHECK_SIGN) && !mTxn.checkSign (mSigningPubKey)))
{
mTxn.setBad ();
m_journal.warning << "apply: Invalid transaction (bad signature)";

View File

@@ -54,11 +54,11 @@ TER TrustSetTransactor::doApply ()
return temINVALID_FLAG;
}
bool const bSetAuth = isSetBit (uTxFlags, tfSetfAuth);
bool const bSetNoRipple = isSetBit (uTxFlags, tfSetNoRipple);
bool const bClearNoRipple = isSetBit (uTxFlags, tfClearNoRipple);
bool const bSetAuth = is_bit_set (uTxFlags, tfSetfAuth);
bool const bSetNoRipple = is_bit_set (uTxFlags, tfSetNoRipple);
bool const bClearNoRipple = is_bit_set (uTxFlags, tfClearNoRipple);
if (bSetAuth && !isSetBit (mTxnAccount->getFieldU32 (sfFlags), lsfRequireAuth))
if (bSetAuth && !is_bit_set (mTxnAccount->getFieldU32 (sfFlags), lsfRequireAuth))
{
m_journal.trace <<
"Retry: Auth not required.";
@@ -248,19 +248,19 @@ TER TrustSetTransactor::doApply ()
bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
isSetBit (uFlagsOut, lsfLowNoRipple) ||
is_bit_set (uFlagsOut, lsfLowNoRipple) ||
!!saLowLimit || saLowBalance > zero;
bool const bLowReserveClear = !bLowReserveSet;
bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
isSetBit (uFlagsOut, lsfHighNoRipple) ||
is_bit_set (uFlagsOut, lsfHighNoRipple) ||
!!saHighLimit || saHighBalance > zero;
bool const bHighReserveClear = !bHighReserveSet;
bool const bDefault = bLowReserveClear && bHighReserveClear;
bool const bLowReserved = isSetBit (uFlagsIn, lsfLowReserve);
bool const bHighReserved = isSetBit (uFlagsIn, lsfHighReserve);
bool const bLowReserved = is_bit_set (uFlagsIn, lsfLowReserve);
bool const bHighReserved = is_bit_set (uFlagsIn, lsfHighReserve);
bool bReserveIncrease = false;

View File

@@ -127,7 +127,7 @@ TER TransactionEngine::applyTransaction (const SerializedTransaction& txn, Trans
if (isTesSuccess (terResult))
didApply = true;
else if (isTecClaim (terResult) && !isSetBit (params, tapRETRY))
else if (isTecClaim (terResult) && !is_bit_set (params, tapRETRY))
{
// only claim the transaction fee
WriteLog (lsDEBUG, TransactionEngine) << "Reprocessing to only claim fee";
@@ -188,7 +188,7 @@ TER TransactionEngine::applyTransaction (const SerializedTransaction& txn, Trans
Serializer s;
txn.add (s);
if (isSetBit (params, tapOPEN_LEDGER))
if (is_bit_set (params, tapOPEN_LEDGER))
{
if (!mLedger->addTransaction (txID, s))
{
@@ -216,7 +216,7 @@ TER TransactionEngine::applyTransaction (const SerializedTransaction& txn, Trans
mTxnAccount.reset ();
mNodes.clear ();
if (!isSetBit (params, tapOPEN_LEDGER) && isTemMalformed (terResult))
if (!is_bit_set (params, tapOPEN_LEDGER) && isTemMalformed (terResult))
{
// XXX Malformed or failed transaction in closed ledger must bow out.
}

View File

@@ -21,6 +21,7 @@
#define RIPPLE_PLATFORMMACROS_H
#include <functional>
#include "../../beast/beast/cxx14/type_traits.h" // <type_traits>
namespace ripple {
@@ -30,11 +31,22 @@ namespace ripple {
#define P_3 std::placeholders::_3
#define P_4 std::placeholders::_4
template <typename X, typename Y>
inline
std::enable_if_t<
(std::is_integral<X>::value || std::is_enum<X>::value) &&
(std::is_integral<Y>::value || std::is_enum<Y>::value),
bool>
is_bit_set(X const x, Y const y)
{
return (x & y);
}
// VFALCO TODO Clean this stuff up. Remove as much as possible
// DEPRECATED
#define nothing() do {} while (0)
#define NUMBER(x) (sizeof(x)/sizeof((x)[0]))
#define isSetBit(x,y) (!!((x) & (y)))
#define is_bit_set(x,y) (!!((x) & (y)))
} // ripple

View File

@@ -1521,13 +1521,13 @@ private:
if (! getApp().getHashRouter ().addSuppressionPeer (txID, m_shortId, flags))
{
// we have seen this transaction recently
if (isSetBit (flags, SF_BAD))
if (is_bit_set (flags, SF_BAD))
{
charge (Resource::feeInvalidSignature);
return;
}
if (!isSetBit (flags, SF_RETRY))
if (!is_bit_set (flags, SF_RETRY))
return;
}
@@ -2616,7 +2616,7 @@ private:
return;
}
bool needCheck = ! isSetBit (flags, SF_SIGGOOD);
bool needCheck = ! is_bit_set (flags, SF_SIGGOOD);
Transaction::pointer tx =
boost::make_shared<Transaction> (stx, needCheck);
@@ -2629,7 +2629,7 @@ private:
else
getApp().getHashRouter ().setFlag (stx->getTransactionID (), SF_SIGGOOD);
getApp().getOPs ().processTransaction (tx, isSetBit (flags, SF_TRUSTED), false, false);
getApp().getOPs ().processTransaction (tx, is_bit_set (flags, SF_TRUSTED), false, false);
#ifndef TRUST_NETWORK
}