Skip to content

Commit

Permalink
tools: update inspector_protocol to c488ba2
Browse files Browse the repository at this point in the history
PR-URL: #51293
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
cola119 authored and RafaelGSS committed Jan 2, 2024
1 parent 69a46ad commit bdcb5ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 54 deletions.
1 change: 0 additions & 1 deletion tools/inspector_protocol/lib/Forward_h.template
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class DispatchResponse;
class ErrorSupport;
class FundamentalValue;
class ListValue;
template<typename T> class Maybe;
class Object;
using Response = DispatchResponse;
class SerializedValue;
Expand Down
84 changes: 31 additions & 53 deletions tools/inspector_protocol/lib/Maybe_h.template
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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}}
Expand Down

0 comments on commit bdcb5ed

Please sign in to comment.