mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 958375 - 3/9 - Add a variant of EnumSerializer that works on MFBT typed enums - r=nfroyd
This commit is contained in:
parent
a8ba12fe38
commit
d0616b0136
@ -15,6 +15,7 @@
|
||||
#ifdef XP_WIN
|
||||
#include "mozilla/TimeStamp_windows.h"
|
||||
#endif
|
||||
#include "mozilla/TypedEnum.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -134,6 +135,43 @@ struct EnumSerializer {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Variant of EnumSerializer for MFBT's typed enums
|
||||
* defined by MOZ_BEGIN_ENUM_CLASS in mfbt/TypedEnum.h
|
||||
*
|
||||
* This is only needed on non-C++11 compilers such as B2G's GCC 4.4,
|
||||
* where MOZ_BEGIN_ENUM_CLASS is implemented using a nested enum, T::Enum,
|
||||
* in a wrapper class T. In this case, the "typed enum" type T cannot be
|
||||
* used as an integer template parameter type. MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(T)
|
||||
* is how we get at the integer enum type.
|
||||
*/
|
||||
template <typename E,
|
||||
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) smallestLegal,
|
||||
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) highBound>
|
||||
struct TypedEnumSerializer {
|
||||
typedef E paramType;
|
||||
typedef MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) intParamType;
|
||||
|
||||
static bool IsLegalValue(const paramType &aValue) {
|
||||
return smallestLegal <= intParamType(aValue) && intParamType(aValue) < highBound;
|
||||
}
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aValue) {
|
||||
MOZ_ASSERT(IsLegalValue(aValue));
|
||||
WriteParam(aMsg, int32_t(intParamType(aValue)));
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
|
||||
int32_t value;
|
||||
if(!ReadParam(aMsg, aIter, &value) ||
|
||||
!IsLegalValue(intParamType(value))) {
|
||||
return false;
|
||||
}
|
||||
*aResult = intParamType(value);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<base::ChildPrivileges>
|
||||
: public EnumSerializer<base::ChildPrivileges,
|
||||
|
Loading…
Reference in New Issue
Block a user