Skip to content

Commit 40eb0ad

Browse files
var-consta-maurice
authored andcommitted
Small fixes to the public C++ API:
- make `CollectionReference::id` return by const reference instead of by value (made possible by the recent import of M68); - rename all `FieldValue::FromFoo` static functions to just `FieldValue::Foo` for brevity. PiperOrigin-RevId: 307506087
1 parent 6c4cb6f commit 40eb0ad

File tree

9 files changed

+51
-51
lines changed

9 files changed

+51
-51
lines changed

firestore/src/common/collection_reference.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "app/meta/move.h"
44
#include "app/src/include/firebase/future.h"
55
#include "firestore/src/common/futures.h"
6-
6+
#include "firestore/src/common/util.h"
77
#include "firestore/src/include/firebase/firestore/document_reference.h"
88
#if defined(__ANDROID__)
99
#include "firestore/src/android/collection_reference_android.h"
@@ -50,8 +50,8 @@ CollectionReference& CollectionReference::operator=(
5050
return *this;
5151
}
5252

53-
std::string CollectionReference::id() const {
54-
if (!internal()) return "";
53+
const std::string& CollectionReference::id() const {
54+
if (!internal()) return EmptyString();
5555
return internal()->id();
5656
}
5757

firestore/src/common/field_value.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,52 +122,52 @@ FieldValue& FieldValue::operator=(FieldValue&& value) noexcept {
122122
}
123123

124124
/* static */
125-
FieldValue FieldValue::FromBoolean(bool value) {
125+
FieldValue FieldValue::Boolean(bool value) {
126126
return FieldValue{new FieldValueInternal(value)};
127127
}
128128

129129
/* static */
130-
FieldValue FieldValue::FromInteger(int64_t value) {
130+
FieldValue FieldValue::Integer(int64_t value) {
131131
return FieldValue{new FieldValueInternal(value)};
132132
}
133133

134134
/* static */
135-
FieldValue FieldValue::FromDouble(double value) {
135+
FieldValue FieldValue::Double(double value) {
136136
return FieldValue{new FieldValueInternal(value)};
137137
}
138138

139139
/* static */
140-
FieldValue FieldValue::FromTimestamp(Timestamp value) {
140+
FieldValue FieldValue::Timestamp(class Timestamp value) {
141141
return FieldValue{new FieldValueInternal(value)};
142142
}
143143

144144
/* static */
145-
FieldValue FieldValue::FromString(std::string value) {
145+
FieldValue FieldValue::String(std::string value) {
146146
return FieldValue{new FieldValueInternal(firebase::Move(value))};
147147
}
148148

149149
/* static */
150-
FieldValue FieldValue::FromBlob(const uint8_t* value, size_t size) {
150+
FieldValue FieldValue::Blob(const uint8_t* value, size_t size) {
151151
return FieldValue{new FieldValueInternal(value, size)};
152152
}
153153

154154
/* static */
155-
FieldValue FieldValue::FromReference(DocumentReference value) {
155+
FieldValue FieldValue::Reference(DocumentReference value) {
156156
return FieldValue{new FieldValueInternal(firebase::Move(value))};
157157
}
158158

159159
/* static */
160-
FieldValue FieldValue::FromGeoPoint(GeoPoint value) {
160+
FieldValue FieldValue::GeoPoint(class GeoPoint value) {
161161
return FieldValue{new FieldValueInternal(value)};
162162
}
163163

164164
/* static */
165-
FieldValue FieldValue::FromArray(std::vector<FieldValue> value) {
165+
FieldValue FieldValue::Array(std::vector<FieldValue> value) {
166166
return FieldValue{new FieldValueInternal(firebase::Move(value))};
167167
}
168168

169169
/* static */
170-
FieldValue FieldValue::FromMap(MapFieldValue value) {
170+
FieldValue FieldValue::Map(MapFieldValue value) {
171171
return FieldValue{new FieldValueInternal(firebase::Move(value))};
172172
}
173173

firestore/src/include/firebase/firestore/collection_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CollectionReference : public Query {
104104
*
105105
* @return The ID as a std::string.
106106
*/
107-
virtual std::string id() const;
107+
virtual const std::string& id() const;
108108

109109
/**
110110
* @brief Returns the path of this collection (relative to the root of the

firestore/src/include/firebase/firestore/field_value.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,55 +135,55 @@ class FieldValue final {
135135
/**
136136
* @brief Constructs a FieldValue containing the given boolean value.
137137
*/
138-
static FieldValue FromBoolean(bool value);
138+
static FieldValue Boolean(bool value);
139139

140140
/**
141141
* @brief Constructs a FieldValue containing the given 64-bit integer value.
142142
*/
143-
static FieldValue FromInteger(int64_t value);
143+
static FieldValue Integer(int64_t value);
144144

145145
/**
146146
* @brief Constructs a FieldValue containing the given double-precision
147147
* floating point value.
148148
*/
149-
static FieldValue FromDouble(double value);
149+
static FieldValue Double(double value);
150150

151151
/**
152152
* @brief Constructs a FieldValue containing the given Timestamp value.
153153
*/
154-
static FieldValue FromTimestamp(Timestamp value);
154+
static FieldValue Timestamp(Timestamp value);
155155

156156
/**
157157
* @brief Constructs a FieldValue containing the given std::string value.
158158
*/
159-
static FieldValue FromString(std::string value);
159+
static FieldValue String(std::string value);
160160

161161
/**
162162
* @brief Constructs a FieldValue containing the given blob value of given
163163
* size. `value` is copied into the returned FieldValue.
164164
*/
165-
static FieldValue FromBlob(const uint8_t* value, size_t size);
165+
static FieldValue Blob(const uint8_t* value, size_t size);
166166

167167
/**
168168
* @brief Constructs a FieldValue containing the given reference value.
169169
*/
170-
static FieldValue FromReference(DocumentReference value);
170+
static FieldValue Reference(DocumentReference value);
171171

172172
/**
173173
* @brief Constructs a FieldValue containing the given GeoPoint value.
174174
*/
175-
static FieldValue FromGeoPoint(GeoPoint value);
175+
static FieldValue GeoPoint(GeoPoint value);
176176

177177
/**
178178
* @brief Constructs a FieldValue containing the given FieldValue vector
179179
* value.
180180
*/
181-
static FieldValue FromArray(std::vector<FieldValue> value);
181+
static FieldValue Array(std::vector<FieldValue> value);
182182

183183
/**
184184
* @brief Constructs a FieldValue containing the given FieldValue map value.
185185
*/
186-
static FieldValue FromMap(MapFieldValue value);
186+
static FieldValue Map(MapFieldValue value);
187187

188188
/** @brief Gets the current type contained in this FieldValue. */
189189
Type type() const;
@@ -235,7 +235,7 @@ class FieldValue final {
235235
double double_value() const;
236236

237237
/** @brief Gets the timestamp value contained in this FieldValue. */
238-
Timestamp timestamp_value() const;
238+
class Timestamp timestamp_value() const;
239239

240240
/** @brief Gets the string value contained in this FieldValue. */
241241
std::string string_value() const;
@@ -250,7 +250,7 @@ class FieldValue final {
250250
DocumentReference reference_value() const;
251251

252252
/** @brief Gets the GeoPoint value contained in this FieldValue. */
253-
GeoPoint geo_point_value() const;
253+
class GeoPoint geo_point_value() const;
254254

255255
/** @brief Gets the vector of FieldValues contained in this FieldValue. */
256256
std::vector<FieldValue> array_value() const;

firestore/src/ios/collection_reference_ios.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CollectionReferenceInternal::collection_core_api() const {
3232
return static_cast<const api::CollectionReference&>(query_core_api());
3333
}
3434

35-
std::string CollectionReferenceInternal::id() const {
35+
const std::string& CollectionReferenceInternal::id() const {
3636
return collection_core_api().collection_id();
3737
}
3838

firestore/src/ios/collection_reference_ios.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CollectionReferenceInternal : public QueryInternal {
1515
public:
1616
explicit CollectionReferenceInternal(api::CollectionReference&& collection);
1717

18-
std::string id() const;
18+
const std::string& id() const;
1919
std::string path() const;
2020

2121
DocumentReference Parent() const;

firestore/src/ios/document_snapshot_ios.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ FieldValue DocumentSnapshotInternal::ConvertObject(
100100
result[kv.first] = ConvertAnyValue(kv.second, stb);
101101
}
102102

103-
return FieldValue::FromMap(std::move(result));
103+
return FieldValue::Map(std::move(result));
104104
}
105105

106106
FieldValue DocumentSnapshotInternal::ConvertArray(
@@ -110,7 +110,7 @@ FieldValue DocumentSnapshotInternal::ConvertArray(
110110
result.push_back(ConvertAnyValue(value, stb));
111111
}
112112

113-
return FieldValue::FromArray(std::move(result));
113+
return FieldValue::Array(std::move(result));
114114
}
115115

116116
FieldValue DocumentSnapshotInternal::ConvertScalar(
@@ -119,20 +119,20 @@ FieldValue DocumentSnapshotInternal::ConvertScalar(
119119
case Type::Null:
120120
return FieldValue::Null();
121121
case Type::Boolean:
122-
return FieldValue::FromBoolean(scalar.boolean_value());
122+
return FieldValue::Boolean(scalar.boolean_value());
123123
case Type::Integer:
124-
return FieldValue::FromInteger(scalar.integer_value());
124+
return FieldValue::Integer(scalar.integer_value());
125125
case Type::Double:
126-
return FieldValue::FromDouble(scalar.double_value());
126+
return FieldValue::Double(scalar.double_value());
127127
case Type::String:
128-
return FieldValue::FromString(scalar.string_value());
128+
return FieldValue::String(scalar.string_value());
129129
case Type::Timestamp:
130-
return FieldValue::FromTimestamp(scalar.timestamp_value());
130+
return FieldValue::Timestamp(scalar.timestamp_value());
131131
case Type::GeoPoint:
132-
return FieldValue::FromGeoPoint(scalar.geo_point_value());
132+
return FieldValue::GeoPoint(scalar.geo_point_value());
133133
case Type::Blob:
134-
return FieldValue::FromBlob(scalar.blob_value().data(),
135-
scalar.blob_value().size());
134+
return FieldValue::Blob(scalar.blob_value().data(),
135+
scalar.blob_value().size());
136136
case Type::Reference:
137137
return ConvertReference(scalar.reference_value());
138138
case Type::ServerTimestamp:
@@ -154,7 +154,7 @@ FieldValue DocumentSnapshotInternal::ConvertReference(
154154
"Converted reference is from another database");
155155

156156
api::DocumentReference api_reference{reference.key(), snapshot_.firestore()};
157-
return FieldValue::FromReference(MakePublic(std::move(api_reference)));
157+
return FieldValue::Reference(MakePublic(std::move(api_reference)));
158158
}
159159

160160
FieldValue DocumentSnapshotInternal::ConvertServerTimestamp(
@@ -164,7 +164,7 @@ FieldValue DocumentSnapshotInternal::ConvertServerTimestamp(
164164
case ServerTimestampBehavior::kNone:
165165
return FieldValue::Null();
166166
case ServerTimestampBehavior::kEstimate: {
167-
return FieldValue::FromTimestamp(server_timestamp.local_write_time());
167+
return FieldValue::Timestamp(server_timestamp.local_write_time());
168168
}
169169
case ServerTimestampBehavior::kPrevious:
170170
if (server_timestamp.previous_value()) {

firestore/src/ios/field_value_ios.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,26 @@ std::string Describe(Type type) {
206206
case Type::kNull:
207207
return "FieldValue::Null()";
208208
case Type::kBoolean:
209-
return "FieldValue::FromBoolean()";
209+
return "FieldValue::Boolean()";
210210
case Type::kInteger:
211-
return "FieldValue::FromInteger()";
211+
return "FieldValue::Integer()";
212212
case Type::kDouble:
213-
return "FieldValue::FromDouble()";
213+
return "FieldValue::Double()";
214214
case Type::kTimestamp:
215-
return "FieldValue::FromTimestamp()";
215+
return "FieldValue::Timestamp()";
216216
case Type::kString:
217-
return "FieldValue::FromString()";
217+
return "FieldValue::String()";
218218
case Type::kBlob:
219-
return "FieldValue::FromBlob()";
219+
return "FieldValue::Blob()";
220220
case Type::kReference:
221-
return "FieldValue::FromReference()";
221+
return "FieldValue::Reference()";
222222
case Type::kGeoPoint:
223-
return "FieldValue::FromGeoPoint()";
223+
return "FieldValue::GeoPoint()";
224224
// Containers
225225
case Type::kArray:
226-
return "FieldValue::FromArray()";
226+
return "FieldValue::Array()";
227227
case Type::kMap:
228-
return "FieldValue::FromMap()";
228+
return "FieldValue::Map()";
229229
// Sentinels
230230
case Type::kDelete:
231231
return "FieldValue::Delete()";

firestore/src/ios/query_ios.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Query QueryInternal::Where(const FieldPath& field_path, Operator op,
8181
Query QueryInternal::Where(const FieldPath& field_path, Operator op,
8282
const std::vector<FieldValue>& values) const {
8383
const model::FieldPath& path = GetInternal(field_path);
84-
auto array_value = FieldValue::FromArray(values);
84+
auto array_value = FieldValue::Array(values);
8585
model::FieldValue parsed =
8686
user_data_converter_.ParseQueryValue(array_value, true);
8787
auto describer = [&array_value] { return Describe(array_value.type()); };

0 commit comments

Comments
 (0)