Google Cloud Spanner C++ Client  1.32.1
A C++ Client Library for Google Cloud Spanner
backup.cc
Go to the documentation of this file.
1 // Copyright 2020 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 #include "google/cloud/spanner/backup.h"
16 #include <ostream>
17 #include <regex>
18 
19 namespace google {
20 namespace cloud {
21 namespace spanner {
22 inline namespace SPANNER_CLIENT_NS {
23 
24 Backup::Backup(Instance instance, std::string backup_id)
25  : instance_(std::move(instance)), backup_id_(std::move(backup_id)) {}
26 
27 std::string Backup::FullName() const {
28  return instance().FullName() + "/backups/" + backup_id_;
29 }
30 
31 bool operator==(Backup const& a, Backup const& b) {
32  return a.instance_ == b.instance_ && a.backup_id_ == b.backup_id_;
33 }
34 
35 bool operator!=(Backup const& a, Backup const& b) { return !(a == b); }
36 
37 std::ostream& operator<<(std::ostream& os, Backup const& bu) {
38  return os << bu.FullName();
39 }
40 
41 StatusOr<Backup> MakeBackup(std::string const& full_name) {
42  std::regex re("projects/([^/]+)/instances/([^/]+)/backups/([^/]+)");
43  std::smatch matches;
44  if (!std::regex_match(full_name, matches, re)) {
46  "Improperly formatted Backup: " + full_name);
47  }
48  return Backup(Instance(std::move(matches[1]), std::move(matches[2])),
49  std::move(matches[3]));
50 }
51 
52 } // namespace SPANNER_CLIENT_NS
53 } // namespace spanner
54 } // namespace cloud
55 } // namespace google