tools: update inspector_protocol to c488ba2

PR-URL: https://github.com/nodejs/node/pull/51293
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
cola119
2023-12-27 16:19:01 +09:00
committed by Node.js GitHub Bot
parent 02cdc95126
commit f6a83cdb6f
2 changed files with 31 additions and 54 deletions

View File

@@ -28,7 +28,6 @@ class DispatchResponse;
class ErrorSupport;
class FundamentalValue;
class ListValue;
template<typename T> class Maybe;
class Object;
using Response = DispatchResponse;
class SerializedValue;

View File

@@ -13,12 +13,13 @@
namespace {{namespace}} {
{% endfor %}
namespace detail {
template<typename T>
class Maybe {
class PtrMaybe {
public:
Maybe() : m_value() { }
Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
Maybe(Maybe&& other) noexcept : m_value(std::move(other.m_value)) {}
PtrMaybe() = default;
PtrMaybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
PtrMaybe(PtrMaybe&& other) noexcept : m_value(std::move(other.m_value)) {}
void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
T* fromJust() const { DCHECK(m_value); return m_value.get(); }
T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
@@ -29,68 +30,45 @@ private:
};
template<typename T>
class MaybeBase {
class ValueMaybe {
public:
MaybeBase() : m_isJust(false) { }
MaybeBase(T value) : m_isJust(true), m_value(value) { }
MaybeBase(MaybeBase&& other) noexcept
ValueMaybe() : m_isJust(false), m_value() { }
ValueMaybe(T value) : m_isJust(true), m_value(std::move(value)) { }
ValueMaybe(ValueMaybe&& other) noexcept
: m_isJust(other.m_isJust),
m_value(std::move(other.m_value)) {}
void operator=(T value) { m_value = value; m_isJust = true; }
T fromJust() const { DCHECK(m_isJust); return m_value; }
T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
const T& fromJust() const { DCHECK(m_isJust); return m_value; }
const T& fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
bool isJust() const { return m_isJust; }
T takeJust() { DCHECK(m_isJust); return m_value; }
protected:
T takeJust() { DCHECK(m_isJust); return std::move(m_value); }
private:
bool m_isJust;
T m_value;
};
template<>
class Maybe<bool> : public MaybeBase<bool> {
public:
Maybe() { m_value = false; }
Maybe(bool value) : MaybeBase(value) { }
Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
template <typename T>
struct MaybeTypedef { typedef PtrMaybe<T> type; };
template<>
class Maybe<int> : public MaybeBase<int> {
public:
Maybe() { m_value = 0; }
Maybe(int value) : MaybeBase(value) { }
Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
template <>
struct MaybeTypedef<bool> { typedef ValueMaybe<bool> type; };
template<>
class Maybe<double> : public MaybeBase<double> {
public:
Maybe() { m_value = 0; }
Maybe(double value) : MaybeBase(value) { }
Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
template <>
struct MaybeTypedef<int> { typedef ValueMaybe<int> type; };
template<>
class Maybe<String> : public MaybeBase<String> {
public:
Maybe() { }
Maybe(const String& value) : MaybeBase(value) { }
Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
template <>
struct MaybeTypedef<double> { typedef ValueMaybe<double> type; };
template<>
class Maybe<Binary> : public MaybeBase<Binary> {
public:
Maybe() { }
Maybe(Binary value) : MaybeBase(value) { }
Maybe(Maybe&& other) noexcept : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
template <>
struct MaybeTypedef<String> { typedef ValueMaybe<String> type; };
template <>
struct MaybeTypedef<Binary> { typedef ValueMaybe<Binary> type; };
} // namespace detail
template <typename T>
using Maybe = typename detail::MaybeTypedef<T>::type;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}