Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
notification_metadata.h
1// Copyright 2018 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// 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_STORAGE_NOTIFICATION_METADATA_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_NOTIFICATION_METADATA_H
17
18#include "google/cloud/storage/version.h"
19#include "google/cloud/status_or.h"
20#include <map>
21#include <string>
22#include <vector>
23
24namespace google {
25namespace cloud {
26namespace storage {
27GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
28namespace internal {
29struct NotificationMetadataParser;
30} // namespace internal
31
32/**
33 * Represents the metadata for a Google Cloud Storage Notification resource.
34 *
35 * Notifications send information about changes to objects in your buckets to
36 * Cloud Pub/Sub.
37 *
38 * @see https://cloud.google.com/storage/docs/pubsub-notifications for general
39 * information on Google Cloud Storage Notifications.
40 * @see https://cloud.google.com/pubsub/ for general information on Google
41 * Cloud Pub/Sub service.
42 */
44 public:
45 NotificationMetadata() = default;
46
47 explicit NotificationMetadata(std::string id, std::string etag)
48 : etag_(std::move(etag)), id_(std::move(id)) {}
49
50 /**
51 * Returns the payload for a call to `Notifications: insert`.
52 */
53 std::string JsonPayloadForInsert() const;
54
55 ///@{
56 /// @name Accessors and modifiers to the custom attributes.
57 bool has_custom_attribute(std::string const& key) const {
58 return custom_attributes_.end() != custom_attributes_.find(key);
59 }
60
61 std::string const& custom_attribute(std::string const& key) const {
62 return custom_attributes_.at(key);
63 }
64
65 /// Delete a custom attribute. This is a no-op if the key does not exist.
66 NotificationMetadata& delete_custom_attribute(std::string const& key) {
67 auto i = custom_attributes_.find(key);
68 if (i == custom_attributes_.end()) {
69 return *this;
70 }
71 custom_attributes_.erase(i);
72 return *this;
73 }
74
75 /// Insert or update the custom attribute.
77 std::string value) {
78 auto i = custom_attributes_.lower_bound(key);
79 if (i == custom_attributes_.end() || i->first != key) {
80 custom_attributes_.emplace_hint(i, std::move(key), std::move(value));
81 } else {
82 i->second = std::move(value);
83 }
84 return *this;
85 }
86
87 /// Full accessors for the custom attributes.
88 std::map<std::string, std::string> const& custom_attributes() const {
89 return custom_attributes_;
90 }
91 std::map<std::string, std::string>& mutable_custom_attributes() {
92 return custom_attributes_;
93 }
94 ///@}
95
96 std::string const& etag() const { return etag_; }
97
98 ///@{
99 /**
100 * @name Accessors and modifiers to the event types list.
101 *
102 * Define the list of event types that this notification will include.
103 *
104 * @see https://cloud.google.com/storage/docs/pubsub-notifications#events for
105 * a description of valid even types.
106 */
107 std::size_t event_type_size() const { return event_types_.size(); }
108 std::string const& event_type(std::size_t index) const {
109 return event_types_.at(index);
110 }
111
113 event_types_.emplace_back(std::move(e));
114 return *this;
115 }
116
117 std::vector<std::string> const& event_types() const { return event_types_; }
118 std::vector<std::string>& mutable_event_types() { return event_types_; }
119 ///@}
120
121 std::string const& id() const { return id_; }
122 std::string const& kind() const { return kind_; }
123
124 std::string const& object_name_prefix() const { return object_name_prefix_; }
126 object_name_prefix_ = std::move(v);
127 return *this;
128 }
129
130 std::string const& payload_format() const { return payload_format_; }
132 payload_format_ = std::move(v);
133 return *this;
134 }
135
136 std::string const& self_link() const { return self_link_; }
137
138 std::string const& topic() const { return topic_; }
139 NotificationMetadata& set_topic(std::string v) {
140 topic_ = std::move(v);
141 return *this;
142 }
143
144 private:
145 friend struct internal::NotificationMetadataParser;
146 friend std::ostream& operator<<(std::ostream& os,
147 NotificationMetadata const& rhs);
148
149 // Keep the fields in alphabetical order.
150 std::map<std::string, std::string> custom_attributes_;
151 std::string etag_;
152 std::vector<std::string> event_types_;
153 std::string id_;
154 std::string kind_;
155 std::string object_name_prefix_;
156 std::string payload_format_;
157 std::string self_link_;
158 std::string topic_;
159};
160
161inline bool operator==(NotificationMetadata const& lhs,
162 NotificationMetadata const& rhs) {
163 return std::tie(lhs.id(), lhs.custom_attributes(), lhs.etag(),
166 std::tie(rhs.id(), rhs.custom_attributes(), rhs.etag(),
169}
170
171inline bool operator<(NotificationMetadata const& lhs,
172 NotificationMetadata const& rhs) {
173 return std::tie(lhs.id(), lhs.custom_attributes(), lhs.etag(),
176 std::tie(rhs.id(), rhs.custom_attributes(), rhs.etag(),
179}
180
181inline bool operator!=(NotificationMetadata const& lhs,
182 NotificationMetadata const& rhs) {
183 return std::rel_ops::operator!=(lhs, rhs);
184}
185
186inline bool operator>(NotificationMetadata const& lhs,
187 NotificationMetadata const& rhs) {
188 return std::rel_ops::operator>(lhs, rhs);
189}
190
191inline bool operator<=(NotificationMetadata const& lhs,
192 NotificationMetadata const& rhs) {
193 return std::rel_ops::operator<=(lhs, rhs);
194}
195
196inline bool operator>=(NotificationMetadata const& lhs,
197 NotificationMetadata const& rhs) {
198 return std::rel_ops::operator>=(lhs, rhs);
199}
200
201std::ostream& operator<<(std::ostream& os, NotificationMetadata const& rhs);
202
203GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
204} // namespace storage
205} // namespace cloud
206} // namespace google
207
208#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_NOTIFICATION_METADATA_H
Represents the metadata for a Google Cloud Storage Notification resource.
Definition: notification_metadata.h:43
NotificationMetadata & delete_custom_attribute(std::string const &key)
Delete a custom attribute. This is a no-op if the key does not exist.
Definition: notification_metadata.h:66
NotificationMetadata(std::string id, std::string etag)
Definition: notification_metadata.h:47
std::string const & custom_attribute(std::string const &key) const
Delete a custom attribute. This is a no-op if the key does not exist.
Definition: notification_metadata.h:61
std::string const & kind() const
Definition: notification_metadata.h:122
std::size_t event_type_size() const
Definition: notification_metadata.h:107
NotificationMetadata & append_event_type(std::string e)
Definition: notification_metadata.h:112
std::string const & id() const
Definition: notification_metadata.h:121
NotificationMetadata & set_payload_format(std::string v)
Definition: notification_metadata.h:131
NotificationMetadata & set_object_name_prefix(std::string v)
Definition: notification_metadata.h:125
std::string const & topic() const
Definition: notification_metadata.h:138
std::string JsonPayloadForInsert() const
Returns the payload for a call to Notifications: insert.
std::string const & etag() const
Definition: notification_metadata.h:96
std::string const & event_type(std::size_t index) const
Definition: notification_metadata.h:108
std::vector< std::string > const & event_types() const
Definition: notification_metadata.h:117
std::map< std::string, std::string > const & custom_attributes() const
Full accessors for the custom attributes.
Definition: notification_metadata.h:88
std::string const & payload_format() const
Definition: notification_metadata.h:130
NotificationMetadata & set_topic(std::string v)
Definition: notification_metadata.h:139
std::map< std::string, std::string > & mutable_custom_attributes()
Delete a custom attribute. This is a no-op if the key does not exist.
Definition: notification_metadata.h:91
std::vector< std::string > & mutable_event_types()
Definition: notification_metadata.h:118
std::string const & self_link() const
Definition: notification_metadata.h:136
std::string const & object_name_prefix() const
Definition: notification_metadata.h:124
bool has_custom_attribute(std::string const &key) const
Delete a custom attribute. This is a no-op if the key does not exist.
Definition: notification_metadata.h:57
NotificationMetadata & upsert_custom_attributes(std::string key, std::string value)
Insert or update the custom attribute.
Definition: notification_metadata.h:76
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
bool operator>(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:186
bool operator!=(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:181
bool operator<(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:171
bool operator>=(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:196
bool operator<=(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:191
bool operator==(NotificationMetadata const &lhs, NotificationMetadata const &rhs)
Definition: notification_metadata.h:161