diff options
Diffstat (limited to 'upb/pb/textprinter.h')
-rw-r--r-- | upb/pb/textprinter.h | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/upb/pb/textprinter.h b/upb/pb/textprinter.h index 2f40ed8..0af2b1a 100644 --- a/upb/pb/textprinter.h +++ b/upb/pb/textprinter.h @@ -12,68 +12,57 @@ #ifdef __cplusplus namespace upb { namespace pb { -class TextPrinter; +class TextPrinterPtr; } /* namespace pb */ } /* namespace upb */ #endif -UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter) +/* upb_textprinter ************************************************************/ + +struct upb_textprinter; +typedef struct upb_textprinter upb_textprinter; + +#ifdef __cplusplus +extern "C" { +#endif + +/* C API. */ +upb_textprinter *upb_textprinter_create(upb_arena *arena, const upb_handlers *h, + upb_bytessink output); +void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line); +upb_sink upb_textprinter_input(upb_textprinter *p); +upb_handlercache *upb_textprinter_newcache(); #ifdef __cplusplus +} /* extern "C" */ -class upb::pb::TextPrinter { +class upb::pb::TextPrinterPtr { public: + TextPrinterPtr(upb_textprinter* ptr) : ptr_(ptr) {} + /* The given handlers must have come from NewHandlers(). It must outlive the * TextPrinter. */ - static TextPrinter *Create(Environment *env, const upb::Handlers *handlers, - BytesSink *output); + static TextPrinterPtr Create(Arena *arena, upb::HandlersPtr *handlers, + BytesSink output) { + return TextPrinterPtr( + upb_textprinter_create(arena->ptr(), handlers->ptr(), output.sink())); + } - void SetSingleLineMode(bool single_line); + void SetSingleLineMode(bool single_line) { + upb_textprinter_setsingleline(ptr_, single_line); + } - Sink* input(); + Sink input() { return upb_textprinter_input(ptr_); } /* If handler caching becomes a requirement we can add a code cache as in * decoder.h */ - static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md); -}; - -#endif - -UPB_BEGIN_EXTERN_C + static HandlerCache NewCache() { + return HandlerCache(upb_textprinter_newcache()); + } -/* C API. */ -upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h, - upb_bytessink *output); -void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line); -upb_sink *upb_textprinter_input(upb_textprinter *p); - -const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m, - const void *owner); - -UPB_END_EXTERN_C - -#ifdef __cplusplus - -namespace upb { -namespace pb { -inline TextPrinter *TextPrinter::Create(Environment *env, - const upb::Handlers *handlers, - BytesSink *output) { - return upb_textprinter_create(env, handlers, output); -} -inline void TextPrinter::SetSingleLineMode(bool single_line) { - upb_textprinter_setsingleline(this, single_line); -} -inline Sink* TextPrinter::input() { - return upb_textprinter_input(this); -} -inline reffed_ptr<const Handlers> TextPrinter::NewHandlers( - const MessageDef *md) { - const Handlers* h = upb_textprinter_newhandlers(md, &h); - return reffed_ptr<const Handlers>(h, &h); -} -} /* namespace pb */ -} /* namespace upb */ + private: + upb_textprinter* ptr_; +}; #endif |