mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
SHAMapTreeNode * Remove SHAMapTreeNode::pointer and SHAMapTreeNode::ref. * Add std includes necessary to make the header standalone. * Remove implementation from the SHAMapTreeNode declaration. * Make clear what part of SHAMapTreeNode is: 1) Truly public. 2) Used only by SHAMap. 3) Truly private to SHAMapTreeNode. SHAMapItem * Remove SHAMapItem::pointer and SHAMapItem::ref. * Add std includes necessary to make the header standalone. * Remove implementation from the SHAMapItem declaration. * Make clear what part of SHAMapItem is: 1) Truly public. 2) Used only by SHAMapTreeNode. 3) Truly private to SHAMapItem. SHAMapSyncFilter * Add override for SHAMapSyncFilter-derived functions. * Add missing header. * Default the destructor and delete the SHAMapSyncFilter copy members. SHAMapNodeID * Remove unused mHash member. * Remove unused std::hash and boost::hash specializations. * Remove unused constructor. * Remove unused comparison with uint256. * Remove unused getNodeID (int depth, uint256 const& hash). * Remove virtual specifier from getString(). * Fix operator<= and operator>=. * Document what API is used outside of SHAMap. * Move inline definitions outside of the class declaration. SHAMapMissingNode * Make SHAMapType a enum class to prevent unwanted conversions. * Remove needless ~SHAMapMissingNode() declaration/definition. * Add referenced std includes. SHAMapAddNode * Make SHAMapAddNode (int good, int bad, int duplicate) ctor private. * Move all member function definitions out of the class declaration. * Remove dependence on beast::lexicalCastThrow. * Make getGood() const. * Make get() const. * Add #include <string>. SHAMap * Remove unused enum STATE_MAP_BUCKETS. * Remove unused getCountedObjectName(). * Remove SHAMap::pointer * Remove SHAMap::ref * Remove unused fetchPackEntry_t. * Remove inline member function definitions from class declaration. * Remove unused getTrustedPath. * Remove unused getPath. * Remove unused visitLeavesInternal. * Make SHAMapState an enum class. * Explicitly delete SHAMap copy members. * Reduce access to nested types as much as possible. * Normalize member data names to one style. * Change last of the typedefs to usings under shamap. * Reorder some includes ripple-first, beast-second. * Declare a few constructions from make_shared with auto. * Mark those SHAMap member functions which can be, with const. * Add missing includes
122 lines
3.8 KiB
C++
122 lines
3.8 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <BeastConfig.h>
|
|
#include <ripple/app/ledger/DirectoryEntryIterator.h>
|
|
#include <ripple/basics/Log.h>
|
|
#include <ripple/protocol/JsonFields.h>
|
|
|
|
namespace ripple {
|
|
|
|
/** Get the current ledger entry */
|
|
SLE::pointer DirectoryEntryIterator::getEntry (LedgerEntrySet& les, LedgerEntryType type)
|
|
{
|
|
return les.entryCache (type, mEntryIndex);
|
|
}
|
|
|
|
/** Position the iterator at the first entry
|
|
*/
|
|
bool DirectoryEntryIterator::firstEntry (LedgerEntrySet& les)
|
|
{
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::firstEntry(" <<
|
|
to_string (mRootIndex) << ")";
|
|
mEntry = 0;
|
|
mDirNode.reset ();
|
|
|
|
return nextEntry (les);
|
|
}
|
|
|
|
/** Advance the iterator to the next entry
|
|
*/
|
|
bool DirectoryEntryIterator::nextEntry (LedgerEntrySet& les)
|
|
{
|
|
if (!mDirNode)
|
|
{
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::nextEntry(" <<
|
|
to_string (mRootIndex) << ") need dir node";
|
|
// Are we already at the end
|
|
if (mDirIndex.isZero())
|
|
{
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::nextEntry(" <<
|
|
to_string (mRootIndex) << ") at end";
|
|
return false;
|
|
}
|
|
|
|
// Fetch the current directory
|
|
mDirNode = les.entryCache (ltDIR_NODE, mRootIndex);
|
|
if (!mDirNode)
|
|
{
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::nextEntry("
|
|
<< to_string (mRootIndex) << ") no dir node";
|
|
mEntryIndex.zero();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!les.dirNext (mRootIndex, mDirNode, mEntry, mEntryIndex))
|
|
{
|
|
mDirIndex.zero();
|
|
mDirNode.reset();
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::nextEntry(" <<
|
|
to_string (mRootIndex) << ") now at end";
|
|
return false;
|
|
}
|
|
|
|
WriteLog (lsTRACE, Ledger) << "DirectoryEntryIterator::nextEntry(" <<
|
|
to_string (mRootIndex) << ") now at " << mEntry;
|
|
return true;
|
|
}
|
|
|
|
bool DirectoryEntryIterator::addJson (Json::Value& j) const
|
|
{
|
|
if (mDirNode && (mEntry != 0))
|
|
{
|
|
j[jss::dir_root] = to_string (mRootIndex);
|
|
j[jss::dir_entry] = static_cast<Json::UInt> (mEntry);
|
|
|
|
if (mDirNode)
|
|
j[jss::dir_index] = to_string (mDirIndex);
|
|
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool DirectoryEntryIterator::setJson (Json::Value const& j, LedgerEntrySet& les)
|
|
{
|
|
if (!j.isMember(jss::dir_root) || !j.isMember(jss::dir_index) || !j.isMember(jss::dir_entry))
|
|
return false;
|
|
#if 0 // WRITEME
|
|
Json::Value const& dirRoot = j[jss::dir_root];
|
|
Json::Value const& dirIndex = j[jss::dir_index];
|
|
Json::Value const& dirEntry = j[jss::dir_entry];
|
|
|
|
assert(false); // CAUTION: This function is incomplete
|
|
|
|
mEntry = j[jss::dir_entry].asUInt ();
|
|
|
|
if (!mDirIndex.SetHex(j[jss::dir_index].asString()))
|
|
return false;
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
} // ripple
|