printer.h

printer.h

#include <google/protobuf/io/printer.h>
namespace google::protobuf::io

Utility class for writing text to a ZeroCopyOutputStream.

Classes in this file

This simple utility class assists in code generation.

class Printer

#include <google/protobuf/io/printer.h>
namespace google::protobuf::io

This simple utility class assists in code generation.

It basically allows the caller to define a set of variables and then output some text with variable substitutions. Example usage:

Printer printer(output, '$');
map<string, string> vars;
vars[[]"name"] = "Bob";
printer.Print(vars, "My name is $name$.");

The above writes "My name is Bob." to the output stream.

Printer aggressively enforces correct usage, crashing (with assert failures) in the case of undefined variables in debug builds. This helps greatly in debugging code which uses it.

Members

Printer(ZeroCopyOutputStream * output, char variable_delimiter)
Create a printer that writes text to the given output stream.  more...
~Printer()
void
Print(const map< string, string > & variables, const char * text)
Print some text after applying variable substitutions.  more...
void
Print(const char * text)
Like the first  Print(), except the substitutions are given as parameters.
void
Print(const char * text, const char * variable, const string & value)
Like the first  Print(), except the substitutions are given as parameters.
void
Print(const char * text, const char * variable1, const string & value1, const char * variable2, const string & value2)
Like the first  Print(), except the substitutions are given as parameters.
void
Print(const char * text, const char * variable1, const string & value1, const char * variable2, const string & value2, const char * variable3, const string & value3)
Like the first  Print(), except the substitutions are given as parameters.
void
Indent()
Indent text by two spaces.  more...
void
Outdent()
Reduces the current indent level by two spaces, or crashes if the indent level is zero.
void
PrintRaw(const string & data)
Write a string to the output buffer.  more...
void
PrintRaw(const char * data)
Write a zero-delimited string to output buffer.  more...
void
WriteRaw(const char * data, int size)
Write some bytes to the output buffer.  more...
bool
failed() const
True if any write to the underlying stream failed.  more...

Printer::Printer(
        ZeroCopyOutputStream * output,
        char variable_delimiter)

Create a printer that writes text to the given output stream.

Use the given character as the delimiter for variables.


void Printer::Print(
        const map< string, string > & variables,
        const char * text)

Print some text after applying variable substitutions.

If a particular variable in the text is not defined, this will crash. Variables to be substituted are identified by their names surrounded by delimiter characters (as given to the constructor). The variable bindings are defined by the given map.


void Printer::Indent()

Indent text by two spaces.

After calling Indent(), two spaces will be inserted at the beginning of each line of text. Indent() may be called multiple times to produce deeper indents.


void Printer::PrintRaw(
        const string & data)

Write a string to the output buffer.

This method does not look for newlines to add indentation.


void Printer::PrintRaw(
        const char * data)

Write a zero-delimited string to output buffer.

This method does not look for newlines to add indentation.


void Printer::WriteRaw(
        const char * data,
        int size)

Write some bytes to the output buffer.

This method does not look for newlines to add indentation.


bool Printer::failed() const

True if any write to the underlying stream failed.

(We don't just crash in this case because this is an I/O failure, not a programming error.)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值