@@ -42,6 +42,7 @@ namespace model {
42
42
namespace {
43
43
44
44
using BaseValue = FieldValue::BaseValue;
45
+ using Reference = FieldValue::Reference;
45
46
using ServerTimestamp = FieldValue::ServerTimestamp;
46
47
using Type = FieldValue::Type;
47
48
@@ -332,8 +333,8 @@ class BlobValue : public SimpleFieldValue<Type::Blob, ByteString> {
332
333
333
334
class ReferenceValue : public FieldValue ::BaseValue {
334
335
public:
335
- ReferenceValue (DatabaseId database_id, DocumentKey key )
336
- : database_id_ (std::move(database_id)), key_(std::move(key )) {
336
+ explicit ReferenceValue (Reference reference )
337
+ : reference_ (std::move(reference )) {
337
338
}
338
339
339
340
Type type () const override {
@@ -344,31 +345,43 @@ class ReferenceValue : public FieldValue::BaseValue {
344
345
if (type () != other.type ()) return false ;
345
346
346
347
auto & other_value = Cast<ReferenceValue>(other);
347
- return database_id_ == other_value.database_id_ && key_ == other_value.key_ ;
348
+ return database_id () == other_value.database_id () &&
349
+ key () == other_value.key ();
348
350
}
349
351
350
352
ComparisonResult CompareTo (const BaseValue& other) const override {
351
353
ComparisonResult cmp = CompareTypes (other);
352
354
if (!util::Same (cmp)) return cmp;
353
355
354
356
auto & other_value = Cast<ReferenceValue>(other);
355
- cmp = Compare (database_id_ , other_value.database_id_ );
357
+ cmp = Compare (database_id () , other_value.database_id () );
356
358
if (!util::Same (cmp)) return cmp;
357
359
358
- return Compare (key_ , other_value.key_ );
360
+ return Compare (key () , other_value.key () );
359
361
}
360
362
361
363
std::string ToString () const override {
362
- return absl::StrCat (" Reference(key=" , key_ .ToString (), " )" );
364
+ return absl::StrCat (" Reference(key=" , key () .ToString (), " )" );
363
365
}
364
366
365
367
size_t Hash () const override {
366
- return util::Hash (database_id_, key_);
368
+ return util::Hash (database_id (), key ());
369
+ }
370
+
371
+ const Reference& value () const {
372
+ return reference_;
373
+ }
374
+
375
+ const DatabaseId& database_id () const {
376
+ return reference_.database_id ();
377
+ }
378
+
379
+ const DocumentKey& key () const {
380
+ return reference_.key ();
367
381
}
368
382
369
383
private:
370
- DatabaseId database_id_;
371
- DocumentKey key_;
384
+ Reference reference_;
372
385
};
373
386
374
387
class GeoPointValue : public BaseValue {
@@ -548,6 +561,11 @@ const ByteString& FieldValue::blob_value() const {
548
561
return Cast<BlobValue>(*rep_).value ();
549
562
}
550
563
564
+ const Reference& FieldValue::reference_value () const {
565
+ HARD_ASSERT (type () == Type::Reference);
566
+ return Cast<ReferenceValue>(*rep_).value ();
567
+ }
568
+
551
569
const GeoPoint& FieldValue::geo_point_value () const {
552
570
HARD_ASSERT (type () == Type::GeoPoint);
553
571
return Cast<GeoPointValue>(*rep_).value ();
@@ -712,8 +730,8 @@ FieldValue FieldValue::FromBlob(ByteString blob) {
712
730
}
713
731
714
732
FieldValue FieldValue::FromReference (DatabaseId database_id, DocumentKey key) {
715
- return FieldValue (
716
- std::make_shared<ReferenceValue> (std::move (database_id), std::move (key)));
733
+ return FieldValue (std::make_shared<ReferenceValue>(
734
+ Reference (std::move (database_id), std::move (key) )));
717
735
}
718
736
719
737
FieldValue FieldValue::FromGeoPoint (const GeoPoint& value) {
0 commit comments