Re-added const for all of the pointer wrapper types.

pull/13171/head
Joshua Haberman 4 years ago
parent 5aa5b77b41
commit 575acd85bd
  1. 166
      upb/def.hpp

@ -24,21 +24,21 @@ class FieldDefPtr {
FieldDefPtr() : ptr_(nullptr) {}
explicit FieldDefPtr(const upb_fielddef* ptr) : ptr_(ptr) {}
const upb_fielddef* ptr() { return ptr_; }
explicit operator bool() { return ptr_ != nullptr; }
const upb_fielddef* ptr() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
typedef upb_fieldtype_t Type;
typedef upb_label_t Label;
typedef upb_descriptortype_t DescriptorType;
const char* full_name() { return upb_fielddef_fullname(ptr_); }
const char* full_name() const { return upb_fielddef_fullname(ptr_); }
Type type() { return upb_fielddef_type(ptr_); }
Label label() { return upb_fielddef_label(ptr_); }
const char* name() { return upb_fielddef_name(ptr_); }
const char* json_name() { return upb_fielddef_jsonname(ptr_); }
uint32_t number() { return upb_fielddef_number(ptr_); }
bool is_extension() { return upb_fielddef_isextension(ptr_); }
Type type() const { return upb_fielddef_type(ptr_); }
Label label() const { return upb_fielddef_label(ptr_); }
const char* name() const { return upb_fielddef_name(ptr_); }
const char* json_name() const { return upb_fielddef_jsonname(ptr_); }
uint32_t number() const { return upb_fielddef_number(ptr_); }
bool is_extension() const { return upb_fielddef_isextension(ptr_); }
// For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
// indicates whether this field should have lazy parsing handlers that yield
@ -47,20 +47,20 @@ class FieldDefPtr {
// TODO(haberman): I think we want to move this into a FieldOptions container
// when we add support for custom options (the FieldOptions struct will
// contain both regular FieldOptions like "lazy" *and* custom options).
bool lazy() { return upb_fielddef_lazy(ptr_); }
bool lazy() const { return upb_fielddef_lazy(ptr_); }
// For non-string, non-submessage fields, this indicates whether binary
// protobufs are encoded in packed or non-packed format.
//
// TODO(haberman): see note above about putting options like this into a
// FieldOptions container.
bool packed() { return upb_fielddef_packed(ptr_); }
bool packed() const { return upb_fielddef_packed(ptr_); }
// An integer that can be used as an index into an array of fields for
// whatever message this field belongs to. Guaranteed to be less than
// f->containing_type()->field_count(). May only be accessed once the def has
// been finalized.
uint32_t index() { return upb_fielddef_index(ptr_); }
uint32_t index() const { return upb_fielddef_index(ptr_); }
// The MessageDef to which this field belongs.
//
@ -70,27 +70,27 @@ class FieldDefPtr {
// If the field has not yet been added to a MessageDef, you can set the name
// of the containing type symbolically instead. This is mostly useful for
// extensions, where the extension is declared separately from the message.
MessageDefPtr containing_type();
MessageDefPtr containing_type() const;
// The OneofDef to which this field belongs, or NULL if this field is not part
// of a oneof.
OneofDefPtr containing_oneof();
OneofDefPtr containing_oneof() const;
// The field's type according to the enum in descriptor.proto. This is not
// the same as UPB_TYPE_*, because it distinguishes between (for example)
// INT32 and SINT32, whereas our "type" enum does not. This return of
// descriptor_type() is a function of type(), integer_format(), and
// is_tag_delimited().
DescriptorType descriptor_type() {
DescriptorType descriptor_type() const {
return upb_fielddef_descriptortype(ptr_);
}
// Convenient field type tests.
bool IsSubMessage() { return upb_fielddef_issubmsg(ptr_); }
bool IsString() { return upb_fielddef_isstring(ptr_); }
bool IsSequence() { return upb_fielddef_isseq(ptr_); }
bool IsPrimitive() { return upb_fielddef_isprimitive(ptr_); }
bool IsMap() { return upb_fielddef_ismap(ptr_); }
bool IsSubMessage() const { return upb_fielddef_issubmsg(ptr_); }
bool IsString() const { return upb_fielddef_isstring(ptr_); }
bool IsSequence() const { return upb_fielddef_isseq(ptr_); }
bool IsPrimitive() const { return upb_fielddef_isprimitive(ptr_); }
bool IsMap() const { return upb_fielddef_ismap(ptr_); }
// Returns the non-string default value for this fielddef, which may either
// be something the client set explicitly or the "default default" (0 for
@ -98,25 +98,25 @@ class FieldDefPtr {
// returned value, except for enum fields that are still mutable.
//
// Requires that the given function matches the field's current type.
int64_t default_int64() { return upb_fielddef_defaultint64(ptr_); }
int32_t default_int32() { return upb_fielddef_defaultint32(ptr_); }
uint64_t default_uint64() { return upb_fielddef_defaultuint64(ptr_); }
uint32_t default_uint32() { return upb_fielddef_defaultuint32(ptr_); }
bool default_bool() { return upb_fielddef_defaultbool(ptr_); }
float default_float() { return upb_fielddef_defaultfloat(ptr_); }
double default_double() { return upb_fielddef_defaultdouble(ptr_); }
int64_t default_int64() const { return upb_fielddef_defaultint64(ptr_); }
int32_t default_int32() const { return upb_fielddef_defaultint32(ptr_); }
uint64_t default_uint64() const { return upb_fielddef_defaultuint64(ptr_); }
uint32_t default_uint32() const { return upb_fielddef_defaultuint32(ptr_); }
bool default_bool() const { return upb_fielddef_defaultbool(ptr_); }
float default_float() const { return upb_fielddef_defaultfloat(ptr_); }
double default_double() const { return upb_fielddef_defaultdouble(ptr_); }
// The resulting string is always NULL-terminated. If non-NULL, the length
// will be stored in *len.
const char* default_string(size_t* len) {
const char* default_string(size_t* len) const {
return upb_fielddef_defaultstr(ptr_, len);
}
// Returns the enum or submessage def for this field, if any. The field's
// type must match (ie. you may only call enum_subdef() for fields where
// type() == UPB_TYPE_ENUM).
EnumDefPtr enum_subdef();
MessageDefPtr message_subdef();
EnumDefPtr enum_subdef() const;
MessageDefPtr message_subdef() const;
private:
const upb_fielddef* ptr_;
@ -128,34 +128,34 @@ class OneofDefPtr {
OneofDefPtr() : ptr_(nullptr) {}
explicit OneofDefPtr(const upb_oneofdef* ptr) : ptr_(ptr) {}
const upb_oneofdef* ptr() { return ptr_; }
explicit operator bool() { return ptr_ != nullptr; }
const upb_oneofdef* ptr() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
// Returns the MessageDef that contains this OneofDef.
MessageDefPtr containing_type();
MessageDefPtr containing_type() const;
// Returns the name of this oneof.
const char* name() { return upb_oneofdef_name(ptr_); }
const char* name() const { return upb_oneofdef_name(ptr_); }
// Returns the number of fields in the oneof.
int field_count() { return upb_oneofdef_numfields(ptr_); }
FieldDefPtr field(int i) { return FieldDefPtr(upb_oneofdef_field(ptr_, i)); }
int field_count() const { return upb_oneofdef_numfields(ptr_); }
FieldDefPtr field(int i) const { return FieldDefPtr(upb_oneofdef_field(ptr_, i)); }
// Looks up by name.
FieldDefPtr FindFieldByName(const char* name, size_t len) {
FieldDefPtr FindFieldByName(const char* name, size_t len) const {
return FieldDefPtr(upb_oneofdef_ntof(ptr_, name, len));
}
FieldDefPtr FindFieldByName(const char* name) {
FieldDefPtr FindFieldByName(const char* name) const {
return FieldDefPtr(upb_oneofdef_ntofz(ptr_, name));
}
template <class T>
FieldDefPtr FindFieldByName(const T& str) {
FieldDefPtr FindFieldByName(const T& str) const {
return FindFieldByName(str.c_str(), str.size());
}
// Looks up by tag number.
FieldDefPtr FindFieldByNumber(uint32_t num) {
FieldDefPtr FindFieldByNumber(uint32_t num) const {
return FieldDefPtr(upb_oneofdef_itof(ptr_, num));
}
@ -169,62 +169,62 @@ class MessageDefPtr {
MessageDefPtr() : ptr_(nullptr) {}
explicit MessageDefPtr(const upb_msgdef* ptr) : ptr_(ptr) {}
const upb_msgdef* ptr() { return ptr_; }
explicit operator bool() { return ptr_ != nullptr; }
const upb_msgdef* ptr() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
const char* full_name() { return upb_msgdef_fullname(ptr_); }
const char* name() { return upb_msgdef_name(ptr_); }
const char* full_name() const { return upb_msgdef_fullname(ptr_); }
const char* name() const { return upb_msgdef_name(ptr_); }
// The number of fields that belong to the MessageDef.
int field_count() { return upb_msgdef_numfields(ptr_); }
FieldDefPtr field(int i) { return FieldDefPtr(upb_msgdef_field(ptr_, i)); }
int field_count() const { return upb_msgdef_numfields(ptr_); }
FieldDefPtr field(int i) const { return FieldDefPtr(upb_msgdef_field(ptr_, i)); }
// The number of oneofs that belong to the MessageDef.
int oneof_count() { return upb_msgdef_numoneofs(ptr_); }
OneofDefPtr oneof(int i) { return OneofDefPtr(upb_msgdef_oneof(ptr_, i)); }
int oneof_count() const { return upb_msgdef_numoneofs(ptr_); }
OneofDefPtr oneof(int i) const { return OneofDefPtr(upb_msgdef_oneof(ptr_, i)); }
upb_syntax_t syntax() { return upb_msgdef_syntax(ptr_); }
upb_syntax_t syntax() const { return upb_msgdef_syntax(ptr_); }
// These return null pointers if the field is not found.
FieldDefPtr FindFieldByNumber(uint32_t number) {
FieldDefPtr FindFieldByNumber(uint32_t number) const {
return FieldDefPtr(upb_msgdef_itof(ptr_, number));
}
FieldDefPtr FindFieldByName(const char* name, size_t len) {
FieldDefPtr FindFieldByName(const char* name, size_t len) const {
return FieldDefPtr(upb_msgdef_ntof(ptr_, name, len));
}
FieldDefPtr FindFieldByName(const char* name) {
FieldDefPtr FindFieldByName(const char* name) const {
return FieldDefPtr(upb_msgdef_ntofz(ptr_, name));
}
template <class T>
FieldDefPtr FindFieldByName(const T& str) {
FieldDefPtr FindFieldByName(const T& str) const {
return FindFieldByName(str.c_str(), str.size());
}
OneofDefPtr FindOneofByName(const char* name, size_t len) {
OneofDefPtr FindOneofByName(const char* name, size_t len) const {
return OneofDefPtr(upb_msgdef_ntoo(ptr_, name, len));
}
OneofDefPtr FindOneofByName(const char* name) {
OneofDefPtr FindOneofByName(const char* name) const {
return OneofDefPtr(upb_msgdef_ntooz(ptr_, name));
}
template <class T>
OneofDefPtr FindOneofByName(const T& str) {
OneofDefPtr FindOneofByName(const T& str) const {
return FindOneofByName(str.c_str(), str.size());
}
// Is this message a map entry?
bool mapentry() { return upb_msgdef_mapentry(ptr_); }
bool mapentry() const { return upb_msgdef_mapentry(ptr_); }
// Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
// non-well-known message.
upb_wellknowntype_t wellknowntype() {
upb_wellknowntype_t wellknowntype() const {
return upb_msgdef_wellknowntype(ptr_);
}
// Whether is a number wrapper.
bool isnumberwrapper() { return upb_msgdef_isnumberwrapper(ptr_); }
bool isnumberwrapper() const { return upb_msgdef_isnumberwrapper(ptr_); }
private:
class FieldIter {
@ -276,8 +276,8 @@ class MessageDefPtr {
};
public:
FieldAccessor fields() { return FieldAccessor(ptr()); }
OneofAccessor oneofs() { return OneofAccessor(ptr()); }
FieldAccessor fields() const { return FieldAccessor(ptr()); }
OneofAccessor oneofs() const { return OneofAccessor(ptr()); }
private:
const upb_msgdef* ptr_;
@ -288,32 +288,32 @@ class EnumDefPtr {
EnumDefPtr() : ptr_(nullptr) {}
explicit EnumDefPtr(const upb_enumdef* ptr) : ptr_(ptr) {}
const upb_enumdef* ptr() { return ptr_; }
explicit operator bool() { return ptr_ != nullptr; }
const upb_enumdef* ptr() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
const char* full_name() { return upb_enumdef_fullname(ptr_); }
const char* name() { return upb_enumdef_name(ptr_); }
const char* full_name() const { return upb_enumdef_fullname(ptr_); }
const char* name() const { return upb_enumdef_name(ptr_); }
// The value that is used as the default when no field default is specified.
// If not set explicitly, the first value that was added will be used.
// The default value must be a member of the enum.
// Requires that value_count() > 0.
int32_t default_value() { return upb_enumdef_default(ptr_); }
int32_t default_value() const { return upb_enumdef_default(ptr_); }
// Returns the number of values currently defined in the enum. Note that
// multiple names can refer to the same number, so this may be greater than
// the total number of unique numbers.
int value_count() { return upb_enumdef_numvals(ptr_); }
int value_count() const { return upb_enumdef_numvals(ptr_); }
// Lookups from name to integer, returning true if found.
bool FindValueByName(const char* name, int32_t* num) {
bool FindValueByName(const char* name, int32_t* num) const {
return upb_enumdef_ntoiz(ptr_, name, num);
}
// Finds the name corresponding to the given number, or NULL if none was
// found. If more than one name corresponds to this number, returns the
// first one that was added.
const char* FindValueByNumber(int32_t num) {
const char* FindValueByNumber(int32_t num) const {
return upb_enumdef_iton(ptr_, num);
}
@ -346,31 +346,31 @@ class FileDefPtr {
public:
explicit FileDefPtr(const upb_filedef* ptr) : ptr_(ptr) {}
const upb_filedef* ptr() { return ptr_; }
explicit operator bool() { return ptr_ != nullptr; }
const upb_filedef* ptr() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
// Get/set name of the file (eg. "foo/bar.proto").
const char* name() { return upb_filedef_name(ptr_); }
const char* name() const { return upb_filedef_name(ptr_); }
// Package name for definitions inside the file (eg. "foo.bar").
const char* package() { return upb_filedef_package(ptr_); }
const char* package() const { return upb_filedef_package(ptr_); }
// Sets the php class prefix which is prepended to all php generated classes
// from this .proto. Default is empty.
const char* phpprefix() { return upb_filedef_phpprefix(ptr_); }
const char* phpprefix() const { return upb_filedef_phpprefix(ptr_); }
// Use this option to change the namespace of php generated classes. Default
// is empty. When this option is empty, the package name will be used for
// determining the namespace.
const char* phpnamespace() { return upb_filedef_phpnamespace(ptr_); }
const char* phpnamespace() const { return upb_filedef_phpnamespace(ptr_); }
// Syntax for the file. Defaults to proto2.
upb_syntax_t syntax() { return upb_filedef_syntax(ptr_); }
upb_syntax_t syntax() const { return upb_filedef_syntax(ptr_); }
// Get the list of dependencies from the file. These are returned in the
// order that they were added to the FileDefPtr.
int dependency_count() { return upb_filedef_depcount(ptr_); }
const FileDefPtr dependency(int index) {
int dependency_count() const { return upb_filedef_depcount(ptr_); }
const FileDefPtr dependency(int index) const {
return FileDefPtr(upb_filedef_dep(ptr_, index));
}
@ -414,23 +414,23 @@ class SymbolTable {
std::unique_ptr<upb_symtab, decltype(&upb_symtab_free)> ptr_;
};
inline MessageDefPtr FieldDefPtr::message_subdef() {
inline MessageDefPtr FieldDefPtr::message_subdef() const {
return MessageDefPtr(upb_fielddef_msgsubdef(ptr_));
}
inline MessageDefPtr FieldDefPtr::containing_type() {
inline MessageDefPtr FieldDefPtr::containing_type() const {
return MessageDefPtr(upb_fielddef_containingtype(ptr_));
}
inline MessageDefPtr OneofDefPtr::containing_type() {
inline MessageDefPtr OneofDefPtr::containing_type() const {
return MessageDefPtr(upb_oneofdef_containingtype(ptr_));
}
inline OneofDefPtr FieldDefPtr::containing_oneof() {
inline OneofDefPtr FieldDefPtr::containing_oneof() const {
return OneofDefPtr(upb_fielddef_containingoneof(ptr_));
}
inline EnumDefPtr FieldDefPtr::enum_subdef() {
inline EnumDefPtr FieldDefPtr::enum_subdef() const {
return EnumDefPtr(upb_fielddef_enumsubdef(ptr_));
}

Loading…
Cancel
Save