Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
update_instance_request_builder.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
17 
20 #include <google/protobuf/util/field_mask_util.h>
21 #include <google/spanner/admin/instance/v1/spanner_instance_admin.pb.h>
22 #include <map>
23 
24 namespace google {
25 namespace cloud {
26 namespace spanner {
27 inline namespace SPANNER_CLIENT_NS {
28 
40  public:
44  UpdateInstanceRequestBuilder() = default;
45 
46  // Copy and move.
50  default;
52  default;
53 
54  explicit UpdateInstanceRequestBuilder(std::string instance_name) {
55  request_.mutable_instance()->set_name(std::move(instance_name));
56  }
57  explicit UpdateInstanceRequestBuilder(Instance const& in) {
58  request_.mutable_instance()->set_name(in.FullName());
59  }
60 
67  google::spanner::admin::instance::v1::Instance in) {
68  *request_.mutable_instance() = std::move(in);
69  }
70 
71  UpdateInstanceRequestBuilder& SetName(std::string name) & {
72  request_.mutable_instance()->set_name(std::move(name));
73  return *this;
74  }
75  UpdateInstanceRequestBuilder&& SetName(std::string name) && {
76  request_.mutable_instance()->set_name(std::move(name));
77  return std::move(*this);
78  }
79  UpdateInstanceRequestBuilder& SetDisplayName(std::string display_name) & {
80  SetDisplayNameImpl(std::move(display_name));
81  return *this;
82  }
83  UpdateInstanceRequestBuilder&& SetDisplayName(std::string display_name) && {
84  SetDisplayNameImpl(std::move(display_name));
85  return std::move(*this);
86  }
88  SetNodeCountImpl(node_count);
89  return *this;
90  }
92  SetNodeCountImpl(node_count);
93  return std::move(*this);
94  }
96  std::map<std::string, std::string> const& labels) & {
97  AddLabelsImpl(labels);
98  return *this;
99  }
101  std::map<std::string, std::string> const& labels) && {
102  AddLabelsImpl(labels);
103  return std::move(*this);
104  }
106  std::map<std::string, std::string> const& labels) & {
107  request_.mutable_instance()->clear_labels();
108  AddLabelsImpl(labels);
109  return *this;
110  }
112  std::map<std::string, std::string> const& labels) && {
113  request_.mutable_instance()->clear_labels();
114  AddLabelsImpl(labels);
115  return std::move(*this);
116  }
117  google::spanner::admin::instance::v1::UpdateInstanceRequest& Build() & {
118  return request_;
119  }
120  google::spanner::admin::instance::v1::UpdateInstanceRequest&& Build() && {
121  return std::move(request_);
122  }
123 
124  private:
125  google::spanner::admin::instance::v1::UpdateInstanceRequest request_;
126  void SetDisplayNameImpl(std::string display_name) {
127  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
128  "display_name", request_.field_mask())) {
129  request_.mutable_field_mask()->add_paths("display_name");
130  }
131  request_.mutable_instance()->set_display_name(std::move(display_name));
132  }
133  void SetNodeCountImpl(int node_count) {
134  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
135  "node_count", request_.field_mask())) {
136  request_.mutable_field_mask()->add_paths("node_count");
137  }
138  request_.mutable_instance()->set_node_count(node_count);
139  }
140  void AddLabelsImpl(std::map<std::string, std::string> const& labels) {
141  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
142  "labels", request_.field_mask())) {
143  request_.mutable_field_mask()->add_paths("labels");
144  }
145  for (auto const& pair : labels) {
146  request_.mutable_instance()->mutable_labels()->insert(
147  {pair.first, pair.second});
148  }
149  }
150 };
151 
152 } // namespace SPANNER_CLIENT_NS
153 } // namespace spanner
154 } // namespace cloud
155 } // namespace google
156 
157 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
google::spanner::admin::instance::v1::UpdateInstanceRequest && Build() &&
UpdateInstanceRequestBuilder && SetNodeCount(int node_count) &&
UpdateInstanceRequestBuilder & SetLabels(std::map< std::string, std::string > const &labels) &
UpdateInstanceRequestBuilder is a builder class for google::spanner::admin::instance::v1::UpdateInsta...
This class identifies a Cloud Spanner Instance.
Definition: instance.h:41
UpdateInstanceRequestBuilder && SetLabels(std::map< std::string, std::string > const &labels) &&
UpdateInstanceRequestBuilder & SetName(std::string name) &
UpdateInstanceRequestBuilder & SetDisplayName(std::string display_name) &
Contains all the Cloud Spanner C++ client types and functions.
UpdateInstanceRequestBuilder && SetDisplayName(std::string display_name) &&
UpdateInstanceRequestBuilder && SetName(std::string name) &&
UpdateInstanceRequestBuilder && AddLabels(std::map< std::string, std::string > const &labels) &&
#define SPANNER_CLIENT_NS
Definition: version.h:22
UpdateInstanceRequestBuilder & SetNodeCount(int node_count) &
std::string FullName() const
Returns the fully qualified instance name as a string of the form: "projects/<project-id>/instances/<...
Definition: instance.cc:27
UpdateInstanceRequestBuilder(google::spanner::admin::instance::v1::Instance in)
Constructs UpdateInstanceRequestBuilder with google::spanner::admin::instance::v1::Instance.
google::spanner::admin::instance::v1::UpdateInstanceRequest & Build() &
UpdateInstanceRequestBuilder & AddLabels(std::map< std::string, std::string > const &labels) &