diff options
author | Josh Haberman <jhaberman@gmail.com> | 2014-07-29 16:12:53 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2014-07-29 16:12:53 -0700 |
commit | 43f2455cbda22c513f2885d760ca2766b23e100f (patch) | |
tree | 3068031b1f5cc16e530ad25408a3c5a7554a7a28 /upb/handlers-inl.h | |
parent | d493500abc6def6b62d664990ed821e0a836a6cf (diff) |
Added UPB_UNTRACKED_REF and some more handler overload options.
Diffstat (limited to 'upb/handlers-inl.h')
-rw-r--r-- | upb/handlers-inl.h | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/upb/handlers-inl.h b/upb/handlers-inl.h index b4ba4a3..14ecb41 100644 --- a/upb/handlers-inl.h +++ b/upb/handlers-inl.h @@ -586,6 +586,17 @@ void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); } +// 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; +} + +template <class P1, class P2, class P3, bool F(P1, P2, P3)> +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. template <class P1, class P2, void F(P1, P2, const char *, size_t, const BufferHandle *)> @@ -595,6 +606,15 @@ 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. +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, + const BufferHandle *p5) { + 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. template <class P1, class P2, void F(P1, P2), class I> @@ -619,17 +639,6 @@ 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 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< - Func5<void, P1, P2, const char *, size_t, const BufferHandle *, F, I>, - size_t> { - typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *, - ReturnStringLen<P1, P2, F>, I> Func; -}; - // 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> @@ -645,6 +654,41 @@ 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. +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; +}; + +template <class P1, class P2, class P3, bool F(P1, P2, P3), class I> +struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> { + typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I> + Func; +}; + +// 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< + Func5<void, P1, P2, const char *, size_t, const BufferHandle *, F, I>, + size_t> { + typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *, + 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. +template <class P1, class P2, + bool F(P1, P2, const char *, size_t, const BufferHandle *), class I> +struct MaybeWrapReturn< + Func5<bool, P1, P2, const char *, size_t, const BufferHandle *, F, I>, + size_t> { + typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *, + ReturnNOr0<P1, P2, F>, I> Func; +}; + // ConvertParams /////////////////////////////////////////////////////////////// // Template class that converts the function parameters if necessary, and |