printer.h

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

Utility class for writing text to a ZeroCopyOutputStream.

Classes in this file

Records annotations about a Printer's output.
Records annotations about a Printer's output to the given protocol buffer, assuming that the buffer has an ::Annotation message exposing path, source_file, begin and end fields.

class AnnotationCollector

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

Records annotations about a Printer's output.

Known subclasses:

Members

virtual void
AddAnnotation(size_t begin_offset, size_t end_offset, const string & file_path, const vector< int > & path) = 0
Records that the bytes in file_path beginning with begin_offset and ending before end_offset are associated with the SourceCodeInfo-style path.
virtual
~AnnotationCollector()

template class AnnotationProtoCollector: public AnnotationCollector

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

template <typename >

Records annotations about a Printer's output to the given protocol buffer, assuming that the buffer has an ::Annotation message exposing path, source_file, begin and end fields.

Members

explicit
AnnotationProtoCollector(AnnotationProto * annotation_proto)
annotation_proto is the protocol buffer to which new Annotations should be added. more...
virtual void
AddAnnotation(size_t begin_offset, size_t end_offset, const string & file_path, const vector< int > & path)

explicit AnnotationProtoCollector::AnnotationProtoCollector(
        AnnotationProto * annotation_proto)

annotation_proto is the protocol buffer to which new Annotations should be added.

It is not owned by the AnnotationProtoCollector.

class Printer

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

Members

Printer(ZeroCopyOutputStream * output, char variable_delimiter)
Create a printer that writes text to the given output stream. more...
Printer(ZeroCopyOutputStream * output, char variable_delimiter, AnnotationCollector * annotation_collector)
Create a printer that writes text to the given output stream. more...
~Printer()
template void
Annotate(const char * varname, const SomeDescriptor * descriptor)
Link a subsitution variable emitted by the last call to Print to the object described by descriptor.
template void
Annotate(const char * begin_varname, const char * end_varname, const SomeDescriptor * descriptor)
Link the output range defined by the substitution variables as emitted by the last call to Print to the object described by descriptor. more...
void
Annotate(const char * varname, const string & file_name)
Link a subsitution variable emitted by the last call to Print to the file with path file_name.
void
Annotate(const char * begin_varname, const char * end_varname, const string & file_name)
Link the output range defined by the substitution variables as emitted by the last call to Print to the file with path file_name. more...
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
Print(const char * text, const char * variable1, const string & value1, const char * variable2, const string & value2, const char * variable3, const string & value3, const char * variable4, const string & value4)
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, const char * variable4, const string & value4, const char * variable5, const string & value5)
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, const char * variable4, const string & value4, const char * variable5, const string & value5, const char * variable6, const string & value6)
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, const char * variable4, const string & value4, const char * variable5, const string & value5, const char * variable6, const string & value6, const char * variable7, const string & value7)
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, const char * variable4, const string & value4, const char * variable5, const string & value5, const char * variable6, const string & value6, const char * variable7, const string & value7, const char * variable8, const string & value8)
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.


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

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

Use the given character as the delimiter for variables. If annotation_collector is not null, Printer will provide it with annotations about code written to the stream. annotation_collector is not owned by Printer.


template void Printer::Annotate(
        const char * begin_varname,
        const char * end_varname,
        const SomeDescriptor * descriptor)

Link the output range defined by the substitution variables as emitted by the last call to Print to the object described by descriptor.

The range begins at begin_varname's value and ends after the last character of the value substituted for end_varname.


void Printer::Annotate(
        const char * begin_varname,
        const char * end_varname,
        const string & file_name)

Link the output range defined by the substitution variables as emitted by the last call to Print to the file with path file_name.

The range begins at begin_varname's value and ends after the last character of the value substituted for end_varname.


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