• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // An RAII type for printing a namespace.
9 //
10 // Example:
11 // {
12 //   Printer printer(output_stream.get(), '$');
13 //   const NamespacePrinter namespace_printer(&printer, {"a", "b", "c"});
14 //   // namespace opening will be opened here
15 //   ...
16 //   // namespace closing will be emitted here
17 // }
18 //
19 // By default, the filename will be converted to a macro by substituting '/' and
20 // '.' characters with '_'.  If a different transformation is required, an
21 // optional transformation function can be provided.
22 
23 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_NAMESPACE_PRINTER_H__
24 #define GOOGLE_PROTOBUF_COMPILER_CPP_NAMESPACE_PRINTER_H__
25 
26 #include <string>
27 #include <vector>
28 
29 #include "google/protobuf/io/printer.h"
30 
31 // Must be included last.
32 #include "google/protobuf/port_def.inc"
33 
34 namespace google {
35 namespace protobuf {
36 namespace compiler {
37 namespace cpp {
38 
39 // An RAII type for printing a namespace.
40 class PROTOC_EXPORT NamespacePrinter final {
41  public:
42   explicit NamespacePrinter(google::protobuf::io::Printer* p,
43                             std::vector<std::string> namespace_components);
44   ~NamespacePrinter();
45 
46  private:
47   google::protobuf::io::Printer* const p_;
48   const std::vector<std::string> namespace_components_;
49 };
50 
51 #include "google/protobuf/port_undef.inc"
52 
53 }  // namespace cpp
54 }  // namespace compiler
55 }  // namespace protobuf
56 }  // namespace google
57 
58 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_NAMESPACE_PRINTER_H__
59