Google Cloud Bigtable C++ Client  2.0.0
A C++ Client Library for Google Cloud Bigtable
read_modify_write_rule.h
Go to the documentation of this file.
1 // Copyright 2018 Google Inc.
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 // https://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_BIGTABLE_READ_MODIFY_WRITE_RULE_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_READ_MODIFY_WRITE_RULE_H
17 
18 #include "google/cloud/bigtable/version.h"
19 #include <google/bigtable/v2/data.pb.h>
20 #include <string>
21 
22 namespace google {
23 namespace cloud {
24 namespace bigtable {
26 /**
27  * Define the interfaces to create ReadWriteModifyRule operations.
28  *
29  * Cloud Bigtable has operations to perform atomic updates to a row, such as
30  * incrementing an integer value or appending to a string value. The changes are
31  * represented by a ReadModifyWriteRule operations. One or much such operations
32  * can be sent in a single request. This class helps users create the operations
33  * through a more idiomatic C++ interface.
34  */
36  public:
41 
42  /// Create an operation that appends a string value.
43  static ReadModifyWriteRule AppendValue(std::string family_name,
44  std::string column_qualifier,
45  std::string value) {
47  tmp.rule_.set_family_name(std::move(family_name));
48  tmp.rule_.set_column_qualifier(std::move(column_qualifier));
49  tmp.rule_.set_append_value(std::move(value));
50  return tmp;
51  }
52 
53  /// Create an operation that increments an integer value.
54  static ReadModifyWriteRule IncrementAmount(std::string family_name,
55  std::string column_qualifier,
56  std::int64_t amount) {
58  tmp.rule_.set_family_name(std::move(family_name));
59  tmp.rule_.set_column_qualifier(std::move(column_qualifier));
60  tmp.rule_.set_increment_amount(amount);
61  return tmp;
62  }
63 
64  /// Return the filter expression as a protobuf.
65  google::bigtable::v2::ReadModifyWriteRule const& as_proto() const& {
66  return rule_;
67  }
68 
69  /// Move out the underlying protobuf value.
70  google::bigtable::v2::ReadModifyWriteRule&& as_proto() && {
71  return std::move(rule_);
72  }
73 
74  private:
75  /**
76  * Create an empty operation.
77  *
78  * Empty operations are not usable, so this constructor is private.
79  */
80  ReadModifyWriteRule() = default;
81 
82  google::bigtable::v2::ReadModifyWriteRule rule_;
83 };
84 
86 } // namespace bigtable
87 } // namespace cloud
88 } // namespace google
89 
90 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_READ_MODIFY_WRITE_RULE_H