From 8f2758dda2ba12b78ae8f8c7170decc5e88dd28c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 3 Sep 2011 11:14:18 -0700 Subject: Work on C++ wrappers, added C++ test. --- bindings/cpp/upb/def.hpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bindings/cpp/upb/def.hpp (limited to 'bindings/cpp/upb/def.hpp') diff --git a/bindings/cpp/upb/def.hpp b/bindings/cpp/upb/def.hpp new file mode 100644 index 0000000..6500243 --- /dev/null +++ b/bindings/cpp/upb/def.hpp @@ -0,0 +1,49 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2011 Google Inc. See LICENSE for details. + * Author: Josh Haberman + * + * The set of upb::*Def classes and upb::SymbolTable allow for defining and + * manipulating schema information (as defined in .proto files). + */ + +#ifndef UPB_DEF_HPP +#define UPB_DEF_HPP + +#include "upb/def.h" + +namespace upb { + +class MessageDef : public upb_msgdef { + public: + static MessageDef* Cast(upb_msgdef *md) { return (MessageDef*)md; } + + void Unref() { return upb_msgdef_unref(this); } + + private: + MessageDef(); + ~MessageDef(); +}; + +class SymbolTable : public upb_symtab { + public: + static SymbolTable* Cast(upb_symtab *s) { return (SymbolTable*)s; } + static SymbolTable* New() { return Cast(upb_symtab_new()); } + + void Unref() { return upb_symtab_unref(this); } + + // If the given name refers to a message in this symbol table, returns a new + // ref to that MessageDef object, otherwise returns NULL. + MessageDef* LookupMessage(const char *name) { + return MessageDef::Cast(upb_symtab_lookupmsg(this, name)); + } + + private: + SymbolTable(); + ~SymbolTable(); +}; + +} // namespace upb + +#endif -- cgit v1.2.3