/Users/deen/code/yugabyte-db/src/yb/gen_yrpc/printer.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_GEN_YRPC_PRINTER_H |
15 | | #define YB_GEN_YRPC_PRINTER_H |
16 | | |
17 | | #include <map> |
18 | | #include <memory> |
19 | | #include <string> |
20 | | #include <vector> |
21 | | |
22 | | #include "yb/gen_yrpc/gen_yrpc_fwd.h" |
23 | | #include "yb/gen_yrpc/substitutions.h" |
24 | | |
25 | | namespace yb { |
26 | | namespace gen_yrpc { |
27 | | |
28 | | class SubstitutionContext { |
29 | | public: |
30 | | void Push(const Substitutions& subs); |
31 | | void Pop(const Substitutions& subs); |
32 | | |
33 | 0 | const std::map<std::string, std::string>& map() const { |
34 | 0 | return map_; |
35 | 0 | } |
36 | | |
37 | | private: |
38 | | std::map<std::string, std::string> map_; |
39 | | }; |
40 | | |
41 | | class YBPrinter { |
42 | | public: |
43 | | YBPrinter(google::protobuf::io::Printer* printer, SubstitutionContext* subs); |
44 | | |
45 | | void operator()(const char* text); |
46 | | |
47 | 0 | void operator()(const std::string& text) { |
48 | 0 | (*this)(text.c_str()); |
49 | 0 | } |
50 | | |
51 | | void Indent(); |
52 | | void Outdent(); |
53 | | |
54 | 0 | SubstitutionContext* subs() { |
55 | 0 | return subs_; |
56 | 0 | } |
57 | | |
58 | 0 | google::protobuf::io::Printer& printer() const { |
59 | 0 | return *printer_; |
60 | 0 | } |
61 | | |
62 | | private: |
63 | | google::protobuf::io::Printer* printer_; |
64 | | SubstitutionContext* subs_; |
65 | | }; |
66 | | |
67 | | class ScopedIndent { |
68 | | public: |
69 | | explicit ScopedIndent(const YBPrinter& printer); |
70 | | |
71 | | ScopedIndent(const ScopedIndent&) = delete; |
72 | | void operator=(const ScopedIndent&) = delete; |
73 | | |
74 | | ~ScopedIndent(); |
75 | | |
76 | | void Reset(const char* suffix = nullptr); |
77 | | |
78 | | private: |
79 | | google::protobuf::io::Printer* printer_; |
80 | | }; |
81 | | |
82 | | class ScopedSubstituter { |
83 | | public: |
84 | | template <class... Args> |
85 | | ScopedSubstituter(SubstitutionContext* context, Args&&... args) |
86 | 0 | : ScopedSubstituter(context, CreateSubstitutions(std::forward<Args>(args)...)) { |
87 | 0 | } Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::Descriptor const*&>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::Descriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::FieldDescriptor const*&>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::FieldDescriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::Descriptor const* const&>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::Descriptor const* const&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::MethodDescriptor const*, yb::rpc::RpcSides>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::MethodDescriptor const*&&, yb::rpc::RpcSides&&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::ServiceDescriptor const*&>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::ServiceDescriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::MethodDescriptor const*&, yb::rpc::RpcSides>(yb::gen_yrpc::SubstitutionContext*, google::protobuf::MethodDescriptor const*&, yb::rpc::RpcSides&&) |
88 | | |
89 | | template <class... Args> |
90 | | ScopedSubstituter(YBPrinter printer, Args&&... args) |
91 | 0 | : ScopedSubstituter(printer.subs(), std::forward<Args>(args)...) { |
92 | 0 | } Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::Descriptor const*&>(yb::gen_yrpc::YBPrinter, google::protobuf::Descriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::FieldDescriptor const*&>(yb::gen_yrpc::YBPrinter, google::protobuf::FieldDescriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::Descriptor const* const&>(yb::gen_yrpc::YBPrinter, google::protobuf::Descriptor const* const&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::MethodDescriptor const*, yb::rpc::RpcSides>(yb::gen_yrpc::YBPrinter, google::protobuf::MethodDescriptor const*&&, yb::rpc::RpcSides&&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::ServiceDescriptor const*&>(yb::gen_yrpc::YBPrinter, google::protobuf::ServiceDescriptor const*&) Unexecuted instantiation: yb::gen_yrpc::ScopedSubstituter::ScopedSubstituter<google::protobuf::MethodDescriptor const*&, yb::rpc::RpcSides>(yb::gen_yrpc::YBPrinter, google::protobuf::MethodDescriptor const*&, yb::rpc::RpcSides&&) |
93 | | |
94 | | ScopedSubstituter(SubstitutionContext* context, Substitutions substitutions); |
95 | | ScopedSubstituter(YBPrinter printer, Substitutions substitutions); |
96 | | |
97 | | ScopedSubstituter(const ScopedSubstituter&) = delete; |
98 | | void operator=(const ScopedSubstituter&) = delete; |
99 | | |
100 | | ~ScopedSubstituter(); |
101 | | |
102 | | private: |
103 | | SubstitutionContext* context_; |
104 | | Substitutions substitutions_; |
105 | | }; |
106 | | |
107 | | } // namespace gen_yrpc |
108 | | } // namespace yb |
109 | | |
110 | | #endif // YB_GEN_YRPC_PRINTER_H |