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 // 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_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 <chrono> 21 22 namespace google { 23 namespace cloud { 24 namespace bigtable { 25 inline namespace BIGTABLE_CLIENT_NS { 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 */ 35 class ReadModifyWriteRule { 36 public: 37 ReadModifyWriteRule(ReadModifyWriteRule&&) noexcept = default; 38 ReadModifyWriteRule& operator=(ReadModifyWriteRule&&) noexcept = default; 39 ReadModifyWriteRule(ReadModifyWriteRule const&) = default; 40 ReadModifyWriteRule& operator=(ReadModifyWriteRule const&) = default; 41 42 /// Create an operation that appends a string value. AppendValue(std::string family_name,std::string column_qualifier,std::string value)43 static ReadModifyWriteRule AppendValue(std::string family_name, 44 std::string column_qualifier, 45 std::string value) { 46 ReadModifyWriteRule tmp; 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. IncrementAmount(std::string family_name,std::string column_qualifier,std::int64_t amount)54 static ReadModifyWriteRule IncrementAmount(std::string family_name, 55 std::string column_qualifier, 56 std::int64_t amount) { 57 ReadModifyWriteRule tmp; 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. as_proto()65 google::bigtable::v2::ReadModifyWriteRule const& as_proto() const& { 66 return rule_; 67 } 68 69 /// Move out the underlying protobuf value. as_proto()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 private: 83 google::bigtable::v2::ReadModifyWriteRule rule_; 84 }; 85 86 } // namespace BIGTABLE_CLIENT_NS 87 } // namespace bigtable 88 } // namespace cloud 89 } // namespace google 90 91 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_READ_MODIFY_WRITE_RULE_H 92