37 #ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__
38 #define GOOGLE_PROTOBUF_IO_PRINTER_H__
45 #include <google/protobuf/port_def.inc>
51 class ZeroCopyOutputStream;
61 virtual void AddAnnotation(
size_t begin_offset,
size_t end_offset,
63 const std::vector<int>&
path) = 0;
75 template <
typename AnnotationProto>
86 const std::vector<int>&
path) {
87 typename AnnotationProto::Annotation* annotation =
89 for (
int i = 0;
i <
path.size(); ++
i) {
90 annotation->add_path(
path[
i]);
92 annotation->set_source_file(file_path);
93 annotation->set_begin(begin_offset);
94 annotation->set_end(end_offset);
99 annotation->ParseFromString(
a.second);
100 annotation->set_begin(
a.first.first);
101 annotation->set_end(
a.first.second);
198 template <
typename SomeDescriptor>
207 template <
typename SomeDescriptor>
208 void Annotate(
const char* begin_varname,
const char* end_varname,
210 if (annotation_collector_ ==
NULL) {
215 std::vector<int>
path;
217 Annotate(begin_varname, end_varname,
descriptor->file()->name(),
path);
223 Annotate(varname, varname, file_name);
230 void Annotate(
const char* begin_varname,
const char* end_varname,
232 if (annotation_collector_ ==
NULL) {
236 std::vector<int> empty_path;
237 Annotate(begin_varname, end_varname, file_name, empty_path);
245 void Print(
const std::map<std::string, std::string>& variables,
249 template <
typename...
Args>
251 std::map<std::string, std::string> vars;
252 PrintInternal(&vars, text,
args...);
270 void PrintRaw(
const char*
data);
274 void WriteRaw(
const char*
data,
int size);
281 void FormatInternal(
const std::vector<std::string>&
args,
282 const std::map<std::string, std::string>& vars,
297 void Annotate(
const char* begin_varname,
const char* end_varname,
306 template <
typename...
Args>
307 void PrintInternal(std::map<std::string, std::string>* vars,
const char* text,
311 PrintInternal(vars, text,
args...);
315 void CopyToBuffer(
const char*
data,
int size);
319 if (buffer_size_ == 0) {
329 inline void IndentIfAtStart();
330 const char* WriteVariable(
331 const std::vector<std::string>&
args,
332 const std::map<std::string, std::string>& vars,
const char*
format,
334 std::vector<AnnotationCollector::Annotation>* annotations);
368 bool GetSubstitutionRange(
const char* varname,
369 std::pair<size_t, size_t>*
range);
382 #include <google/protobuf/port_undef.inc>
384 #endif // GOOGLE_PROTOBUF_IO_PRINTER_H__