| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #define GOOGLE_PROTOBUF_DESCRIPTOR_H__ | 55 #define GOOGLE_PROTOBUF_DESCRIPTOR_H__ |
| 56 | 56 |
| 57 #include <memory> | 57 #include <memory> |
| 58 #ifndef _SHARED_PTR_H | 58 #ifndef _SHARED_PTR_H |
| 59 #include <google/protobuf/stubs/shared_ptr.h> | 59 #include <google/protobuf/stubs/shared_ptr.h> |
| 60 #endif | 60 #endif |
| 61 #include <set> | 61 #include <set> |
| 62 #include <string> | 62 #include <string> |
| 63 #include <vector> | 63 #include <vector> |
| 64 #include <google/protobuf/stubs/common.h> | 64 #include <google/protobuf/stubs/common.h> |
| 65 #include <google/protobuf/stubs/mutex.h> | 65 #include <google/protobuf/stubs/scoped_ptr.h> |
| 66 | 66 |
| 67 // TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. | 67 // TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. |
| 68 #ifdef TYPE_BOOL | 68 #ifdef TYPE_BOOL |
| 69 #undef TYPE_BOOL | 69 #undef TYPE_BOOL |
| 70 #endif // TYPE_BOOL | 70 #endif // TYPE_BOOL |
| 71 | 71 |
| 72 namespace google { | 72 namespace google { |
| 73 namespace protobuf { | 73 namespace protobuf { |
| 74 | 74 |
| 75 // Defined in this file. | 75 // Defined in this file. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 class DescriptorProto; | 88 class DescriptorProto; |
| 89 class FieldDescriptorProto; | 89 class FieldDescriptorProto; |
| 90 class OneofDescriptorProto; | 90 class OneofDescriptorProto; |
| 91 class EnumDescriptorProto; | 91 class EnumDescriptorProto; |
| 92 class EnumValueDescriptorProto; | 92 class EnumValueDescriptorProto; |
| 93 class ServiceDescriptorProto; | 93 class ServiceDescriptorProto; |
| 94 class MethodDescriptorProto; | 94 class MethodDescriptorProto; |
| 95 class FileDescriptorProto; | 95 class FileDescriptorProto; |
| 96 class MessageOptions; | 96 class MessageOptions; |
| 97 class FieldOptions; | 97 class FieldOptions; |
| 98 class OneofOptions; | |
| 99 class EnumOptions; | 98 class EnumOptions; |
| 100 class EnumValueOptions; | 99 class EnumValueOptions; |
| 101 class ServiceOptions; | 100 class ServiceOptions; |
| 102 class MethodOptions; | 101 class MethodOptions; |
| 103 class FileOptions; | 102 class FileOptions; |
| 104 class UninterpretedOption; | 103 class UninterpretedOption; |
| 105 class SourceCodeInfo; | 104 class SourceCodeInfo; |
| 106 | 105 |
| 107 // Defined in message.h | 106 // Defined in message.h |
| 108 class Message; | 107 class Message; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 137 struct SourceLocation { | 136 struct SourceLocation { |
| 138 int start_line; | 137 int start_line; |
| 139 int end_line; | 138 int end_line; |
| 140 int start_column; | 139 int start_column; |
| 141 int end_column; | 140 int end_column; |
| 142 | 141 |
| 143 // Doc comments found at the source location. | 142 // Doc comments found at the source location. |
| 144 // See the comments in SourceCodeInfo.Location (descriptor.proto) for details. | 143 // See the comments in SourceCodeInfo.Location (descriptor.proto) for details. |
| 145 string leading_comments; | 144 string leading_comments; |
| 146 string trailing_comments; | 145 string trailing_comments; |
| 147 std::vector<string> leading_detached_comments; | 146 vector<string> leading_detached_comments; |
| 148 }; | 147 }; |
| 149 | 148 |
| 150 // Options when generating machine-parsable output from a descriptor with | 149 // Options when generating machine-parsable output from a descriptor with |
| 151 // DebugString(). | 150 // DebugString(). |
| 152 struct DebugStringOptions { | 151 struct DebugStringOptions { |
| 153 // include original user comments as recorded in SourceLocation entries. N.B. | 152 // include original user comments as recorded in SourceLocation entries. N.B. |
| 154 // that this must be |false| by default: several other pieces of code (for | 153 // that this must be |false| by default: several other pieces of code (for |
| 155 // example, the C++ code generation for fields in the proto compiler) rely on | 154 // example, the C++ code generation for fields in the proto compiler) rely on |
| 156 // DebugString() output being unobstructed by user comments. | 155 // DebugString() output being unobstructed by user comments. |
| 157 bool include_comments; | 156 bool include_comments; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 bool is_map() const; // shorthand for type() == TYPE_MESSAGE && | 551 bool is_map() const; // shorthand for type() == TYPE_MESSAGE && |
| 553 // message_type()->options().map_entry() | 552 // message_type()->options().map_entry() |
| 554 | 553 |
| 555 // Index of this field within the message's field array, or the file or | 554 // Index of this field within the message's field array, or the file or |
| 556 // extension scope's extensions array. | 555 // extension scope's extensions array. |
| 557 int index() const; | 556 int index() const; |
| 558 | 557 |
| 559 // Does this field have an explicitly-declared default value? | 558 // Does this field have an explicitly-declared default value? |
| 560 bool has_default_value() const; | 559 bool has_default_value() const; |
| 561 | 560 |
| 562 // Whether the user has specified the json_name field option in the .proto | |
| 563 // file. | |
| 564 bool has_json_name() const; | |
| 565 | |
| 566 // Get the field default value if cpp_type() == CPPTYPE_INT32. If no | 561 // Get the field default value if cpp_type() == CPPTYPE_INT32. If no |
| 567 // explicit default was defined, the default is 0. | 562 // explicit default was defined, the default is 0. |
| 568 int32 default_value_int32() const; | 563 int32 default_value_int32() const; |
| 569 // Get the field default value if cpp_type() == CPPTYPE_INT64. If no | 564 // Get the field default value if cpp_type() == CPPTYPE_INT64. If no |
| 570 // explicit default was defined, the default is 0. | 565 // explicit default was defined, the default is 0. |
| 571 int64 default_value_int64() const; | 566 int64 default_value_int64() const; |
| 572 // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no | 567 // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no |
| 573 // explicit default was defined, the default is 0. | 568 // explicit default was defined, the default is 0. |
| 574 uint32 default_value_uint32() const; | 569 uint32 default_value_uint32() const; |
| 575 // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no | 570 // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 void GetLocationPath(std::vector<int>* output) const; | 676 void GetLocationPath(std::vector<int>* output) const; |
| 682 | 677 |
| 683 const string* name_; | 678 const string* name_; |
| 684 const string* full_name_; | 679 const string* full_name_; |
| 685 const string* lowercase_name_; | 680 const string* lowercase_name_; |
| 686 const string* camelcase_name_; | 681 const string* camelcase_name_; |
| 687 // Whether the user has specified the json_name field option in the .proto | 682 // Whether the user has specified the json_name field option in the .proto |
| 688 // file. | 683 // file. |
| 689 bool has_json_name_; | 684 bool has_json_name_; |
| 690 // If has_json_name_ is true, it's the value specified by the user. | 685 // If has_json_name_ is true, it's the value specified by the user. |
| 691 // Otherwise, it has the same value as camelcase_name_. | 686 // Otherwise, it has the same value as lowercase_name_. |
| 692 const string* json_name_; | 687 const string* json_name_; |
| 693 const FileDescriptor* file_; | 688 const FileDescriptor* file_; |
| 694 int number_; | 689 int number_; |
| 695 Type type_; | 690 Type type_; |
| 696 Label label_; | 691 Label label_; |
| 697 bool is_extension_; | 692 bool is_extension_; |
| 698 int index_in_oneof_; | 693 int index_in_oneof_; |
| 699 const Descriptor* containing_type_; | 694 const Descriptor* containing_type_; |
| 700 const OneofDescriptor* containing_oneof_; | 695 const OneofDescriptor* containing_oneof_; |
| 701 const Descriptor* extension_scope_; | 696 const Descriptor* extension_scope_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 743 |
| 749 // The Descriptor for the message containing this oneof. | 744 // The Descriptor for the message containing this oneof. |
| 750 const Descriptor* containing_type() const; | 745 const Descriptor* containing_type() const; |
| 751 | 746 |
| 752 // The number of (non-extension) fields which are members of this oneof. | 747 // The number of (non-extension) fields which are members of this oneof. |
| 753 int field_count() const; | 748 int field_count() const; |
| 754 // Get a member of this oneof, in the order in which they were declared in the | 749 // Get a member of this oneof, in the order in which they were declared in the |
| 755 // .proto file. Does not include extensions. | 750 // .proto file. Does not include extensions. |
| 756 const FieldDescriptor* field(int index) const; | 751 const FieldDescriptor* field(int index) const; |
| 757 | 752 |
| 758 const OneofOptions& options() const; | |
| 759 | |
| 760 // See Descriptor::CopyTo(). | 753 // See Descriptor::CopyTo(). |
| 761 void CopyTo(OneofDescriptorProto* proto) const; | 754 void CopyTo(OneofDescriptorProto* proto) const; |
| 762 | 755 |
| 763 // See Descriptor::DebugString(). | 756 // See Descriptor::DebugString(). |
| 764 string DebugString() const; | 757 string DebugString() const; |
| 765 | 758 |
| 766 // See Descriptor::DebugStringWithOptions(). | 759 // See Descriptor::DebugStringWithOptions(). |
| 767 string DebugStringWithOptions(const DebugStringOptions& options) const; | 760 string DebugStringWithOptions(const DebugStringOptions& options) const; |
| 768 | 761 |
| 769 // Source Location --------------------------------------------------- | 762 // Source Location --------------------------------------------------- |
| 770 | 763 |
| 771 // Updates |*out_location| to the source location of the complete | 764 // Updates |*out_location| to the source location of the complete |
| 772 // extent of this oneof declaration. Returns false and leaves | 765 // extent of this oneof declaration. Returns false and leaves |
| 773 // |*out_location| unchanged iff location information was not available. | 766 // |*out_location| unchanged iff location information was not available. |
| 774 bool GetSourceLocation(SourceLocation* out_location) const; | 767 bool GetSourceLocation(SourceLocation* out_location) const; |
| 775 | 768 |
| 776 private: | 769 private: |
| 777 typedef OneofOptions OptionsType; | |
| 778 | |
| 779 // Allows access to GetLocationPath for annotations. | 770 // Allows access to GetLocationPath for annotations. |
| 780 friend class ::google::protobuf::io::Printer; | 771 friend class ::google::protobuf::io::Printer; |
| 781 | 772 |
| 782 // See Descriptor::DebugString(). | 773 // See Descriptor::DebugString(). |
| 783 void DebugString(int depth, string* contents, | 774 void DebugString(int depth, string* contents, |
| 784 const DebugStringOptions& options) const; | 775 const DebugStringOptions& options) const; |
| 785 | 776 |
| 786 // Walks up the descriptor tree to generate the source location path | 777 // Walks up the descriptor tree to generate the source location path |
| 787 // to this descriptor from the file root. | 778 // to this descriptor from the file root. |
| 788 void GetLocationPath(std::vector<int>* output) const; | 779 void GetLocationPath(std::vector<int>* output) const; |
| 789 | 780 |
| 790 const string* name_; | 781 const string* name_; |
| 791 const string* full_name_; | 782 const string* full_name_; |
| 792 const Descriptor* containing_type_; | 783 const Descriptor* containing_type_; |
| 793 bool is_extendable_; | 784 bool is_extendable_; |
| 794 int field_count_; | 785 int field_count_; |
| 795 const FieldDescriptor** fields_; | 786 const FieldDescriptor** fields_; |
| 796 const OneofOptions* options_; | |
| 797 | |
| 798 // IMPORTANT: If you add a new field, make sure to search for all instances | 787 // IMPORTANT: If you add a new field, make sure to search for all instances |
| 799 // of Allocate<OneofDescriptor>() and AllocateArray<OneofDescriptor>() | 788 // of Allocate<OneofDescriptor>() and AllocateArray<OneofDescriptor>() |
| 800 // in descriptor.cc and update them to initialize the field. | 789 // in descriptor.cc and update them to initialize the field. |
| 801 | 790 |
| 802 // Must be constructed using DescriptorPool. | 791 // Must be constructed using DescriptorPool. |
| 803 OneofDescriptor() {} | 792 OneofDescriptor() {} |
| 804 friend class DescriptorBuilder; | 793 friend class DescriptorBuilder; |
| 805 friend class Descriptor; | 794 friend class Descriptor; |
| 806 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor); | 795 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor); |
| 807 }; | 796 }; |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) | 1686 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) |
| 1698 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) | 1687 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) |
| 1699 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_oneof, | 1688 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_oneof, |
| 1700 const OneofDescriptor*) | 1689 const OneofDescriptor*) |
| 1701 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int) | 1690 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int) |
| 1702 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) | 1691 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) |
| 1703 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) | 1692 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) |
| 1704 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) | 1693 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) |
| 1705 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) | 1694 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) |
| 1706 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) | 1695 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) |
| 1707 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool) | |
| 1708 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) | 1696 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) |
| 1709 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) | 1697 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) |
| 1710 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) | 1698 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) |
| 1711 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) | 1699 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) |
| 1712 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) | 1700 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) |
| 1713 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) | 1701 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) |
| 1714 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) | 1702 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) |
| 1715 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, | 1703 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, |
| 1716 const EnumValueDescriptor*) | 1704 const EnumValueDescriptor*) |
| 1717 PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) | 1705 PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) |
| 1718 | 1706 |
| 1719 PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, name) | 1707 PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, name) |
| 1720 PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, full_name) | 1708 PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, full_name) |
| 1721 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*) | 1709 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*) |
| 1722 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int) | 1710 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int) |
| 1723 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(OneofDescriptor, OneofOptions) | |
| 1724 | 1711 |
| 1725 PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, name) | 1712 PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, name) |
| 1726 PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, full_name) | 1713 PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, full_name) |
| 1727 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) | 1714 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) |
| 1728 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) | 1715 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) |
| 1729 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) | 1716 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) |
| 1730 PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, | 1717 PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, |
| 1731 const EnumValueDescriptor*) | 1718 const EnumValueDescriptor*) |
| 1732 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions) | 1719 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions) |
| 1733 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool) | 1720 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 // Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because fields_ is actually an array | 1903 // Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because fields_ is actually an array |
| 1917 // of pointers rather than the usual array of objects. | 1904 // of pointers rather than the usual array of objects. |
| 1918 inline const FieldDescriptor* OneofDescriptor::field(int index) const { | 1905 inline const FieldDescriptor* OneofDescriptor::field(int index) const { |
| 1919 return fields_[index]; | 1906 return fields_[index]; |
| 1920 } | 1907 } |
| 1921 | 1908 |
| 1922 } // namespace protobuf | 1909 } // namespace protobuf |
| 1923 | 1910 |
| 1924 } // namespace google | 1911 } // namespace google |
| 1925 #endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ | 1912 #endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ |
| OLD | NEW |