code_generator.h

code_generator.h

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

Defines the abstract interface implemented by each of the language-specific code generators.

Classes in this file

The abstract interface to a class which generates code implementing a particular proto file in a particular language.
CodeGenerators generate one or more files in a given directory.

File Members

These definitions are not part of any class.
typedef
GeneratorContext OutputDirectory
The type  GeneratorContext was once called OutputDirectory.  more...
void
ParseGeneratorParameter(const string & , vector< pair< string, string > > * )
Several code generators treat the parameter argument as holding a list of options separated by commas.  more...

typedef compiler::OutputDirectory

The type GeneratorContext was once called OutputDirectory.

This typedef provides backward compatibility.


void compiler::ParseGeneratorParameter(
        const string & ,
        vector< pair< string, string > > * )

Several code generators treat the parameter argument as holding a list of options separated by commas.

This helper function parses a set of comma-delimited name/value pairs: e.g., "foo=bar,baz,qux=corge" parses to the pairs:

("foo", "bar"), ("baz", ""), ("qux", "corge")

class CodeGenerator

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

The abstract interface to a class which generates code implementing a particular proto file in a particular language.

A number of these may be registered with CommandLineInterface to support various languages.

Known subclasses:

Members

CodeGenerator()
virtual
~CodeGenerator()
virtual bool
Generate(const FileDescriptor * file, const string & parameter, GeneratorContext * generator_context, string * error) const = 0
Generates code for the given proto file, generating one or more files in the given output directory.  more...

virtual bool CodeGenerator::Generate(
        const FileDescriptor * file,
        const string & parameter,
        GeneratorContext * generator_context,
        string * error) const = 0

Generates code for the given proto file, generating one or more files in the given output directory.

A parameter to be passed to the generator can be specified on the command line. This is intended to be used by Java and similar languages to specify which specific class from the proto file is to be generated, though it could have other uses as well. It is empty if no parameter was given.

Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.

class GeneratorContext

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

CodeGenerators generate one or more files in a given directory.

This abstract interface represents the directory to which the CodeGenerator is to write and other information about the context in which the Generator runs.

Members

GeneratorContext()
virtual
~GeneratorContext()
virtual io::ZeroCopyOutputStream*
Open(const string & filename) = 0
Opens the given file, truncating it if it exists, and returns a ZeroCopyOutputStream that writes to the file. more...
virtual io::ZeroCopyOutputStream*
OpenForInsert(const string & filename, const string & insertion_point)
Creates a ZeroCopyOutputStream which will insert code into the given file at the given insertion point. more...
virtual void
ListParsedFiles(vector< const FileDescriptor * > * output)
Returns a vector of FileDescriptors for all the files being compiled in this run.  more...

virtual io::ZeroCopyOutputStream * 
    GeneratorContext::Open(
        const string & filename) = 0

Opens the given file, truncating it if it exists, and returns a ZeroCopyOutputStream that writes to the file.

The caller takes ownership of the returned object. This method never fails (a dummy stream will be returned instead).

The filename given should be relative to the root of the source tree. E.g. the C++ generator, when generating code for "foo/bar.proto", will generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that "foo/" is included in these filenames. The filename is not allowed to contain "." or ".." components.


virtual io::ZeroCopyOutputStream * 
    GeneratorContext::OpenForInsert(
        const string & filename,
        const string & insertion_point)

Creates a ZeroCopyOutputStream which will insert code into the given file at the given insertion point.

See plugin.proto (plugin.pb.h) for more information on insertion points. The default implementation assert-fails -- it exists only for backwards-compatibility.

WARNING: This feature is currently EXPERIMENTAL and is subject to change.


virtual void GeneratorContext::ListParsedFiles(
        vector< const FileDescriptor * > * output)

Returns a vector of FileDescriptors for all the files being compiled in this run.

Useful for languages, such as Go, that treat files differently when compiled as a set rather than individually.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值