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)
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)
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)
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)
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)
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.)