Commit ec49e07a authored by Kenton Varda's avatar Kenton Varda

Use consistent naming style for structs that exist purely to specialize template…

Use consistent naming style for structs that exist purely to specialize template aliases or functions.
parent 059c50d4
......@@ -484,36 +484,17 @@ private:
// -------------------------------------------------------------------
namespace internal {
// Make sure ReaderFor<T> and BuilderFor<T> work for DynamicEnum, DynamicObject, DynamicStruct, and
// DynamicList, so that we can define DynamicValue::as().
template <>
struct MaybeReaderBuilder<DynamicEnum, Kind::UNKNOWN> {
typedef DynamicEnum Reader;
typedef DynamicEnum Builder;
};
template <>
struct MaybeReaderBuilder<DynamicObject, Kind::UNKNOWN> {
typedef DynamicObject Reader;
typedef DynamicObject Builder;
};
template <>
struct MaybeReaderBuilder<DynamicStruct, Kind::UNKNOWN> {
typedef DynamicStruct::Reader Reader;
typedef DynamicStruct::Builder Builder;
};
template <>
struct MaybeReaderBuilder<DynamicList, Kind::UNKNOWN> {
typedef DynamicList::Reader Reader;
typedef DynamicList::Builder Builder;
};
} // namespace internal
template <> struct ReaderFor_ <DynamicEnum, Kind::UNKNOWN> { typedef DynamicEnum Type; };
template <> struct BuilderFor_<DynamicEnum, Kind::UNKNOWN> { typedef DynamicEnum Type; };
template <> struct ReaderFor_ <DynamicObject, Kind::UNKNOWN> { typedef DynamicObject Type; };
template <> struct BuilderFor_<DynamicObject, Kind::UNKNOWN> { typedef DynamicObject Type; };
template <> struct ReaderFor_ <DynamicStruct, Kind::UNKNOWN> { typedef DynamicStruct::Reader Type; };
template <> struct BuilderFor_<DynamicStruct, Kind::UNKNOWN> { typedef DynamicStruct::Builder Type; };
template <> struct ReaderFor_ <DynamicList, Kind::UNKNOWN> { typedef DynamicList::Reader Type; };
template <> struct BuilderFor_<DynamicList, Kind::UNKNOWN> { typedef DynamicList::Builder Type; };
class DynamicValue::Reader {
public:
......
......@@ -158,25 +158,25 @@ struct RawSchema {
};
template <typename T>
struct RawSchemaFor;
struct RawSchema_;
template <typename T>
inline const RawSchema& rawSchema() {
return RawSchemaFor<T>::getSchema();
return RawSchema_<T>::get();
}
template <typename T>
struct TypeIdFor;
struct TypeId_;
template <typename T>
struct UnionMemberIndexFor;
struct UnionMemberIndex_;
template <typename T>
inline uint unionMemberIndex() { return UnionMemberIndexFor<T>::value; }
inline uint unionMemberIndex() { return UnionMemberIndex_<T>::value; }
template <typename T>
struct UnionParentTypeFor;
struct UnionParentType_;
template <typename T>
using UnionParentType = typename UnionParentTypeFor<T>::Type;
using UnionParentType = typename UnionParentType_<T>::Type;
kj::String structString(StructReader reader, const RawSchema& schema);
kj::String unionString(StructReader reader, const RawSchema& schema, uint memberIndex);
......@@ -196,53 +196,53 @@ inline kj::String unionString(StructReader reader) {
} // namespace internal
template <typename T>
inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; }
inline constexpr uint64_t typeId() { return internal::TypeId_<T>::typeId; }
// typeId<MyType>() returns the type ID as defined in the schema. Works with structs, enums, and
// interfaces.
} // namespace capnproto
#define CAPNPROTO_DECLARE_ENUM(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::ENUM; }; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
template <> struct Kind_<type> { static constexpr Kind kind = Kind::ENUM; }; \
template <> struct TypeId_<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchema_<type> { \
static inline const RawSchema& get() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_ENUM(type) \
constexpr Kind KindOf<type>::kind; \
constexpr uint64_t TypeIdFor<type>::typeId;
constexpr Kind Kind_<type>::kind; \
constexpr uint64_t TypeId_<type>::typeId;
#define CAPNPROTO_DECLARE_STRUCT(type, id, dataWordSize, pointerCount, preferredElementEncoding) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \
template <> struct Kind_<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSize_<type> { \
static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * POINTERS, FieldSize::preferredElementEncoding); \
}; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
template <> struct TypeId_<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchema_<type> { \
static inline const RawSchema& get() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_STRUCT(type) \
constexpr Kind KindOf<type>::kind; \
constexpr StructSize StructSizeFor<type>::value; \
constexpr uint64_t TypeIdFor<type>::typeId;
constexpr Kind Kind_<type>::kind; \
constexpr StructSize StructSize_<type>::value; \
constexpr uint64_t TypeId_<type>::typeId;
#define CAPNPROTO_DECLARE_UNION(type, parentType, memberIndex) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::UNION; }; \
template <> struct UnionMemberIndexFor<type> { static constexpr uint value = memberIndex; }; \
template <> struct UnionParentTypeFor<type> { typedef parentType Type; }
template <> struct Kind_<type> { static constexpr Kind kind = Kind::UNION; }; \
template <> struct UnionMemberIndex_<type> { static constexpr uint value = memberIndex; }; \
template <> struct UnionParentType_<type> { typedef parentType Type; }
#define CAPNPROTO_DEFINE_UNION(type) \
constexpr Kind KindOf<type>::kind; \
constexpr uint UnionMemberIndexFor<type>::value;
constexpr Kind Kind_<type>::kind; \
constexpr uint UnionMemberIndex_<type>::value;
#define CAPNPROTO_DECLARE_INTERFACE(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::INTERFACE; }; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
template <> struct Kind_<type> { static constexpr Kind kind = Kind::INTERFACE; }; \
template <> struct TypeId_<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchema_<type> { \
static inline const RawSchema& get() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_INTERFACE(type) \
constexpr Kind KindOf<type>::kind; \
constexpr uint64_t TypeIdFor<type>::typeId;
constexpr Kind Kind_<type>::kind; \
constexpr uint64_t TypeId_<type>::typeId;
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
......@@ -134,28 +134,28 @@ enum class Kind: uint8_t {
namespace internal {
template <typename T> struct KindOf { static constexpr Kind kind = Kind::UNKNOWN; };
template <> struct KindOf<Void> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<bool> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<int8_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<int16_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<int32_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<int64_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<uint8_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<uint16_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<uint32_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<uint64_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<float> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<double> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct KindOf<Text> { static constexpr Kind kind = Kind::BLOB; };
template <> struct KindOf<Data> { static constexpr Kind kind = Kind::BLOB; };
template <typename T> struct Kind_ { static constexpr Kind kind = Kind::UNKNOWN; };
template <> struct Kind_<Void> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<bool> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<int8_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<int16_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<int32_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<int64_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<uint8_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<uint16_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<uint32_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<uint64_t> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<float> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<double> { static constexpr Kind kind = Kind::PRIMITIVE; };
template <> struct Kind_<Text> { static constexpr Kind kind = Kind::BLOB; };
template <> struct Kind_<Data> { static constexpr Kind kind = Kind::BLOB; };
} // namespace internal
template <typename T>
inline constexpr Kind kind() {
return internal::KindOf<T>::kind;
return internal::Kind_<T>::kind;
}
// =============================================================================
......@@ -188,31 +188,31 @@ struct StructSize {
: data(data), pointers(pointers), preferredListEncoding(preferredListEncoding) {}
};
template <typename T> struct StructSizeFor;
template <typename T> struct StructSize_;
// Specialized for every struct type with member: static constexpr StructSize value"
template <typename T>
inline constexpr StructSize structSize() {
return StructSizeFor<T>::value;
return StructSize_<T>::value;
}
// -------------------------------------------------------------------
// Masking of default values
template <typename T, Kind kind = kind<T>()> struct MaskType;
template <typename T> struct MaskType<T, Kind::PRIMITIVE> { typedef T Type; };
template <typename T> struct MaskType<T, Kind::ENUM> { typedef uint16_t Type; };
template <> struct MaskType<float, Kind::PRIMITIVE> { typedef uint32_t Type; };
template <> struct MaskType<double, Kind::PRIMITIVE> { typedef uint64_t Type; };
template <typename T, Kind kind = kind<T>()> struct Mask_;
template <typename T> struct Mask_<T, Kind::PRIMITIVE> { typedef T Type; };
template <typename T> struct Mask_<T, Kind::ENUM> { typedef uint16_t Type; };
template <> struct Mask_<float, Kind::PRIMITIVE> { typedef uint32_t Type; };
template <> struct Mask_<double, Kind::PRIMITIVE> { typedef uint64_t Type; };
template <typename T> struct MaskType<T, Kind::UNKNOWN> {
template <typename T> struct Mask_<T, Kind::UNKNOWN> {
// Union discriminants end up here.
static_assert(sizeof(T) == 2, "Don't know how to mask this type.");
typedef uint16_t Type;
};
template <typename T>
using Mask = typename MaskType<T>::Type;
using Mask = typename Mask_<T>::Type;
template <typename T>
KJ_ALWAYS_INLINE(Mask<T> mask(T value, Mask<T> mask));
......
......@@ -30,36 +30,24 @@
namespace capnproto {
namespace internal {
template <typename T, Kind kind = kind<T>()>
struct MaybeReaderBuilder {
typedef typename T::Reader Reader;
typedef typename T::Builder Builder;
};
template <typename T>
struct MaybeReaderBuilder<T, Kind::PRIMITIVE> {
typedef T Reader;
typedef T Builder;
};
template <typename T>
struct MaybeReaderBuilder<T, Kind::ENUM> {
typedef T Reader;
typedef T Builder;
};
template <typename T, Kind k = kind<T>()>
struct PointerHelpers;
} // namespace internal
template <typename T, Kind kind = kind<T>()>
template <typename T, Kind k = kind<T>()>
struct List;
template <typename T>
using ReaderFor = typename internal::MaybeReaderBuilder<T>::Reader;
template <typename T, Kind k = kind<T>()> struct ReaderFor_ { typedef typename T::Reader Type; };
template <typename T> struct ReaderFor_<T, Kind::PRIMITIVE> { typedef T Type; };
template <typename T> struct ReaderFor_<T, Kind::ENUM> { typedef T Type; };
template <typename T> using ReaderFor = typename ReaderFor_<T>::Type;
// The type returned by List<T>::Reader::operator[].
template <typename T>
using BuilderFor = typename internal::MaybeReaderBuilder<T>::Builder;
template <typename T, Kind k = kind<T>()> struct BuilderFor_ { typedef typename T::Builder Type; };
template <typename T> struct BuilderFor_<T, Kind::PRIMITIVE> { typedef T Type; };
template <typename T> struct BuilderFor_<T, Kind::ENUM> { typedef T Type; };
template <typename T> using BuilderFor = typename BuilderFor_<T>::Type;
// The type returned by List<T>::Builder::operator[].
template <typename T>
......@@ -78,7 +66,7 @@ using TypeIfEnum = typename TypeIfEnum_<kj::Decay<T>>::Type;
namespace internal {
template <typename T, Kind k> struct KindOf<List<T, k>> { static constexpr Kind kind = Kind::LIST; };
template <typename T, Kind k> struct Kind_<List<T, k>> { static constexpr Kind kind = Kind::LIST; };
template <size_t size> struct FieldSizeForByteSize;
template <> struct FieldSizeForByteSize<1> { static constexpr FieldSize value = FieldSize::BYTE; };
......
......@@ -243,10 +243,6 @@ template <typename T> struct EnableIfConst_;
template <typename T> struct EnableIfConst_<const T> { typedef T Type; };
template <typename T> using EnableIfConst = typename EnableIfConst_<T>::Type;
template <typename T, typename U> struct EnableIfDifferent_ { typedef int Type; };
template <typename T> struct EnableIfDifferent_<T, T> {};
template <typename T, typename U> using EnableIfDifferent = typename EnableIfDifferent_<T, U>::Type;
// =======================================================================================
// Equivalents to std::move() and std::forward(), since these are very commonly needed and the
// std header <utility> pulls in lots of other stuff.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment