Skip to content

Commit 2998549

Browse files
committed
Initial commit
1 parent edad366 commit 2998549

File tree

10 files changed

+105
-11
lines changed

10 files changed

+105
-11
lines changed

firestore/src/common/futures.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ template <typename T>
5555
Future<T> FailedFuture() {
5656
static auto* future = new Future<T>(FailedFuture<T>(
5757
Error::kErrorFailedPrecondition,
58-
"This instance is in an invalid state. This is because the underlying "
59-
"Firestore instance has been destructed."));
58+
"The object that issued this future is in an invalid state. This can be "
59+
"because:\n- the object was default-constructed and never reassigned;\n"
60+
"- the object was moved from;\n- the Firestore instance with which the "
61+
"object was associated has been destroyed."));
6062
return *future;
6163
}
6264

firestore/src/include/firebase/firestore/document_change.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ class DocumentChange {
159159
*/
160160
virtual std::size_t new_index() const;
161161

162+
/**
163+
* @brief Returns true if this `DocumentChange` is valid, false if it is
164+
* not valid. An invalid `DocumentChange` could be the result of:
165+
* - Creating a `DocumentChange` using the default constructor.
166+
* - Moving from the `DocumentChange`.
167+
* - Deleting your Firestore instance, which will invalidate all
168+
* `DocumentChange` instances associated with it.
169+
*
170+
* @return true if this `DocumentChange` is valid, false if this
171+
* `DocumentChange` is invalid.
172+
*/
173+
bool is_valid() const { return internal_ != nullptr; }
174+
162175
private:
163176
friend class FirestoreInternal;
164177
friend class Wrapper;

firestore/src/include/firebase/firestore/document_reference.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,17 @@ class DocumentReference {
285285
callback);
286286

287287
/**
288-
* @brief Returns true if this DocumentReference is valid, false if it is not
289-
* valid. An invalid DocumentReference could be the result of:
290-
* - Creating a DocumentReference with the default constructor.
291-
* - Calling CollectionReference::Parent() on a CollectionReference that is
292-
* not a subcollection.
288+
* @brief Returns true if this `DocumentReference` is valid, false if it is
289+
* not valid. An invalid `DocumentReference` could be the result of:
290+
* - Creating a `DocumentReference` using the default constructor.
291+
* - Moving from the `DocumentReference`.
292+
* - Calling `CollectionReference::Parent()` on a `CollectionReference` that
293+
* is not a subcollection.
293294
* - Deleting your Firestore instance, which will invalidate all
294-
* DocumentReference instances associated with it.
295+
* `DocumentReference` instances associated with it.
295296
*
296-
* @return true if this DocumentReference is valid, false if this
297-
* DocumentReference is invalid.
297+
* @return true if this `DocumentReference` is valid, false if this
298+
* `DocumentReference` is invalid.
298299
*/
299300
bool is_valid() const { return internal_ != nullptr; }
300301

firestore/src/include/firebase/firestore/document_snapshot.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ class DocumentSnapshot {
229229
const FieldPath& field,
230230
ServerTimestampBehavior stb = ServerTimestampBehavior::kDefault) const;
231231

232+
/**
233+
* @brief Returns true if this `DocumentSnapshot` is valid, false if it is
234+
* not valid. An invalid `DocumentSnapshot` could be the result of:
235+
* - Creating a `DocumentSnapshot` with the default constructor.
236+
* - Moving from the `DocumentSnapshot`.
237+
* - Deleting your Firestore instance, which will invalidate all
238+
* `DocumentSnapshot` instances associated with it.
239+
*
240+
* @return true if this `DocumentSnapshot` is valid, false if this
241+
* `DocumentSnapshot` is invalid.
242+
*/
243+
bool is_valid() const { return internal_ != nullptr; }
244+
232245
/**
233246
* Returns a string representation of this `DocumentSnapshot` for
234247
* logging/debugging purposes.

firestore/src/include/firebase/firestore/field_path.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ class FieldPath final {
122122
*/
123123
static FieldPath DocumentId();
124124

125+
/**
126+
* @brief Returns true if this `FieldPath` is valid, false if it is not valid.
127+
* An invalid `FieldPath` could be the result of:
128+
* - Creating a `FieldPath` using the default constructor.
129+
* - Moving from the `FieldPath`.
130+
* - Deleting your Firestore instance, which will invalidate all
131+
* `FieldPath` instances associated with it.
132+
*
133+
* @return true if this `FieldPath` is valid, false if this `FieldPath` is
134+
* invalid.
135+
*/
136+
bool is_valid() const { return internal_ != nullptr; }
137+
125138
/**
126139
* Returns a string representation of this `FieldPath` for
127140
* logging/debugging purposes.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ class FieldValue final {
277277
* @brief Returns `true` if this `FieldValue` is valid, `false` if it is not
278278
* valid. An invalid `FieldValue` could be the result of:
279279
* - Creating a `FieldValue` using the default constructor.
280+
* - Moving from the `FieldValue`.
280281
* - Calling `DocumentSnapshot::Get(field)` for a field that does not exist
281-
* in the document.
282+
* in the document.
282283
*
283284
* @return `true` if this `FieldValue` is valid, `false` if this `FieldValue`
284285
* is invalid.

firestore/src/include/firebase/firestore/listener_registration.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class ListenerRegistration {
9494
*/
9595
virtual void Remove();
9696

97+
/**
98+
* @brief Returns true if this `ListenerRegistration` is valid, false if it is
99+
* not valid. An invalid `ListenerRegistration` could be the result of:
100+
* - Creating a `ListenerRegistration` using the default constructor.
101+
* - Moving from the `ListenerRegistration`.
102+
* - Deleting your Firestore instance, which will invalidate all
103+
* `ListenerRegistration` instances associated with it.
104+
*
105+
* @return true if this `ListenerRegistration` is valid, false if this
106+
* `ListenerRegistration` is invalid.
107+
*/
108+
bool is_valid() const { return internal_ != nullptr; }
109+
97110
private:
98111
friend class DocumentReferenceInternal;
99112
friend class FirestoreInternal;

firestore/src/include/firebase/firestore/query.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,18 @@ class Query {
637637
std::function<void(const QuerySnapshot&, Error, const std::string&)>
638638
callback);
639639

640+
/**
641+
* @brief Returns true if this `Query` is valid, false if it is not valid. An
642+
* invalid `Query` could be the result of:
643+
* - Creating a `Query` using the default constructor.
644+
* - Moving from the `Query`.
645+
* - Deleting your Firestore instance, which will invalidate all `Query`
646+
* instances associated with it.
647+
*
648+
* @return true if this `Query` is valid, false if this `Query` is invalid.
649+
*/
650+
bool is_valid() const { return internal_ != nullptr; }
651+
640652
private:
641653
friend bool operator==(const Query& lhs, const Query& rhs);
642654

firestore/src/include/firebase/firestore/query_snapshot.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ class QuerySnapshot {
150150
*/
151151
virtual std::size_t size() const;
152152

153+
/**
154+
* @brief Returns true if this `QuerySnapshot` is valid, false if it is not
155+
* valid. An invalid `QuerySnapshot` could be the result of:
156+
* - Creating a `QuerySnapshot` using the default constructor.
157+
* - Moving from the `QuerySnapshot`.
158+
* - Deleting your Firestore instance, which will invalidate all
159+
* `QuerySnapshot` instances associated with it.
160+
*
161+
* @return true if this `QuerySnapshot` is valid, false if this
162+
* `QuerySnapshot` is invalid.
163+
*/
164+
bool is_valid() const { return internal_ != nullptr; }
165+
153166
private:
154167
friend class EventListenerInternal;
155168
friend class FirestoreInternal;

firestore/src/include/firebase/firestore/write_batch.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ class WriteBatch {
157157
*/
158158
virtual Future<void> Commit();
159159

160+
/**
161+
* @brief Returns true if this `WriteBatch` is valid, false if it is not
162+
* valid. An invalid `WriteBatch` could be the result of:
163+
* - Creating a `WriteBatch` using the default constructor.
164+
* - Moving from the `WriteBatch`.
165+
* - Deleting your Firestore instance, which will invalidate all
166+
* `WriteBatch` instances associated with it.
167+
*
168+
* @return true if this `WriteBatch` is valid, false if this `WriteBatch` is
169+
* invalid.
170+
*/
171+
bool is_valid() const { return internal_ != nullptr; }
172+
160173
private:
161174
friend class FirestoreInternal;
162175
friend class WriteBatchInternal;

0 commit comments

Comments
 (0)