Files
tubestation/dom/canvas/ParamTraits_IsEnumCase.h
Kelsey Gilbert d6075a00e6 Bug 1932784 - Move ParamTraits_IsEnumCase,_TiedFields out of WebGLIpdl.h. r=gfx-reviewers,lsalzman
This means other headers that need these ParamTraits don't also
include all the other things that WebGLIpdl.h needs, like WebGLTypes.h.

This reduces the preprocessed size of modules outside of dom/canvas,
hopefully improving compilation speed, and reducing breadth of
recompiles.

Differential Revision: https://phabricator.services.mozilla.com/D229865
2024-12-04 11:13:49 +00:00

44 lines
1.3 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_PARAMTRAITS_ISENUMCASE_H
#define MOZILLA_PARAMTRAITS_ISENUMCASE_H
#include "ipc/IPCMessageUtils.h"
#include "IsEnumCase.h"
#include "mozilla/ipc/IPDLParamTraits.h"
namespace IPC {
/*
`IsEnumCase(T) -> bool` guarantees that we never have false negatives or false
positives due to adding or removing enum cases to enums, and forgetting to
update their serializations. Also, it allows enums to be non-continguous, unlike
ContiguousEnumSerializer.
*/
template <class T>
struct ParamTraits_IsEnumCase {
static bool Write(MessageWriter* const writer, const T& in) {
MOZ_ASSERT(mozilla::IsEnumCase(in));
const auto shadow = static_cast<std::underlying_type_t<T>>(in);
WriteParam(writer, shadow);
return true;
}
static bool Read(MessageReader* const reader, T* const out) {
auto shadow = std::underlying_type_t<T>{};
if (!ReadParam(reader, &shadow)) return false;
const auto e = mozilla::AsEnumCase<T>(shadow);
if (!e) return false;
*out = *e;
return true;
}
};
} // namespace IPC
#endif