Google Cloud Pub/Sub C++ Client  1.32.1
A C++ Client Library for Google Cloud Pub/Sub
subscription.h
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 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_H
17 
18 #include "google/cloud/pubsub/version.h"
19 #include <grpcpp/grpcpp.h>
20 #include <string>
21 
22 namespace google {
23 namespace cloud {
24 namespace pubsub {
25 inline namespace GOOGLE_CLOUD_CPP_PUBSUB_NS {
26 
27 /**
28  * Objects of this class identify a Cloud Pub/Sub subscription.
29  *
30  * @note
31  * This class makes no effort to validate the ids provided. The application
32  * should verify that any ids passed to this application conform to the
33  * Cloud Pub/Sub [resource name][name-link] restrictions.
34  *
35  * [name-link]: https://cloud.google.com/pubsub/docs/admin#resource_names
36  */
37 class Subscription {
38  public:
39  Subscription(std::string project_id, std::string subscription_id)
40  : project_id_(std::move(project_id)),
41  subscription_id_(std::move(subscription_id)) {}
42 
43  /// @name Copy and move
44  //@{
45  Subscription(Subscription const&) = default;
46  Subscription& operator=(Subscription const&) = default;
47  Subscription(Subscription&&) = default;
49  //@}
50 
51  /// Returns the Project ID
52  std::string const& project_id() const { return project_id_; }
53 
54  /// Returns the Subscription ID
55  std::string const& subscription_id() const { return subscription_id_; }
56 
57  /**
58  * Returns the fully qualified subscription name as a string of the form:
59  * "projects/<project-id>/subscriptions/<subscription-id>"
60  */
61  std::string FullName() const;
62 
63  /// @name Equality operators
64  //@{
65  friend bool operator==(Subscription const& a, Subscription const& b);
66  friend bool operator!=(Subscription const& a, Subscription const& b) {
67  return !(a == b);
68  }
69  //@}
70 
71  /// Output the `FullName()` format.
72  friend std::ostream& operator<<(std::ostream& os, Subscription const& rhs);
73 
74  private:
75  std::string project_id_;
76  std::string subscription_id_;
77 };
78 
79 } // namespace GOOGLE_CLOUD_CPP_PUBSUB_NS
80 } // namespace pubsub
81 } // namespace cloud
82 } // namespace google
83 
84 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_H