/Users/deen/code/yugabyte-db/src/yb/gen_yrpc/printer.cc
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 | | #include "yb/gen_yrpc/printer.h" |
15 | | |
16 | | #include <google/protobuf/io/printer.h> |
17 | | |
18 | | namespace yb { |
19 | | namespace gen_yrpc { |
20 | | |
21 | 0 | void SubstitutionContext::Push(const Substitutions& subs) { |
22 | 0 | for (const auto& p : subs) { |
23 | 0 | map_.emplace(p.first, p.second); |
24 | 0 | } |
25 | 0 | } |
26 | | |
27 | 0 | void SubstitutionContext::Pop(const Substitutions& subs) { |
28 | 0 | for (const auto& p : subs) { |
29 | 0 | map_.erase(p.first); |
30 | 0 | } |
31 | 0 | } |
32 | | |
33 | | YBPrinter::YBPrinter(google::protobuf::io::Printer* printer, SubstitutionContext* subs) |
34 | 0 | : printer_(printer), subs_(subs) { |
35 | 0 | } |
36 | | |
37 | 0 | void YBPrinter::operator()(const char* text) { |
38 | 0 | printer_->Print(subs_->map(), text); |
39 | 0 | } |
40 | | |
41 | 0 | void YBPrinter::Indent() { |
42 | 0 | printer_->Indent(); |
43 | 0 | } |
44 | | |
45 | 0 | void YBPrinter::Outdent() { |
46 | 0 | printer_->Outdent(); |
47 | 0 | } |
48 | | |
49 | | ScopedIndent::ScopedIndent(const YBPrinter& printer) |
50 | 0 | : printer_(&printer.printer()) { |
51 | 0 | printer_->Indent(); |
52 | 0 | } |
53 | | |
54 | 0 | ScopedIndent::~ScopedIndent() { |
55 | 0 | Reset(); |
56 | 0 | } |
57 | | |
58 | 0 | void ScopedIndent::Reset(const char* suffix) { |
59 | 0 | if (printer_) { |
60 | 0 | printer_->Outdent(); |
61 | 0 | if (suffix) { |
62 | 0 | printer_->Print(suffix); |
63 | 0 | } |
64 | 0 | printer_ = nullptr; |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | ScopedSubstituter::ScopedSubstituter(SubstitutionContext* context, Substitutions substitutions) |
69 | 0 | : context_(context), substitutions_(std::move(substitutions)) { |
70 | 0 | context_->Push(substitutions_); |
71 | 0 | } |
72 | | |
73 | | ScopedSubstituter::ScopedSubstituter(YBPrinter printer, Substitutions substitutions) |
74 | 0 | : ScopedSubstituter(printer.subs(), std::move(substitutions)) { |
75 | 0 | } Unexecuted instantiation: _ZN2yb8gen_yrpc17ScopedSubstituterC2ENS0_9YBPrinterENSt3__16vectorINS3_4pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_EENS9_ISC_EEEE Unexecuted instantiation: _ZN2yb8gen_yrpc17ScopedSubstituterC1ENS0_9YBPrinterENSt3__16vectorINS3_4pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_EENS9_ISC_EEEE |
76 | | |
77 | 0 | ScopedSubstituter::~ScopedSubstituter() { |
78 | 0 | context_->Pop(substitutions_); |
79 | 0 | } |
80 | | |
81 | | } // namespace gen_yrpc |
82 | | } // namespace yb |