diff options
author | Josh Haberman <jhaberman@gmail.com> | 2015-06-03 14:52:46 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2015-06-03 14:52:46 -0700 |
commit | e5bcdc2a3fdc0c38bf09a596efd951d5aaab1148 (patch) | |
tree | 3cbc06765d77bba866efc7623c044491b48f31af /upb/handlers-inl.h | |
parent | 6f30032183ccd20d7a7f031ebc9350f54179bba8 (diff) | |
parent | 97eeb570225bb2f1060f4eff18ba664e129767d2 (diff) |
Merge branch 'master' into google-internal
Diffstat (limited to 'upb/handlers-inl.h')
-rw-r--r-- | upb/handlers-inl.h | 391 |
1 files changed, 190 insertions, 201 deletions
diff --git a/upb/handlers-inl.h b/upb/handlers-inl.h index 70ddf91..444ca76 100644 --- a/upb/handlers-inl.h +++ b/upb/handlers-inl.h @@ -13,21 +13,56 @@ #include <limits.h> -// Type detection and typedefs for integer types. -// For platforms where there are multiple 32-bit or 64-bit types, we need to be -// able to enumerate them so we can properly create overloads for all variants. -// -// If any platform existed where there were three integer types with the same -// size, this would have to become more complicated. For example, short, int, -// and long could all be 32-bits. Even more diabolically, short, int, long, -// and long long could all be 64 bits and still be standard-compliant. -// However, few platforms are this strange, and it's unlikely that upb will be -// used on the strangest ones. - -// Can't count on stdint.h limits like INT32_MAX, because in C++ these are -// only defined when __STDC_LIMIT_MACROS are defined before the *first* include -// of stdint.h. We can't guarantee that someone else didn't include these first -// without defining __STDC_LIMIT_MACROS. +/* C inline methods. */ + +/* upb_bufhandle */ +UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h) { + h->obj_ = NULL; + h->objtype_ = NULL; + h->buf_ = NULL; + h->objofs_ = 0; +} +UPB_INLINE void upb_bufhandle_uninit(upb_bufhandle *h) { + UPB_UNUSED(h); +} +UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj, + const void *type) { + h->obj_ = obj; + h->objtype_ = type; +} +UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf, + size_t ofs) { + h->buf_ = buf; + h->objofs_ = ofs; +} +UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h) { + return h->obj_; +} +UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h) { + return h->objtype_; +} +UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) { + return h->buf_; +} + + +#ifdef __cplusplus + +/* Type detection and typedefs for integer types. + * For platforms where there are multiple 32-bit or 64-bit types, we need to be + * able to enumerate them so we can properly create overloads for all variants. + * + * If any platform existed where there were three integer types with the same + * size, this would have to become more complicated. For example, short, int, + * and long could all be 32-bits. Even more diabolically, short, int, long, + * and long long could all be 64 bits and still be standard-compliant. + * However, few platforms are this strange, and it's unlikely that upb will be + * used on the strangest ones. */ + +/* Can't count on stdint.h limits like INT32_MAX, because in C++ these are + * only defined when __STDC_LIMIT_MACROS are defined before the *first* include + * of stdint.h. We can't guarantee that someone else didn't include these first + * without defining __STDC_LIMIT_MACROS. */ #define UPB_INT32_MAX 0x7fffffffLL #define UPB_INT32_MIN (-UPB_INT32_MAX - 1) #define UPB_INT64_MAX 0x7fffffffffffffffLL @@ -49,8 +84,8 @@ #define UPB_LLONG_IS_64BITS 1 #endif -// We use macros instead of typedefs so we can undefine them later and avoid -// leaking them outside this header file. +/* We use macros instead of typedefs so we can undefine them later and avoid + * leaking them outside this header file. */ #if UPB_INT_IS_32BITS #define UPB_INT32_T int #define UPB_UINT32_T unsigned int @@ -59,12 +94,12 @@ #define UPB_TWO_32BIT_TYPES 1 #define UPB_INT32ALT_T long #define UPB_UINT32ALT_T unsigned long -#endif // UPB_LONG_IS_32BITS +#endif /* UPB_LONG_IS_32BITS */ -#elif UPB_LONG_IS_32BITS // && !UPB_INT_IS_32BITS +#elif UPB_LONG_IS_32BITS /* && !UPB_INT_IS_32BITS */ #define UPB_INT32_T long #define UPB_UINT32_T unsigned long -#endif // UPB_INT_IS_32BITS +#endif /* UPB_INT_IS_32BITS */ #if UPB_LONG_IS_64BITS @@ -75,12 +110,12 @@ #define UPB_TWO_64BIT_TYPES 1 #define UPB_INT64ALT_T long long #define UPB_UINT64ALT_T unsigned long long -#endif // UPB_LLONG_IS_64BITS +#endif /* UPB_LLONG_IS_64BITS */ -#elif UPB_LLONG_IS_64BITS // && !UPB_LONG_IS_64BITS +#elif UPB_LLONG_IS_64BITS /* && !UPB_LONG_IS_64BITS */ #define UPB_INT64_T long long #define UPB_UINT64_T unsigned long long -#endif // UPB_LONG_IS_64BITS +#endif /* UPB_LONG_IS_64BITS */ #undef UPB_INT32_MAX #undef UPB_INT32_MIN @@ -91,56 +126,22 @@ #undef UPB_LONG_IS_64BITS #undef UPB_LLONG_IS_64BITS -// C inline methods. - -// upb_bufhandle -UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h) { - h->obj_ = NULL; - h->objtype_ = NULL; - h->buf_ = NULL; - h->objofs_ = 0; -} -UPB_INLINE void upb_bufhandle_uninit(upb_bufhandle *h) { - UPB_UNUSED(h); -} -UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj, - const void *type) { - h->obj_ = obj; - h->objtype_ = type; -} -UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf, - size_t ofs) { - h->buf_ = buf; - h->objofs_ = ofs; -} -UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h) { - return h->obj_; -} -UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h) { - return h->objtype_; -} -UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) { - return h->buf_; -} - - -#ifdef __cplusplus namespace upb { typedef void CleanupFunc(void *ptr); -// Template to remove "const" from "const T*" and just return "T*". -// -// We define a nonsense default because otherwise it will fail to instantiate as -// a function parameter type even in cases where we don't expect any caller to -// actually match the overload. +/* Template to remove "const" from "const T*" and just return "T*". + * + * We define a nonsense default because otherwise it will fail to instantiate as + * a function parameter type even in cases where we don't expect any caller to + * actually match the overload. */ class CouldntRemoveConst {}; template <class T> struct remove_constptr { typedef CouldntRemoveConst type; }; template <class T> struct remove_constptr<const T *> { typedef T *type; }; -// Template that we use below to remove a template specialization from -// consideration if it matches a specific type. +/* Template that we use below to remove a template specialization from + * consideration if it matches a specific type. */ template <class T, class U> struct disable_if_same { typedef void Type; }; template <class T> struct disable_if_same<T, T> {}; @@ -177,27 +178,27 @@ bool is_same<T, U>::value = false; template<class T> bool is_same<T, T>::value = true; -// FuncInfo //////////////////////////////////////////////////////////////////// +/* FuncInfo *******************************************************************/ -// Info about the user's original, pre-wrapped function. +/* Info about the user's original, pre-wrapped function. */ template <class C, class R = void> struct FuncInfo { - // The type of the closure that the function takes (its first param). + /* The type of the closure that the function takes (its first param). */ typedef C Closure; - // The return type. + /* The return type. */ typedef R Return; }; -// Func //////////////////////////////////////////////////////////////////////// +/* Func ***********************************************************************/ -// Func1, Func2, Func3: Template classes representing a function and its -// signature. -// -// Since the function is a template parameter, calling the function can be -// inlined at compile-time and does not require a function pointer at runtime. -// These functions are not bound to a handler data so have no data or cleanup -// handler. +/* Func1, Func2, Func3: Template classes representing a function and its + * signature. + * + * Since the function is a template parameter, calling the function can be + * inlined at compile-time and does not require a function pointer at runtime. + * These functions are not bound to a handler data so have no data or cleanup + * handler. */ struct UnboundFunc { CleanupFunc *GetCleanup() { return NULL; } void *GetData() { return NULL; } @@ -242,13 +243,13 @@ struct Func5 : public UnboundFunc { } }; -// BoundFunc /////////////////////////////////////////////////////////////////// +/* BoundFunc ******************************************************************/ -// BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that -// shall be bound to the function's second parameter. -// -// Note that the second parameter is a const pointer, but our stored bound value -// is non-const so we can free it when the handlers are destroyed. +/* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that + * shall be bound to the function's second parameter. + * + * Note that the second parameter is a const pointer, but our stored bound value + * is non-const so we can free it when the handlers are destroyed. */ template <class T> struct BoundFunc { typedef typename remove_constptr<T>::type MutableP2; @@ -288,13 +289,13 @@ struct BoundFunc5 : public BoundFunc<P2> { explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {} }; -// FuncSig ///////////////////////////////////////////////////////////////////// +/* FuncSig ********************************************************************/ -// FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function -// *signature*, but without a specific function attached. -// -// These classes contain member functions that can be invoked with a -// specific function to return a Func/BoundFunc class. +/* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function + * *signature*, but without a specific function attached. + * + * These classes contain member functions that can be invoked with a + * specific function to return a Func/BoundFunc class. */ template <class R, class P1> struct FuncSig1 { template <R F(P1)> @@ -359,41 +360,41 @@ struct FuncSig5 { } }; -// Overloaded template function that can construct the appropriate FuncSig* -// class given a function pointer by deducing the template parameters. +/* Overloaded template function that can construct the appropriate FuncSig* + * class given a function pointer by deducing the template parameters. */ template <class R, class P1> inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return FuncSig1<R, P1>(); } template <class R, class P1, class P2> inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return FuncSig2<R, P1, P2>(); } template <class R, class P1, class P2, class P3> inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return FuncSig3<R, P1, P2, P3>(); } template <class R, class P1, class P2, class P3, class P4> inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return FuncSig4<R, P1, P2, P3, P4>(); } template <class R, class P1, class P2, class P3, class P4, class P5> inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return FuncSig5<R, P1, P2, P3, P4, P5>(); } -// MethodSig /////////////////////////////////////////////////////////////////// +/* MethodSig ******************************************************************/ -// CallMethod*: a function template that calls a given method. +/* CallMethod*: a function template that calls a given method. */ template <class R, class C, R (C::*F)()> R CallMethod0(C *obj) { return ((*obj).*F)(); @@ -420,10 +421,10 @@ R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) { return ((*obj).*F)(arg1, arg2, arg3, arg4); } -// MethodSig: like FuncSig, but for member functions. -// -// GetFunc() returns a normal FuncN object, so after calling GetFunc() no -// more logic is required to special-case methods. +/* MethodSig: like FuncSig, but for member functions. + * + * GetFunc() returns a normal FuncN object, so after calling GetFunc() no + * more logic is required to special-case methods. */ template <class R, class C> struct MethodSig0 { template <R (C::*F)()> @@ -504,61 +505,61 @@ struct MethodSig4 { template <class R, class C> inline MethodSig0<R, C> MatchFunc(R (C::*f)()) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return MethodSig0<R, C>(); } template <class R, class C, class P1> inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return MethodSig1<R, C, P1>(); } template <class R, class C, class P1, class P2> inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return MethodSig2<R, C, P1, P2>(); } template <class R, class C, class P1, class P2, class P3> inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return MethodSig3<R, C, P1, P2, P3>(); } template <class R, class C, class P1, class P2, class P3, class P4> inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) { - UPB_UNUSED(f); // Only used for template parameter deduction. + UPB_UNUSED(f); /* Only used for template parameter deduction. */ return MethodSig4<R, C, P1, P2, P3, P4>(); } -// MaybeWrapReturn ///////////////////////////////////////////////////////////// +/* MaybeWrapReturn ************************************************************/ -// Template class that attempts to wrap the return value of the function so it -// matches the expected type. There are two main adjustments it may make: -// -// 1. If the function returns void, make it return the expected type and with -// a value that always indicates success. -// 2. If the function returns bool, make it return the expected type with a -// value that indicates success or failure. -// -// The "expected type" for return is: -// 1. void* for start handlers. If the closure parameter has a different type -// we will cast it to void* for the return in the success case. -// 2. size_t for string buffer handlers. -// 3. bool for everything else. +/* Template class that attempts to wrap the return value of the function so it + * matches the expected type. There are two main adjustments it may make: + * + * 1. If the function returns void, make it return the expected type and with + * a value that always indicates success. + * 2. If the function returns bool, make it return the expected type with a + * value that indicates success or failure. + * + * The "expected type" for return is: + * 1. void* for start handlers. If the closure parameter has a different type + * we will cast it to void* for the return in the success case. + * 2. size_t for string buffer handlers. + * 3. bool for everything else. */ -// Template parameters are FuncN type and desired return type. +/* Template parameters are FuncN type and desired return type. */ template <class F, class R, class Enable = void> struct MaybeWrapReturn; -// If the return type matches, return the given function unwrapped. +/* If the return type matches, return the given function unwrapped. */ template <class F> struct MaybeWrapReturn<F, typename F::Return> { typedef F Func; }; -// Function wrapper that munges the return value from void to (bool)true. +/* Function wrapper that munges the return value from void to (bool)true. */ template <class P1, class P2, void F(P1, P2)> bool ReturnTrue2(P1 p1, P2 p2) { F(p1, p2); @@ -571,7 +572,7 @@ bool ReturnTrue3(P1 p1, P2 p2, P3 p3) { return true; } -// Function wrapper that munges the return value from void to (void*)arg1 +/* Function wrapper that munges the return value from void to (void*)arg1 */ template <class P1, class P2, void F(P1, P2)> void *ReturnClosure2(P1 p1, P2 p2) { F(p1, p2); @@ -584,7 +585,7 @@ void *ReturnClosure3(P1 p1, P2 p2, P3 p3) { return p1; } -// Function wrapper that munges the return value from R to void*. +/* Function wrapper that munges the return value from R to void*. */ template <class R, class P1, class P2, R F(P1, P2)> void *CastReturnToVoidPtr2(P1 p1, P2 p2) { return F(p1, p2); @@ -595,7 +596,7 @@ void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); } -// Function wrapper that munges the return value from bool to void*. +/* Function wrapper that munges the return value from bool to void*. */ template <class P1, class P2, bool F(P1, P2)> void *ReturnClosureOrBreak2(P1 p1, P2 p2) { return F(p1, p2) ? p1 : UPB_BREAK; @@ -606,7 +607,7 @@ void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3) ? p1 : UPB_BREAK; } -// For the string callback, which takes five params, returns the size param. +/* For the string callback, which takes five params, returns the size param. */ template <class P1, class P2, void F(P1, P2, const char *, size_t, const BufferHandle *)> size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4, @@ -615,8 +616,8 @@ size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4, return p4; } -// For the string callback, which takes five params, returns the size param or -// zero. +/* For the string callback, which takes five params, returns the size param or + * zero. */ template <class P1, class P2, bool F(P1, P2, const char *, size_t, const BufferHandle *)> size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4, @@ -624,8 +625,8 @@ size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4, return F(p1, p2, p3, p4, p5) ? p4 : 0; } -// If we have a function returning void but want a function returning bool, wrap -// it in a function that returns true. +/* If we have a function returning void but want a function returning bool, wrap + * it in a function that returns true. */ template <class P1, class P2, void F(P1, P2), class I> struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> { typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func; @@ -636,8 +637,8 @@ struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> { typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func; }; -// If our function returns void but we want one returning void*, wrap it in a -// function that returns the first argument. +/* If our function returns void but we want one returning void*, wrap it in a + * function that returns the first argument. */ template <class P1, class P2, void F(P1, P2), class I> struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> { typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func; @@ -648,8 +649,8 @@ struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> { typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func; }; -// If our function returns R* but we want one returning void*, wrap it in a -// function that casts to void*. +/* If our function returns R* but we want one returning void*, wrap it in a + * function that casts to void*. */ template <class R, class P1, class P2, R *F(P1, P2), class I> struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *, typename disable_if_same<R *, void *>::Type> { @@ -663,8 +664,8 @@ struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *, Func; }; -// If our function returns bool but we want one returning void*, wrap it in a -// function that returns either the first param or UPB_BREAK. +/* If our function returns bool but we want one returning void*, wrap it in a + * function that returns either the first param or UPB_BREAK. */ template <class P1, class P2, bool F(P1, P2), class I> struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> { typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func; @@ -676,8 +677,8 @@ struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> { Func; }; -// If our function returns void but we want one returning size_t, wrap it in a -// function that returns the size argument. +/* If our function returns void but we want one returning size_t, wrap it in a + * function that returns the size argument. */ template <class P1, class P2, void F(P1, P2, const char *, size_t, const BufferHandle *), class I> struct MaybeWrapReturn< @@ -687,8 +688,8 @@ struct MaybeWrapReturn< ReturnStringLen<P1, P2, F>, I> Func; }; -// If our function returns bool but we want one returning size_t, wrap it in a -// function that returns either 0 or the buf size. +/* If our function returns bool but we want one returning size_t, wrap it in a + * function that returns either 0 or the buf size. */ template <class P1, class P2, bool F(P1, P2, const char *, size_t, const BufferHandle *), class I> struct MaybeWrapReturn< @@ -698,16 +699,16 @@ struct MaybeWrapReturn< ReturnNOr0<P1, P2, F>, I> Func; }; -// ConvertParams /////////////////////////////////////////////////////////////// +/* ConvertParams **************************************************************/ -// Template class that converts the function parameters if necessary, and -// ignores the HandlerData parameter if appropriate. -// -// Template parameter is the are FuncN function type. +/* Template class that converts the function parameters if necessary, and + * ignores the HandlerData parameter if appropriate. + * + * Template parameter is the are FuncN function type. */ template <class F, class T> struct ConvertParams; -// Function that discards the handler data parameter. +/* Function that discards the handler data parameter. */ template <class R, class P1, R F(P1)> R IgnoreHandlerData2(void *p1, const void *hd) { UPB_UNUSED(hd); @@ -741,7 +742,7 @@ R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2, return F(static_cast<P1>(p1), p2, p3); } -// Function that casts the handler data parameter. +/* Function that casts the handler data parameter. */ template <class R, class P1, class P2, R F(P1, P2)> R CastHandlerData2(void *c, const void *hd) { return F(static_cast<P1>(c), static_cast<P2>(hd)); @@ -766,7 +767,7 @@ R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3, return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4); } -// For unbound functions, ignore the handler data. +/* For unbound functions, ignore the handler data. */ template <class R, class P1, R F(P1), class I, class T> struct ConvertParams<Func1<R, P1, F, I>, T> { typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func; @@ -780,8 +781,8 @@ struct ConvertParams<Func2<R, P1, P2, F, I>, IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func; }; -// For StringBuffer only; this ignores both the handler data and the -// BufferHandle. +/* For StringBuffer only; this ignores both the handler data and the + * BufferHandle. */ template <class R, class P1, R F(P1, const char *, size_t), class I, class T> struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> { typedef Func5<R, void *, const void *, const char *, size_t, @@ -796,7 +797,7 @@ struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> { IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func; }; -// For bound functions, cast the handler data. +/* For bound functions, cast the handler data. */ template <class R, class P1, class P2, R F(P1, P2), class I, class T> struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> { typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I> @@ -811,7 +812,7 @@ struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>, CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func; }; -// For StringBuffer only; this ignores the BufferHandle. +/* For StringBuffer only; this ignores the BufferHandle. */ template <class R, class P1, class P2, R F(P1, P2, const char *, size_t), class I, class T> struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> { @@ -827,8 +828,8 @@ struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> { CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func; }; -// utype/ltype are upper/lower-case, ctype is canonical C type, vtype is -// variant C type. +/* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is + * variant C type. */ #define TYPE_METHODS(utype, ltype, ctype, vtype) \ template <> struct CanonicalType<vtype> { \ typedef ctype Type; \ @@ -843,22 +844,22 @@ struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> { return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \ } \ -TYPE_METHODS(Double, double, double, double); -TYPE_METHODS(Float, float, float, float); -TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T); -TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T); -TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T); -TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T); -TYPE_METHODS(Bool, bool, bool, bool); +TYPE_METHODS(Double, double, double, double) +TYPE_METHODS(Float, float, float, float) +TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T) +TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T) +TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T) +TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T) +TYPE_METHODS(Bool, bool, bool, bool) #ifdef UPB_TWO_32BIT_TYPES -TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T); -TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T); +TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T) +TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T) #endif #ifdef UPB_TWO_64BIT_TYPES -TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T); -TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T); +TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T) +TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T) #endif #undef TYPE_METHODS @@ -866,7 +867,8 @@ template <> struct CanonicalType<Status*> { typedef Status* Type; }; -// Type methods that are only one-per-canonical-type and not one-per-cvariant. +/* Type methods that are only one-per-canonical-type and not + * one-per-cvariant. */ #define TYPE_METHODS(utype, ctype) \ inline bool Handlers::Set##utype##Handler(const FieldDef *f, \ @@ -874,13 +876,13 @@ template <> struct CanonicalType<Status*> { return SetValueHandler<ctype>(f, h); \ } \ -TYPE_METHODS(Double, double); -TYPE_METHODS(Float, float); -TYPE_METHODS(UInt64, uint64_t); -TYPE_METHODS(UInt32, uint32_t); -TYPE_METHODS(Int64, int64_t); -TYPE_METHODS(Int32, int32_t); -TYPE_METHODS(Bool, bool); +TYPE_METHODS(Double, double) +TYPE_METHODS(Float, float) +TYPE_METHODS(UInt64, uint64_t) +TYPE_METHODS(UInt32, uint32_t) +TYPE_METHODS(Int64, int64_t) +TYPE_METHODS(Int32, int32_t) +TYPE_METHODS(Bool, bool) #undef TYPE_METHODS template <class F> struct ReturnOf; @@ -923,23 +925,23 @@ inline Handler<T>::Handler(F func) ReturnWrappedFunc; handler_ = ReturnWrappedFunc().Call; - // Set attributes based on what templates can statically tell us about the - // user's function. + /* Set attributes based on what templates can statically tell us about the + * user's function. */ - // If the original function returns void, then we know that we wrapped it to - // always return ok. + /* If the original function returns void, then we know that we wrapped it to + * always return ok. */ bool always_ok = is_same<typename F::FuncInfo::Return, void>::value; attr_.SetAlwaysOk(always_ok); - // Closure parameter and return type. + /* Closure parameter and return type. */ attr_.SetClosureType(UniquePtrForType<typename F::FuncInfo::Closure>()); - // We use the closure type (from the first parameter) if the return type is - // void or bool, since these are the two cases we wrap to return the closure's - // type anyway. - // - // This is all nonsense for non START* handlers, but it doesn't matter because - // in that case the value will be ignored. + /* We use the closure type (from the first parameter) if the return type is + * void or bool, since these are the two cases we wrap to return the closure's + * type anyway. + * + * This is all nonsense for non START* handlers, but it doesn't matter because + * in that case the value will be ignored. */ typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return, typename F::FuncInfo::Closure>::value EffectiveReturn; @@ -1010,19 +1012,6 @@ inline reffed_ptr<const Handlers> Handlers::NewFrozen( const upb_handlers *h = upb_handlers_newfrozen(m, &h, callback, closure); return reffed_ptr<const Handlers>(h, &h); } -inline bool Handlers::IsFrozen() const { return upb_handlers_isfrozen(this); } -inline void Handlers::Ref(const void *owner) const { - upb_handlers_ref(this, owner); -} -inline void Handlers::Unref(const void *owner) const { - upb_handlers_unref(this, owner); -} -inline void Handlers::DonateRef(const void *from, const void *to) const { - upb_handlers_donateref(this, from, to); -} -inline void Handlers::CheckRef(const void *owner) const { - upb_handlers_checkref(this, owner); -} inline const Status* Handlers::status() { return upb_handlers_status(this); } @@ -1138,9 +1127,9 @@ inline BytesHandler::BytesHandler() { inline BytesHandler::~BytesHandler() {} -} // namespace upb +} /* namespace upb */ -#endif // __cplusplus +#endif /* __cplusplus */ #undef UPB_TWO_32BIT_TYPES @@ -1154,4 +1143,4 @@ inline BytesHandler::~BytesHandler() {} #undef UPB_INT64ALT_T #undef UPB_UINT64ALT_T -#endif // UPB_HANDLERS_INL_H_ +#endif /* UPB_HANDLERS_INL_H_ */ |