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