diff options
Diffstat (limited to 'src/google/protobuf/descriptor_database.h')
-rw-r--r-- | src/google/protobuf/descriptor_database.h | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/src/google/protobuf/descriptor_database.h b/src/google/protobuf/descriptor_database.h index 0a87a147..48892af1 100644 --- a/src/google/protobuf/descriptor_database.h +++ b/src/google/protobuf/descriptor_database.h @@ -44,6 +44,12 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/descriptor.h> +#include <google/protobuf/port_def.inc> + +#ifdef SWIG +#define PROTOBUF_EXPORT +#endif + namespace google { namespace protobuf { @@ -62,27 +68,27 @@ class MergedDescriptorDatabase; // calling DescriptorPool::BuildFile() for each one. Instead, a DescriptorPool // can be created which wraps a DescriptorDatabase and only builds particular // descriptors when they are needed. -class LIBPROTOBUF_EXPORT DescriptorDatabase { +class PROTOBUF_EXPORT DescriptorDatabase { public: inline DescriptorDatabase() {} virtual ~DescriptorDatabase(); // Find a file by file name. Fills in in *output and returns true if found. // Otherwise, returns false, leaving the contents of *output undefined. - virtual bool FindFileByName(const string& filename, + virtual bool FindFileByName(const std::string& filename, FileDescriptorProto* output) = 0; // Find the file that declares the given fully-qualified symbol name. // If found, fills in *output and returns true, otherwise returns false // and leaves *output undefined. - virtual bool FindFileContainingSymbol(const string& symbol_name, + virtual bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) = 0; // Find the file which defines an extension extending the given message type // with the given field number. If found, fills in *output and returns true, // otherwise returns false and leaves *output undefined. containing_type // must be a fully-qualified type name. - virtual bool FindFileContainingExtension(const string& containing_type, + virtual bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) = 0; @@ -96,7 +102,7 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase { // // This method has a default implementation that always returns // false. - virtual bool FindAllExtensionNumbers(const string& /* extendee_type */, + virtual bool FindAllExtensionNumbers(const std::string& /* extendee_type */, std::vector<int>* /* output */) { return false; } @@ -110,7 +116,7 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase { // // This method has a default implementation that always returns // false. - virtual bool FindAllFileNames(std::vector<string>* output) { + virtual bool FindAllFileNames(std::vector<std::string>* output) { return false; } @@ -139,7 +145,7 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase { // FileDescriptor::CopyTo()) will always use fully-qualified names for all // types. You only need to worry if you are constructing FileDescriptorProtos // yourself, or are calling compiler::Parser directly. -class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { +class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { public: SimpleDescriptorDatabase(); ~SimpleDescriptorDatabase() override; @@ -154,17 +160,17 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { bool AddAndOwn(const FileDescriptorProto* file); // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, + bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const string& symbol_name, + bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) override; - bool FindFileContainingExtension(const string& containing_type, + bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) override; - bool FindAllExtensionNumbers(const string& extendee_type, + bool FindAllExtensionNumbers(const std::string& extendee_type, std::vector<int>* output) override; - bool FindAllFileNames(std::vector<string>* output) override; + bool FindAllFileNames(std::vector<std::string>* output) override; private: // So that it can use DescriptorIndex. @@ -179,23 +185,23 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { // to the index. bool AddFile(const FileDescriptorProto& file, Value value); - bool AddSymbol(const string& name, Value value); + bool AddSymbol(const std::string& name, Value value); bool AddNestedExtensions(const DescriptorProto& message_type, Value value); bool AddExtension(const FieldDescriptorProto& field, Value value); - Value FindFile(const string& filename); - Value FindSymbol(const string& name); - Value FindExtension(const string& containing_type, int field_number); - bool FindAllExtensionNumbers(const string& containing_type, + Value FindFile(const std::string& filename); + Value FindSymbol(const std::string& name); + Value FindExtension(const std::string& containing_type, int field_number); + bool FindAllExtensionNumbers(const std::string& containing_type, std::vector<int>* output); - void FindAllFileNames(std::vector<string>* output); + void FindAllFileNames(std::vector<std::string>* output); private: - std::map<string, Value> by_name_; - std::map<string, Value> by_symbol_; - std::map<std::pair<string, int>, Value> by_extension_; + std::map<std::string, Value> by_name_; + std::map<std::string, Value> by_symbol_; + std::map<std::pair<std::string, int>, Value> by_extension_; // Invariant: The by_symbol_ map does not contain any symbols which are // prefixes of other symbols in the map. For example, "foo.bar" is a @@ -250,17 +256,17 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { // Find the last entry in the by_symbol_ map whose key is less than or // equal to the given name. - typename std::map<string, Value>::iterator FindLastLessOrEqual( - const string& name); + typename std::map<std::string, Value>::iterator FindLastLessOrEqual( + const std::string& name); // True if either the arguments are equal or super_symbol identifies a // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of // "foo.bar.baz", but not a parent of "foo.barbaz"). - bool IsSubSymbol(const string& sub_symbol, const string& super_symbol); + bool IsSubSymbol(const std::string& sub_symbol, const std::string& super_symbol); // Returns true if and only if all characters in the name are alphanumerics, // underscores, or periods. - bool ValidateSymbolName(const string& name); + bool ValidateSymbolName(const std::string& name); }; @@ -280,7 +286,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { // // The same caveats regarding FindFileContainingExtension() apply as with // SimpleDescriptorDatabase. -class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { +class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { public: EncodedDescriptorDatabase(); ~EncodedDescriptorDatabase() override; @@ -298,18 +304,18 @@ class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { bool AddCopy(const void* encoded_file_descriptor, int size); // Like FindFileContainingSymbol but returns only the name of the file. - bool FindNameOfFileContainingSymbol(const string& symbol_name, - string* output); + bool FindNameOfFileContainingSymbol(const std::string& symbol_name, + std::string* output); // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, + bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const string& symbol_name, + bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) override; - bool FindFileContainingExtension(const string& containing_type, + bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) override; - bool FindAllExtensionNumbers(const string& extendee_type, + bool FindAllExtensionNumbers(const std::string& extendee_type, std::vector<int>* output) override; private: @@ -326,20 +332,20 @@ class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { }; // A DescriptorDatabase that fetches files from a given pool. -class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { +class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { public: explicit DescriptorPoolDatabase(const DescriptorPool& pool); ~DescriptorPoolDatabase() override; // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, + bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const string& symbol_name, + bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) override; - bool FindFileContainingExtension(const string& containing_type, + bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) override; - bool FindAllExtensionNumbers(const string& extendee_type, + bool FindAllExtensionNumbers(const std::string& extendee_type, std::vector<int>* output) override; private: @@ -349,7 +355,7 @@ class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { // A DescriptorDatabase that wraps two or more others. It first searches the // first database and, if that fails, tries the second, and so on. -class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { +class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { public: // Merge just two databases. The sources remain property of the caller. MergedDescriptorDatabase(DescriptorDatabase* source1, @@ -362,16 +368,16 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { ~MergedDescriptorDatabase() override; // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, + bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const string& symbol_name, + bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) override; - bool FindFileContainingExtension(const string& containing_type, + bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) override; // Merges the results of calling all databases. Returns true iff any // of the databases returned true. - bool FindAllExtensionNumbers(const string& extendee_type, + bool FindAllExtensionNumbers(const std::string& extendee_type, std::vector<int>* output) override; @@ -383,4 +389,6 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ |