fix: revert all unrelated upstream develop changes from phase-7 PR

Reverts 259 files that carried unrelated upstream changes through the
phase-6 merge: enum class removals (cppcoreguidelines-use-enum-class),
scoped_lock→lock_guard conversions (modernize-use-scoped-lock),
nodestore Backend API changes (void const* key), .clang-tidy config,
test infrastructure deletions, and miscellaneous develop changes.

These changes belong on develop, not in the telemetry PR chain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pratik Mankawde
2026-04-30 16:59:24 +01:00
parent f44b89b99d
commit f4555c80fe
261 changed files with 4172 additions and 1770 deletions

View File

@@ -15,6 +15,7 @@
namespace xrpl {
// DEPRECATED use beast::severities::Severity instead
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LogSeverity {
lsINVALID = -1, // used to indicate an invalid severity
lsTRACE = 0, // Very low-level progress information, details inside
@@ -207,6 +208,8 @@ public:
fromString(std::string const& s);
private:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Maximum line length for log messages.
// If the message exceeds this length it will be truncated with

View File

@@ -131,7 +131,7 @@ public:
* @tparam LockType The type of lock to use
* @return A lock on the mutex and a reference to the protected data
*/
template <template <typename...> typename LockType = std::lock_guard>
template <template <typename...> typename LockType = std::scoped_lock>
Lock<ProtectedDataType const, LockType, MutexType>
lock() const
{
@@ -144,7 +144,7 @@ public:
* @tparam LockType The type of lock to use
* @return A lock on the mutex and a reference to the protected data
*/
template <template <typename...> typename LockType = std::lock_guard>
template <template <typename...> typename LockType = std::scoped_lock>
Lock<ProtectedDataType, LockType, MutexType>
lock()
{

View File

@@ -70,7 +70,7 @@ isPowerOfTen(T value)
struct MantissaRange
{
using rep = std::uint64_t;
enum mantissa_scale { small, large };
enum class mantissa_scale { small, large };
explicit constexpr MantissaRange(mantissa_scale scale_)
: min(getMin(scale_)), log(logTen(min).value_or(-1)), scale(scale_)
@@ -88,9 +88,9 @@ private:
{
switch (scale_)
{
case small:
case mantissa_scale::small:
return 1'000'000'000'000'000ULL;
case large:
case mantissa_scale::large:
return 1'000'000'000'000'000'000ULL;
default:
// Since this can never be called outside a non-constexpr
@@ -384,7 +384,7 @@ public:
root2(Number f);
// Thread local rounding control. Default is to_nearest
enum rounding_mode { to_nearest, towards_zero, downward, upward };
enum class rounding_mode { to_nearest, towards_zero, downward, upward };
static rounding_mode
getround();
// Returns previously set mode
@@ -443,14 +443,14 @@ private:
static thread_local rounding_mode mode_;
// The available ranges for mantissa
constexpr static MantissaRange smallRange{MantissaRange::small};
constexpr static MantissaRange smallRange{MantissaRange::mantissa_scale::small};
static_assert(isPowerOfTen(smallRange.min));
static_assert(smallRange.min == 1'000'000'000'000'000LL);
static_assert(smallRange.max == 9'999'999'999'999'999LL);
static_assert(smallRange.log == 15);
static_assert(smallRange.min < maxRep);
static_assert(smallRange.max < maxRep);
constexpr static MantissaRange largeRange{MantissaRange::large};
constexpr static MantissaRange largeRange{MantissaRange::mantissa_scale::large};
static_assert(isPowerOfTen(largeRange.min));
static_assert(largeRange.min == 1'000'000'000'000'000'000ULL);
static_assert(largeRange.max == internalrep(9'999'999'999'999'999'999ULL));
@@ -759,9 +759,9 @@ to_string(MantissaRange::mantissa_scale const& scale)
{
switch (scale)
{
case MantissaRange::small:
case MantissaRange::mantissa_scale::small:
return "small";
case MantissaRange::large:
case MantissaRange::mantissa_scale::large:
return "large";
default:
throw std::runtime_error("Bad scale");

View File

@@ -92,7 +92,7 @@ class SlabAllocator
std::uint8_t* ret = nullptr; // NOLINT(misc-const-correctness)
{
std::lock_guard const l(m_);
std::scoped_lock const l(m_);
ret = l_;
@@ -121,7 +121,7 @@ class SlabAllocator
{
XRPL_ASSERT(own(ptr), "xrpl::SlabAllocator::SlabBlock::deallocate : own input");
std::lock_guard const l(m_);
std::scoped_lock const l(m_);
// Use memcpy to avoid unaligned UB
// (will optimize to equivalent code)

View File

@@ -166,7 +166,7 @@ public:
private:
SharedPointerType
initialFetch(key_type const& key, std::lock_guard<mutex_type> const& l);
initialFetch(key_type const& key, std::scoped_lock<mutex_type> const& l);
void
collect_metrics();
@@ -266,7 +266,7 @@ private:
typename KeyValueCacheType::map_type& partition,
SweptPointersVector& stuffToSweep,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&);
std::scoped_lock<std::recursive_mutex> const&);
[[nodiscard]] std::thread
sweepHelper(
@@ -275,7 +275,7 @@ private:
typename KeyOnlyCacheType::map_type& partition,
SweptPointersVector&,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&);
std::scoped_lock<std::recursive_mutex> const&);
beast::Journal m_journal;
clock_type& m_clock;

View File

@@ -69,7 +69,7 @@ inline std::size_t
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
size() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache.size();
}
@@ -86,7 +86,7 @@ inline int
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getCacheSize() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache_count;
}
@@ -103,7 +103,7 @@ inline int
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getTrackSize() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache.size();
}
@@ -120,7 +120,7 @@ inline float
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getHitRate()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const total = static_cast<float>(m_hits + m_misses);
return m_hits * (100.0f / std::max(1.0f, total));
}
@@ -138,7 +138,7 @@ inline void
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
clear()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
m_cache.clear();
m_cache_count = 0;
}
@@ -156,7 +156,7 @@ inline void
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
reset()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
m_cache.clear();
m_cache_count = 0;
m_hits = 0;
@@ -177,7 +177,7 @@ inline bool
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
touch_if_exists(KeyComparable const& key)
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const iter(m_cache.find(key));
if (iter == m_cache.end())
{
@@ -212,7 +212,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
auto const start = std::chrono::steady_clock::now();
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
if (m_target_size == 0 || (static_cast<int>(m_cache.size()) <= m_target_size))
{
@@ -269,7 +269,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
// Remove from cache, if !valid, remove from map too. Returns true if
// removed from cache
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto cit = m_cache.find(key);
@@ -309,7 +309,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
// Return canonical value, store if needed, refresh in cache
// Return values: true=we had the data already
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto cit = m_cache.find(key);
@@ -423,7 +423,7 @@ inline SharedPointerType
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
fetch(key_type const& key)
{
std::lock_guard<mutex_type> l(m_mutex);
std::scoped_lock<mutex_type> l(m_mutex);
auto ret = initialFetch(key, l);
if (!ret)
++m_misses;
@@ -474,7 +474,7 @@ inline auto
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
insert(key_type const& key) -> std::enable_if_t<IsKeyCache, ReturnType>
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
clock_type::time_point const now(m_clock.now());
auto [it, inserted] = m_cache.emplace(
std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(now));
@@ -538,7 +538,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
std::vector<key_type> v;
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
v.reserve(m_cache.size());
for (auto const& _ : m_cache)
v.push_back(_.first);
@@ -560,7 +560,7 @@ inline double
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
rate() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const tot = m_hits + m_misses;
if (tot == 0)
return 0;
@@ -582,7 +582,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
fetch(key_type const& digest, Handler const& h)
{
{
std::lock_guard l(m_mutex);
std::scoped_lock l(m_mutex);
if (auto ret = initialFetch(digest, l))
return ret;
}
@@ -591,7 +591,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
if (!sle)
return {};
std::lock_guard l(m_mutex);
std::scoped_lock l(m_mutex);
++m_misses;
auto const [it, inserted] = m_cache.emplace(digest, Entry(m_clock.now(), std::move(sle)));
if (!inserted)
@@ -611,7 +611,7 @@ template <
class Mutex>
inline SharedPointerType
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
initialFetch(key_type const& key, std::lock_guard<mutex_type> const& l)
initialFetch(key_type const& key, std::scoped_lock<mutex_type> const& l)
{
auto cit = m_cache.find(key);
if (cit == m_cache.end())
@@ -655,7 +655,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
beast::insight::Gauge::value_type hit_rate(0);
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const total(m_hits + m_misses);
if (total != 0)
hit_rate = (m_hits * 100) / total;
@@ -681,7 +681,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
typename KeyValueCacheType::map_type& partition,
SweptPointersVector& stuffToSweep,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&)
std::scoped_lock<std::recursive_mutex> const&)
{
return std::thread([&, this]() {
int cacheRemovals = 0;
@@ -761,7 +761,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
typename KeyOnlyCacheType::map_type& partition,
SweptPointersVector&,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&)
std::scoped_lock<std::recursive_mutex> const&)
{
return std::thread([&, this]() {
int cacheRemovals = 0;

View File

@@ -32,7 +32,7 @@ make_seed_pair() noexcept
// state_t& operator=(state_t const&) = delete;
};
static state_t state;
std::lock_guard const lock(state.mutex);
std::scoped_lock const lock(state.mutex);
return {state.dist(state.gen), state.dist(state.gen)};
}

View File

@@ -60,7 +60,7 @@ default_prng()
thread_local beast::xor_shift_engine engine = [] {
std::uint64_t seed = 0;
{
std::lock_guard const lk(m);
std::scoped_lock const lk(m);
std::uniform_int_distribution<std::uint64_t> distribution{1};
seed = distribution(seeder);
}

View File

@@ -83,7 +83,7 @@ public:
void
sample_one(Handler&& handler)
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (m_cancel)
throw std::logic_error("io_latency_probe is canceled");
boost::asio::post(
@@ -98,7 +98,7 @@ public:
void
sample(Handler&& handler)
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (m_cancel)
throw std::logic_error("io_latency_probe is canceled");
boost::asio::post(
@@ -122,14 +122,14 @@ private:
void
addref()
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
++m_count;
}
void
release()
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (--m_count == 0)
m_cond.notify_all();
}
@@ -192,7 +192,7 @@ private:
m_handler(elapsed);
{
std::lock_guard const lock(m_probe->m_mutex);
std::scoped_lock const lock(m_probe->m_mutex);
if (m_probe->m_cancel)
return;
}

View File

@@ -115,7 +115,7 @@ enable_yield_to::spawn(F0&& f, FN&&... fn)
boost::context::fixedsize_stack(2 * 1024 * 1024),
[&](yield_context yield) {
f(yield);
std::lock_guard const lock{m_};
std::scoped_lock const lock{m_};
if (--running_ == 0)
cv_.notify_all();
},

View File

@@ -14,7 +14,7 @@ namespace beast::unit_test {
class selector
{
public:
enum mode_t {
enum class mode_t {
// Run all tests except manual ones
all,
@@ -53,8 +53,8 @@ public:
template <class>
selector::selector(mode_t mode, std::string const& pattern) : mode_(mode), pat_(pattern)
{
if (mode_ == automatch && pattern.empty())
mode_ = all;
if (mode_ == mode_t::automatch && pattern.empty())
mode_ = mode_t::all;
}
template <class>
@@ -63,18 +63,18 @@ selector::operator()(suite_info const& s)
{
switch (mode_)
{
case automatch:
case mode_t::automatch:
// suite or full name
if (s.name() == pat_ || s.full_name() == pat_)
{
mode_ = none;
mode_ = mode_t::none;
return true;
}
// check module
if (pat_ == s.module())
{
mode_ = module;
mode_ = mode_t::module;
library_ = s.library();
return !s.manual();
}
@@ -82,7 +82,7 @@ selector::operator()(suite_info const& s)
// check library
if (pat_ == s.library())
{
mode_ = library;
mode_ = mode_t::library;
return !s.manual();
}
@@ -96,19 +96,19 @@ selector::operator()(suite_info const& s)
return false;
case suite:
case mode_t::suite:
return pat_ == s.name();
case module:
case mode_t::module:
return pat_ == s.module() && !s.manual();
case library:
case mode_t::library:
return pat_ == s.library() && !s.manual();
case none:
case mode_t::none:
return false;
case all:
case mode_t::all:
default:
break;
};
@@ -138,28 +138,28 @@ selector::operator()(suite_info const& s)
inline selector
match_auto(std::string const& name)
{
return selector(selector::automatch, name);
return selector(selector::mode_t::automatch, name);
}
/** Return a predicate that matches all suites not marked manual. */
inline selector
match_all()
{
return selector(selector::all);
return selector(selector::mode_t::all);
}
/** Returns a predicate that matches a specific suite. */
inline selector
match_suite(std::string const& name)
{
return selector(selector::suite, name);
return selector(selector::mode_t::suite, name);
}
/** Returns a predicate that matches all suites in a library. */
inline selector
match_library(std::string const& name)
{
return selector(selector::library, name);
return selector(selector::mode_t::library, name);
}
} // namespace beast::unit_test

View File

@@ -62,6 +62,8 @@ private:
{
using run_time = std::pair<std::string, typename clock_type::duration>;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { max_top = 10 };
std::size_t suites = 0;

View File

@@ -231,7 +231,7 @@ template <class>
void
runner::testcase(std::string const& name)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
// Name may not be empty
BOOST_ASSERT(default_ || !name.empty());
// Forgot to call pass or fail
@@ -247,7 +247,7 @@ template <class>
void
runner::pass()
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_pass();
@@ -258,7 +258,7 @@ template <class>
void
runner::fail(std::string const& reason)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_fail(reason);
@@ -270,7 +270,7 @@ template <class>
void
runner::log(std::string const& s)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_log(s);

View File

@@ -37,7 +37,7 @@ make_reason(String const& reason, char const* file, int line)
class Thread;
enum abort_t { no_abort_on_fail, abort_on_fail };
enum class abort_t { no_abort_on_fail, abort_on_fail };
/** A testsuite class.
@@ -127,7 +127,7 @@ private:
@param abort Determines if suite continues running after a failure.
*/
void
operator()(std::string const& name, abort_t abort = no_abort_on_fail);
operator()(std::string const& name, abort_t abort = abort_t::no_abort_on_fail);
scoped_testcase
operator()(abort_t abort);
@@ -363,14 +363,14 @@ public:
inline void
suite::testcase_t::operator()(std::string const& name, abort_t abort)
{
suite_.abort_ = abort == abort_on_fail;
suite_.abort_ = abort == abort_t::abort_on_fail;
suite_.runner_->testcase(name);
}
inline suite::scoped_testcase
suite::testcase_t::operator()(abort_t abort)
{
suite_.abort_ = abort == abort_on_fail;
suite_.abort_ = abort == abort_t::abort_on_fail;
return {suite_, ss_};
}

View File

@@ -9,6 +9,8 @@ namespace beast {
/** A namespace for easy access to logging severity values. */
namespace severities {
/** Severity level / threshold of a Journal message. */
// Hundreds of usages via logging macros
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Severity {
kAll = 0,

View File

@@ -56,7 +56,7 @@ private:
// a lock. This removes a small timing window that occurs if the
// waiting thread is handling a spurious wakeup when closureCount_
// drops to zero.
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
// Update closureCount_. Notify if stopping and closureCount_ == 0.
if ((--closureCount_ == 0) && waitForClosures_)
@@ -170,7 +170,7 @@ public:
{
std::optional<Substitute<Closure>> ret;
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
if (!waitForClosures_)
ret.emplace(*this, std::forward<Closure>(closure));
@@ -193,7 +193,7 @@ public:
bool
joined() const
{
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
return waitForClosures_;
}
};

View File

@@ -34,7 +34,7 @@ inline void
JobQueue::Coro::yield() const
{
{
std::lock_guard lock(jq_.m_mutex);
std::scoped_lock lock(jq_.m_mutex);
++jq_.nSuspend_;
}
(*yield_)();
@@ -44,7 +44,7 @@ inline bool
JobQueue::Coro::post()
{
{
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = true;
}
@@ -55,7 +55,7 @@ JobQueue::Coro::post()
}
// The coroutine will not run. Clean up running_.
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = false;
cv_.notify_all();
return false;
@@ -65,16 +65,16 @@ inline void
JobQueue::Coro::resume()
{
{
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = true;
}
{
std::lock_guard lk(jq_.m_mutex);
std::scoped_lock lk(jq_.m_mutex);
--jq_.nSuspend_;
}
auto saved = detail::getLocalValues().release();
detail::getLocalValues().reset(&lvs_);
std::lock_guard lock(mutex_);
std::scoped_lock lock(mutex_);
// A late resume() can arrive after the coroutine has already completed.
// This is an expected (if rare) outcome of the race condition documented
// in JobQueue.h:354-377 where post() schedules a resume job before the
@@ -89,7 +89,7 @@ JobQueue::Coro::resume()
}
detail::getLocalValues().release();
detail::getLocalValues().reset(saved);
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = false;
cv_.notify_all();
}
@@ -113,7 +113,7 @@ JobQueue::Coro::expectEarlyExit()
//
// That said, since we're outside the Coro's stack, we need to
// decrement the nSuspend that the Coro's call to yield caused.
std::lock_guard lock(jq_.m_mutex);
std::scoped_lock lock(jq_.m_mutex);
--jq_.nSuspend_;
#ifndef NDEBUG
finished_ = true;

View File

@@ -11,6 +11,8 @@ namespace xrpl {
// Note that this queue should only be used for CPU-bound jobs
// It is primarily intended for signature checking
// Protocol-wide
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum JobType {
// Special type indicating an invalid job - will go away soon.
jtINVALID = -1,

View File

@@ -67,7 +67,7 @@ public:
bool
contains(PublicKey const& nodeId)
{
std::lock_guard const lock(this->mutex_);
std::scoped_lock const lock(this->mutex_);
return table_.contains({.nodeId = nodeId, .description = {}});
}

View File

@@ -55,7 +55,7 @@ public:
void
notify()
{
std::lock_guard const lock{m_mutex};
std::scoped_lock const lock{m_mutex};
++m_count;
m_cond.notify_one();
}
@@ -76,7 +76,7 @@ public:
bool
try_wait()
{
std::lock_guard lock{m_mutex};
std::scoped_lock lock{m_mutex};
if (m_count == 0)
return false;
--m_count;

View File

@@ -107,7 +107,7 @@ namespace Json {
class Writer
{
public:
enum CollectionType { array, object };
enum class CollectionType { array, object };
explicit Writer(Output const& output);
Writer(Writer&&) noexcept;

View File

@@ -70,6 +70,8 @@ public:
static constexpr unsigned nest_limit{25};
private:
// 53 files, protocol-wide
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TokenType {
tokenEndOfStream = 0,
tokenObjectBegin,

View File

@@ -15,6 +15,8 @@ namespace Json {
/** \brief Type of the value held by a Value object.
*/
// Used throughout JSON layer
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ValueType {
nullValue = 0, ///< 'null' value
intValue, ///< signed integer value
@@ -147,6 +149,8 @@ private:
class CZString
{
public:
// Stored as int field, implicit conversion
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
CZString(int index);
CZString(char const* cstr, DuplicationPolicy allocate);
@@ -471,6 +475,8 @@ operator>=(Value const& x, Value const& y)
class ValueAllocator
{
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { unknown = (unsigned)-1 };
virtual ~ValueAllocator() = default;

View File

@@ -7,6 +7,8 @@
namespace xrpl {
// Bitwise flag enum with existing operator overloads
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ApplyFlags : std::uint32_t {
tapNONE = 0x00,

View File

@@ -31,7 +31,7 @@ public:
bool
startWork(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto it = map_.find(seq);
@@ -54,7 +54,7 @@ public:
void
finishWork(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
map_.erase(seq);
await_.notify_all();
@@ -64,7 +64,7 @@ public:
bool
pending(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
return map_.contains(seq);
}
@@ -117,7 +117,7 @@ public:
std::map<LedgerIndex, bool>
getSnapshot() const
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
return map_;
}

View File

@@ -28,7 +28,7 @@ reduceOffer(auto const& amount)
static Number const reducedOfferPct(9999, -4);
// Make sure the result is always less than amount or zero.
NumberRoundModeGuard const mg(Number::towards_zero);
NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero);
return amount * reducedOfferPct;
}
@@ -180,7 +180,7 @@ getAMMOfferStartWithTakerGets(
if (targetQuality.rate() == beast::zero)
return std::nullopt;
NumberRoundModeGuard const mg(Number::to_nearest);
NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest);
auto const f = feeMult(tfee);
auto const a = 1;
auto const b = pool.in * (1 - 1 / f) / targetQuality.rate() - 2 * pool.out;
@@ -202,7 +202,7 @@ getAMMOfferStartWithTakerGets(
// Round downward to minimize the offer and to maximize the quality.
// This has the most impact when takerGets is XRP.
auto const takerGets =
toAmount<TOut>(getAsset(pool.out), nTakerGetsProposed, Number::downward);
toAmount<TOut>(getAsset(pool.out), nTakerGetsProposed, Number::rounding_mode::downward);
return TAmounts<TIn, TOut>{swapAssetOut(pool, takerGets, tfee), takerGets};
};
@@ -247,7 +247,7 @@ getAMMOfferStartWithTakerPays(
if (targetQuality.rate() == beast::zero)
return std::nullopt;
NumberRoundModeGuard const mg(Number::to_nearest);
NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest);
auto const f = feeMult(tfee);
auto const& a = f;
auto const b = pool.in * (1 + f);
@@ -269,7 +269,7 @@ getAMMOfferStartWithTakerPays(
// Round downward to minimize the offer and to maximize the quality.
// This has the most impact when takerPays is XRP.
auto const takerPays =
toAmount<TIn>(getAsset(pool.in), nTakerPaysProposed, Number::downward);
toAmount<TIn>(getAsset(pool.in), nTakerPaysProposed, Number::rounding_mode::downward);
return TAmounts<TIn, TOut>{takerPays, swapAssetIn(pool, takerPays, tfee)};
};
@@ -341,7 +341,8 @@ changeSpotPriceQuality(
<< " " << to_string(pool.out) << " " << quality << " " << tfee;
return std::nullopt;
}
auto const takerPays = toAmount<TIn>(getAsset(pool.in), nTakerPays, Number::upward);
auto const takerPays =
toAmount<TIn>(getAsset(pool.in), nTakerPays, Number::rounding_mode::upward);
// should not fail
if (auto amounts = TAmounts<TIn, TOut>{takerPays, swapAssetIn(pool, takerPays, tfee)};
Quality{amounts} < quality &&
@@ -447,32 +448,32 @@ swapAssetIn(TAmounts<TIn, TOut> const& pool, TIn const& assetIn, std::uint16_t t
// fee
saveNumberRoundMode const _{Number::getround()};
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const numerator = pool.in * pool.out;
auto const fee = getFee(tfee);
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const denom = pool.in + assetIn * (1 - fee);
if (denom.signum() <= 0)
return toAmount<TOut>(getAsset(pool.out), 0);
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const ratio = numerator / denom;
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const swapOut = pool.out - ratio;
if (swapOut.signum() < 0)
return toAmount<TOut>(getAsset(pool.out), 0);
return toAmount<TOut>(getAsset(pool.out), swapOut, Number::downward);
return toAmount<TOut>(getAsset(pool.out), swapOut, Number::rounding_mode::downward);
}
return toAmount<TOut>(
getAsset(pool.out),
pool.out - (pool.in * pool.out) / (pool.in + assetIn * feeMult(tfee)),
Number::downward);
Number::rounding_mode::downward);
}
/** Swap assetOut out of the pool and swap in a proportional amount
@@ -509,36 +510,36 @@ swapAssetOut(TAmounts<TIn, TOut> const& pool, TOut const& assetOut, std::uint16_
saveNumberRoundMode const _{Number::getround()};
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const numerator = pool.in * pool.out;
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const denom = pool.out - assetOut;
if (denom.signum() <= 0)
{
return toMaxAmount<TIn>(getAsset(pool.in));
}
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const ratio = numerator / denom;
auto const numerator2 = ratio - pool.in;
auto const fee = getFee(tfee);
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const feeMult = 1 - fee;
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const swapIn = numerator2 / feeMult;
if (swapIn.signum() < 0)
return toAmount<TIn>(getAsset(pool.in), 0);
return toAmount<TIn>(getAsset(pool.in), swapIn, Number::upward);
return toAmount<TIn>(getAsset(pool.in), swapIn, Number::rounding_mode::upward);
}
return toAmount<TIn>(
getAsset(pool.in),
((pool.in * pool.out) / (pool.out - assetOut) - pool.in) / feeMult(tfee),
Number::upward);
Number::rounding_mode::upward);
}
/** Return square of n.
@@ -597,7 +598,8 @@ getLPTokenRounding(IsDeposit isDeposit)
{
// Minimize on deposit, maximize on withdraw to ensure
// AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance
return isDeposit == IsDeposit::Yes ? Number::downward : Number::upward;
return isDeposit == IsDeposit::Yes ? Number::rounding_mode::downward
: Number::rounding_mode::upward;
}
inline Number::rounding_mode
@@ -605,7 +607,8 @@ getAssetRounding(IsDeposit isDeposit)
{
// Maximize on deposit, minimize on withdraw to ensure
// AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance
return isDeposit == IsDeposit::Yes ? Number::upward : Number::downward;
return isDeposit == IsDeposit::Yes ? Number::rounding_mode::upward
: Number::rounding_mode::downward;
}
} // namespace detail

View File

@@ -19,7 +19,7 @@ loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval);
inline Number
roundPeriodicPayment(Asset const& asset, Number const& periodicPayment, std::int32_t scale)
{
return roundToAsset(asset, periodicPayment, scale, Number::upward);
return roundToAsset(asset, periodicPayment, scale, Number::rounding_mode::upward);
}
/* Represents the breakdown of amounts to be paid and changes applied to the

View File

@@ -21,13 +21,13 @@ namespace xrpl {
//------------------------------------------------------------------------------
/** Controls the treatment of frozen account balances */
enum FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN };
enum class FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN };
/** Controls the treatment of unauthorized MPT balances */
enum AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED };
enum class AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED };
/** Controls whether to include the account's full spendable balance */
enum SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE };
enum class SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE };
enum class WaiveTransferFee : bool { No = false, Yes };
@@ -135,7 +135,7 @@ accountHolds(
AccountID const& issuer,
FreezeHandling zeroIfFrozen,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -144,7 +144,7 @@ accountHolds(
Issue const& issue,
FreezeHandling zeroIfFrozen,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -154,7 +154,7 @@ accountHolds(
FreezeHandling zeroIfFrozen,
AuthHandling zeroIfUnauthorized,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -164,7 +164,7 @@ accountHolds(
FreezeHandling zeroIfFrozen,
AuthHandling zeroIfUnauthorized,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
// Returns the amount an account can spend of the currency type saDefault, or
// returns saDefault if this account is the issuer of the currency in

View File

@@ -76,16 +76,16 @@ public:
If the object is not found or an error is encountered, the
result will indicate the condition.
@note This will be called concurrently.
@param key A pointer to the key data.
@param hash The hash of the object.
@param pObject [out] The created object if successful.
@return The result of the operation.
*/
virtual Status
fetch(void const* key, std::shared_ptr<NodeObject>* pObject) = 0;
fetch(uint256 const& hash, std::shared_ptr<NodeObject>* pObject) = 0;
/** Fetch a batch synchronously. */
virtual std::pair<std::vector<std::shared_ptr<NodeObject>>, Status>
fetchBatch(std::vector<uint256 const*> const& hashes) = 0;
fetchBatch(std::vector<uint256> const& hashes) = 0;
/** Store a single object.
Depending on the implementation this may happen immediately

View File

@@ -9,7 +9,7 @@
namespace xrpl {
/** The types of node objects. */
enum NodeObjectType : std::uint32_t {
enum class NodeObjectType : std::uint32_t {
hotUNKNOWN = 0,
hotLEDGER = 1,
hotACCOUNT_NODE = 3,

View File

@@ -6,6 +6,8 @@
namespace xrpl::NodeStore {
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// This is only used to pre-allocate the array for
// batch objects and does not affect the amount written.
@@ -20,7 +22,7 @@ enum {
};
/** Return codes from Backend operations. */
enum Status {
enum class Status {
ok = 0,
notFound = 1,
dataCorrupt = 2,

View File

@@ -127,7 +127,7 @@ nodeobject_decompress(void const* in, std::size_t in_size, BufferFactory&& bf)
ostream os(out, result.second);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
write<std::uint32_t>(os, static_cast<std::uint32_t>(HashPrefix::innerNode));
if (mask == 0)
Throw<std::runtime_error>("nodeobject codec v1: empty inner node");
@@ -173,7 +173,7 @@ nodeobject_decompress(void const* in, std::size_t in_size, BufferFactory&& bf)
ostream os(out, result.second);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
write<std::uint32_t>(os, static_cast<std::uint32_t>(HashPrefix::innerNode));
write(os, is(512), 512);
break;
@@ -307,7 +307,7 @@ filter_inner(void* in, std::size_t in_size)
ostream os(in, 9);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
}
}
}

View File

@@ -17,6 +17,8 @@ namespace xrpl {
//
// Please only append to this table. Do not "fill-in" gaps and do not re-use
// or repurpose error code values.
// Protocol-wide, 50+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum error_code_i {
// -1 represents codes not listed in this enumeration
rpcUNKNOWN = -1,
@@ -148,6 +150,8 @@ enum error_code_i {
These values need to remain stable.
*/
// Protocol-wide, 50+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum warning_code_i {
warnRPC_UNSUPPORTED_MAJORITY = 1001,
warnRPC_AMENDMENT_BLOCKED = 1002,

View File

@@ -29,6 +29,8 @@ namespace xrpl {
@ingroup protocol
*/
// Protocol-critical, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LedgerEntryType : std::uint16_t {
#pragma push_macro("LEDGER_ENTRY")
@@ -214,6 +216,8 @@ enum LedgerEntryType : std::uint16_t {
#define TO_VALUE(name, value) name = (value),
#define NULL_NAME(name, values) values
#define NULL_OUTPUT(name, value)
// Bitwise flag enum
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
// Create getter functions for each set of flags using Meyer's singleton pattern.

View File

@@ -66,8 +66,7 @@ struct MultiApiJson
a[key] = v;
}
// Intentionally not using class enum here, MultivarJson is scope enough
enum IsMemberResult : int { none = 0, some, all };
enum class IsMemberResult : int { none = 0, some, all };
[[nodiscard]] IsMemberResult
isMember(char const* key) const
@@ -80,8 +79,8 @@ struct MultiApiJson
}
if (count == 0)
return none;
return count < size ? some : all;
return IsMemberResult::none;
return count < size ? IsMemberResult::some : IsMemberResult::all;
}
static constexpr struct visitor_t final

View File

@@ -16,6 +16,8 @@ namespace xrpl {
* conflicts with TxType, the GranularPermissionType is always set to a value
* greater than the maximum value of uint16.
*/
// Macro-generated, complex
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum GranularPermissionType : std::uint32_t {
#pragma push_macro("PERMISSION")
#undef PERMISSION
@@ -28,6 +30,9 @@ enum GranularPermissionType : std::uint32_t {
#pragma pop_macro("PERMISSION")
};
// Injected bare enumerators (xrpl::delegable / xrpl::notDelegable) are required by preprocessor
// tricks in tests and macro-generated code; enum class would break that.
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Delegation { delegable, notDelegable };
class Permission

View File

@@ -33,7 +33,7 @@ or may not hold a value. For things not guaranteed to exist,
you use `x[~sfFoo]` because you want such a container. It
avoids having to look something up twice, once just to see if
it exists and a second time to get/set its value.
([Real example](https://github.com/XRPLF/rippled/blob/35f4698aed5dce02f771b34cfbb690495cb5efcc/src/ripple/app/tx/impl/PayChan.cpp#L229-L236))
([Real example](https://github.com/XRPLF/rippled/blob/35f4698aed5dce02f771b34cfbb690495cb5efcc/src/xrpld/app/tx/impl/PayChan.cpp#L229-L236))
The source of this "type magic" is in
[SField.h](./SField.h#L296-L302).

View File

@@ -87,6 +87,8 @@ class STCurrency;
#define TO_ENUM(name, value) name = (value),
#define TO_MAP(name, value) {#name, value},
// Protocol infrastructure, 39+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SerializedTypeID { XMACRO(TO_ENUM) };
static std::map<std::string, int> const sTypeMap = {XMACRO(TO_MAP)};
@@ -125,6 +127,8 @@ field_code(int id, int index)
class SField
{
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
sMD_Never = 0x00,
sMD_ChangeOrig = 0x01, // original value when it changes

View File

@@ -11,6 +11,8 @@
namespace xrpl {
/** Kind of element in each entry of an SOTemplate. */
// 2026 usages, 129 files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SOEStyle {
soeINVALID = -1,
soeREQUIRED = 0, // required
@@ -20,7 +22,8 @@ enum SOEStyle {
// constructed with STObject::makeInnerObject()
};
/** Amount fields that can support MPT */
// Part of a Python-parsed DSL (transactions.macro); bare enumerator names required by the parser
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SOETxMPTIssue { soeMPTNone, soeMPTSupported, soeMPTNotSupported };
//------------------------------------------------------------------------------

View File

@@ -319,7 +319,7 @@ STAmount::STAmount(
: STBase(name), mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative)
{
// mValue is uint64, but needs to fit in the range of int64
if (Number::getMantissaScale() == MantissaRange::small)
if (Number::getMantissaScale() == MantissaRange::mantissa_scale::small)
{
XRPL_ASSERT(
mValue <= std::numeric_limits<std::int64_t>::max(),

View File

@@ -18,6 +18,8 @@ struct JsonOptions
using underlying_t = unsigned int;
underlying_t value;
// Bitwise flags with operator~
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum values : underlying_t {
// clang-format off
none = 0b0000'0000,

View File

@@ -413,9 +413,9 @@ public:
class FieldErr;
private:
enum WhichFields : bool {
enum class WhichFields : bool {
// These values are carefully chosen to do the right thing if passed
// to SField::shouldInclude (bool)
// to SField::shouldInclude (bool) via static_cast<bool>
omitSigningFields = false,
withAllFields = true
};
@@ -987,7 +987,7 @@ STObject::isFree() const
inline void
STObject::addWithoutSigningFields(Serializer& s) const
{
add(s, omitSigningFields);
add(s, WhichFields::omitSigningFields);
}
// VFALCO NOTE does this return an expensive copy of an object with a
@@ -997,7 +997,7 @@ inline Serializer
STObject::getSerializer() const
{
Serializer s;
add(s, withAllFields);
add(s, WhichFields::withAllFields);
return s;
}

View File

@@ -25,6 +25,8 @@ class STPathElement final : public CountedObject<STPathElement>
std::size_t hash_value_;
public:
// Bitwise values (typeCurrency | typeMPT)
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Type {
typeNone = 0x00,
typeAccount = 0x01, // Rippling through an account (vs taking an offer).

View File

@@ -35,7 +35,7 @@ namespace xrpl {
class SeqProxy
{
public:
enum Type : std::uint8_t { seq = 0, ticket };
enum class Type : std::uint8_t { seq = 0, ticket };
private:
std::uint32_t value_;
@@ -67,13 +67,13 @@ public:
[[nodiscard]] constexpr bool
isSeq() const
{
return type_ == seq;
return type_ == Type::seq;
}
[[nodiscard]] constexpr bool
isTicket() const
{
return type_ == ticket;
return type_ == Type::ticket;
}
// Occasionally it is convenient to be able to increase the value_

View File

@@ -19,6 +19,8 @@ using TERUnderlyingType = int;
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TELcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -50,6 +52,8 @@ enum TELcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEMcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -126,6 +130,8 @@ enum TEMcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEFcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -170,6 +176,8 @@ enum TEFcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TERcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -214,6 +222,8 @@ enum TERcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEScodes : TERUnderlyingType {
// Note: Exact number must stay stable. This code is stored by value
// in metadata for historic transactions.
@@ -229,6 +239,8 @@ enum TEScodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TECcodes : TERUnderlyingType {
// Note: Exact numbers must stay stable. These codes are stored by
// value in metadata for historic transactions.

View File

@@ -35,6 +35,8 @@ namespace xrpl {
@ingroup protocol
*/
// clang-format off
// Protocol-critical, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TxType : std::uint16_t
{

View File

@@ -130,6 +130,19 @@ public:
return sle_->at(sfFlags);
}
/**
* @brief Check if a specific flag is set.
*
* @param f The flag bitmask to check
* @return true if all bits in f are set in the flags field
*/
[[nodiscard]]
bool
isFlag(std::uint32_t f) const
{
return sle_->isFlag(f);
}
/**
* @brief Get the underlying SLE object.
*

View File

@@ -3,7 +3,7 @@
namespace xrpl::Resource {
/** The disposition of a consumer after applying a load charge. */
enum Disposition {
enum class Disposition {
/** No action required. */
ok

View File

@@ -39,7 +39,7 @@ struct Entry : public beast::List<Entry>::Node
[[nodiscard]] bool
isUnlimited() const
{
return key->kind == kindUnlimited;
return key->kind == Kind::kindUnlimited;
}
// Balance including remote contributions

View File

@@ -10,6 +10,6 @@ namespace xrpl::Resource {
* subjected to administrative restrictions, such as
* use of some RPC commands like "stop".
*/
enum Kind { kindInbound, kindOutbound, kindUnlimited };
enum class Kind { kindInbound, kindOutbound, kindUnlimited };
} // namespace xrpl::Resource

View File

@@ -92,11 +92,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindInbound, address.at_port(0)), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindInbound, address.at_port(0)), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -122,11 +122,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindOutbound, address), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindOutbound, address), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -155,11 +155,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindUnlimited, address.at_port(1)), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindUnlimited, address.at_port(1)), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -190,7 +190,7 @@ public:
clock_type::time_point const now(m_clock.now());
Json::Value ret(Json::objectValue);
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto& inboundEntry : inbound_)
{
@@ -235,7 +235,7 @@ public:
clock_type::time_point const now(m_clock.now());
Gossip gossip;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
gossip.items.reserve(inbound_.size());
@@ -260,7 +260,7 @@ public:
{
auto const elapsed = m_clock.now();
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = importTable_.emplace(
std::piecewise_construct,
std::make_tuple(origin), // Key
@@ -317,7 +317,7 @@ public:
void
periodicActivity()
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto const elapsed = m_clock.now();
@@ -375,7 +375,7 @@ public:
void
erase(Table::iterator iter)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
Entry& entry(iter->second);
XRPL_ASSERT(entry.refcount == 0, "xrpl::Resource::Logic::erase : entry not used");
inactive_.erase(inactive_.iterator_to(entry));
@@ -385,27 +385,27 @@ public:
void
acquire(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
++entry.refcount;
}
void
release(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
if (--entry.refcount == 0)
{
JLOG(m_journal.debug()) << "Inactive " << entry;
switch (entry.key->kind)
{
case kindInbound:
case Kind::kindInbound:
inbound_.erase(inbound_.iterator_to(entry));
break;
case kindOutbound:
case Kind::kindOutbound:
outbound_.erase(outbound_.iterator_to(entry));
break;
case kindUnlimited:
case Kind::kindUnlimited:
admin_.erase(admin_.iterator_to(entry));
break;
default:
@@ -443,7 +443,7 @@ public:
if (!context.empty())
context = " (" + context + ")";
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
clock_type::time_point const now(m_clock.now());
int const balance(entry.add(fee.cost(), now));
JLOG(getStream(fee.cost(), m_journal)) << "Charging " << entry << " for " << fee << context;
@@ -456,7 +456,7 @@ public:
if (entry.isUnlimited())
return false;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
bool notify(false);
auto const elapsed = m_clock.now();
if (entry.balance(m_clock.now()) >= warningThreshold && elapsed != entry.lastWarningTime)
@@ -479,7 +479,7 @@ public:
if (entry.isUnlimited())
return false;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
bool drop(false);
clock_type::time_point const now(m_clock.now());
int const balance(entry.balance(now));
@@ -501,7 +501,7 @@ public:
int
balance(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
return entry.balance(m_clock.now());
}
@@ -530,7 +530,7 @@ public:
{
clock_type::time_point const now(m_clock.now());
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
{
beast::PropertyStream::Set s("inbound", map);

View File

@@ -5,6 +5,8 @@
namespace xrpl::Resource {
/** Tunable constants. */
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Balance at which a warning is issued
warningThreshold = 5000

View File

@@ -35,28 +35,28 @@ public:
setRemoteFee(std::uint32_t f)
{
JLOG(j_.trace()) << "setRemoteFee: " << f;
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
remoteTxnLoadFee_ = f;
}
std::uint32_t
getRemoteFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return remoteTxnLoadFee_;
}
std::uint32_t
getLocalFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return localTxnLoadFee_;
}
std::uint32_t
getClusterFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return clusterTxnLoadFee_;
}
@@ -69,14 +69,14 @@ public:
std::uint32_t
getLoadFactor() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return std::max({clusterTxnLoadFee_, localTxnLoadFee_, remoteTxnLoadFee_});
}
std::pair<std::uint32_t, std::uint32_t>
getScalingFactors() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return std::make_pair(
std::max(localTxnLoadFee_, remoteTxnLoadFee_),
@@ -87,7 +87,7 @@ public:
setClusterFee(std::uint32_t fee)
{
JLOG(j_.trace()) << "setClusterFee: " << fee;
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
clusterTxnLoadFee_ = fee;
}
@@ -99,14 +99,14 @@ public:
bool
isLoadedLocal() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
}
bool
isLoadedCluster() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
(clusterTxnLoadFee_ != lftNormalFee);
}

View File

@@ -38,6 +38,8 @@ protected:
using endpoint_type = boost::asio::ip::tcp::endpoint;
using yield_context = boost::asio::yield_context;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Size of our read/write buffer
bufferSize = 4 * 1024,
@@ -303,7 +305,7 @@ BaseHTTPPeer<Handler, Impl>::on_write(error_code const& ec, std::size_t bytes_tr
return fail(ec, "write");
bytes_out_ += bytes_transferred;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
wq2_.clear();
wq2_.reserve(wq_.size());
std::swap(wq2_, wq_);
@@ -395,7 +397,7 @@ BaseHTTPPeer<Handler, Impl>::write(void const* buf, std::size_t bytes)
if (bytes == 0)
return;
if ([&] {
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
wq_.emplace_back(buf, bytes);
return wq_.size() == 1 && wq2_.size() == 0;
}())
@@ -449,7 +451,7 @@ BaseHTTPPeer<Handler, Impl>::complete()
complete_ = true;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (!wq_.empty() && !wq2_.empty())
return;
}
@@ -484,7 +486,7 @@ BaseHTTPPeer<Handler, Impl>::close(bool graceful)
{
graceful_ = true;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (!wq_.empty() || !wq2_.empty())
return;
}

View File

@@ -62,6 +62,8 @@ class ServerImpl : public Server
private:
using clock_type = std::chrono::system_clock;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { historySize = 100 };
Handler& handler_;

View File

@@ -165,7 +165,7 @@ io_list::work::destroy()
return;
std::function<void(void)> f;
{
std::lock_guard const lock(ios_->m_);
std::scoped_lock const lock(ios_->m_);
ios_->map_.erase(this);
if (--ios_->n_ == 0 && ios_->closed_)
{
@@ -195,7 +195,7 @@ io_list::emplace(Args&&... args)
auto sp = std::make_shared<T>(std::forward<Args>(args)...);
decltype(sp) dead;
std::lock_guard const lock(m_);
std::scoped_lock const lock(m_);
if (!closed_)
{
++n_;

View File

@@ -22,6 +22,8 @@ private:
using CacheType = KeyCache;
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { defaultCacheTargetSize = 0 };
using key_type = uint256;

View File

@@ -123,6 +123,8 @@ public:
Transactor(Transactor const&) = delete;
Transactor&
operator=(Transactor const&) = delete;
// 68 transactor subclass files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ConsequencesFactoryType { Normal, Blocker, Custom };
/** Process the transaction. */

View File

@@ -39,7 +39,7 @@ class TxConsequences
public:
/// Describes how the transaction affects subsequent
/// transactions
enum Category {
enum class Category {
/// Moves currency around, creates offers, etc.
normal = 0,
/// Affects the ability of subsequent transactions

View File

@@ -25,6 +25,8 @@ not have the relevant amendments enabled_. It's intentionally a pain in the neck
so that bad code gets caught and fixed as early as possible.
*/
// Bitwise flags, 86 files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Privilege {
noPriv = 0x0000, // The transaction can not do any of the enumerated operations
createAcct = 0x0001, // The transaction can create a new ACCOUNT_ROOT object.

View File

@@ -35,10 +35,10 @@ public:
*/
class ValidMPTPayment
{
enum Order { Before = 0, After = 1 };
enum class Order { Before = 0, After = 1 };
struct MPTData
{
std::array<std::int64_t, After + 1> outstanding{};
std::array<std::int64_t, 2> outstanding{};
// sum (MPT after - MPT before)
std::int64_t mptAmount{0};
};

View File

@@ -21,7 +21,7 @@ class AMMContext;
enum class DebtDirection { issues, redeems };
enum class QualityDirection { in, out };
enum class StrandDirection { forward, reverse };
enum OfferCrossing { no = 0, yes = 1, sell = 2 };
enum class OfferCrossing { no = 0, yes = 1, sell = 2 };
inline bool
redeems(DebtDirection dir)

View File

@@ -665,7 +665,7 @@ flow(
// the previous strand execution failed. It has to be reset
// since this strand might not have AMM liquidity.
ammContext.clear();
if (offerCrossing && limitQuality)
if (offerCrossing != OfferCrossing::no && limitQuality)
{
auto const strandQ = qualityUpperBound(sb, *strand);
if (!strandQ || *strandQ < *limitQuality)
@@ -797,7 +797,8 @@ flow(
// fixFillOrKill amendment:
// That case is handled here if tfSell is also not set; i.e,
// case 1.
if (!offerCrossing || (fillOrKillEnabled && offerCrossing != OfferCrossing::sell))
if (offerCrossing == OfferCrossing::no ||
(fillOrKillEnabled && offerCrossing != OfferCrossing::sell))
return {tecPATH_PARTIAL, actualIn, actualOut, std::move(ofrsToRmOnFail)};
}
else if (actualOut == beast::zero)
@@ -805,7 +806,7 @@ flow(
return {tecPATH_DRY, std::move(ofrsToRmOnFail)};
}
}
if (offerCrossing &&
if (offerCrossing != OfferCrossing::no &&
(!partialPayment && (!fillOrKillEnabled || offerCrossing == OfferCrossing::sell)))
{
// If we're offer crossing and partialPayment is *not* true, then

View File

@@ -18,8 +18,8 @@ class SignerListSet : public Transactor
{
private:
// Values determined during preCompute for use later.
enum Operation { unknown, set, destroy };
Operation do_{unknown};
enum class Operation { unknown, set, destroy };
Operation do_{Operation::unknown};
std::uint32_t quorum_{0};
std::vector<SignerEntries::SignerEntry> signers_;

View File

@@ -7,7 +7,7 @@ namespace xrpl {
class LedgerStateFix : public Transactor
{
public:
enum FixType : std::uint16_t {
enum class FixType : std::uint16_t {
nfTokenPageLink = 1,
};