From d439bbccd4b90583a89d209d2cc81308aabca8ac Mon Sep 17 00:00:00 2001 From: Gil Date: Tue, 22 May 2018 13:21:08 -0700 Subject: Add a HARD_ASSERT C++ assertion macro (#1304) * Add HARD_ASSERT * Use HARD_ASSERT * Remove FIREBASE_ASSERT * Remove StringPrintf --- .../src/firebase/firestore/model/field_value.cc | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/model/field_value.cc') diff --git a/Firestore/core/src/firebase/firestore/model/field_value.cc b/Firestore/core/src/firebase/firestore/model/field_value.cc index 35253c8..4f92c8b 100644 --- a/Firestore/core/src/firebase/firestore/model/field_value.cc +++ b/Firestore/core/src/firebase/firestore/model/field_value.cc @@ -23,7 +23,7 @@ #include #include "Firestore/core/src/firebase/firestore/util/comparison.h" -#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" using firebase::firestore::util::Comparator; @@ -130,8 +130,7 @@ FieldValue& FieldValue::operator=(const FieldValue& value) { break; } default: - FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION( - false, lhs.type(), "Unsupported type %d", value.type()); + HARD_FAIL("Unsupported type %s", value.type()); } return *this; } @@ -168,10 +167,10 @@ FieldValue& FieldValue::operator=(FieldValue&& value) { FieldValue FieldValue::Set(const FieldPath& field_path, FieldValue value) const { - FIREBASE_ASSERT_MESSAGE(type() == Type::Object, - "Cannot set field for non-object FieldValue"); - FIREBASE_ASSERT_MESSAGE(!field_path.empty(), - "Cannot set field for empty path on FieldValue"); + HARD_ASSERT(type() == Type::Object, + "Cannot set field for non-object FieldValue"); + HARD_ASSERT(!field_path.empty(), + "Cannot set field for empty path on FieldValue"); // Set the value by recursively calling on child object. const std::string& child_name = field_path.first_segment(); const ObjectValue::Map& object_map = object_value_.internal_value; @@ -195,10 +194,10 @@ FieldValue FieldValue::Set(const FieldPath& field_path, } FieldValue FieldValue::Delete(const FieldPath& field_path) const { - FIREBASE_ASSERT_MESSAGE(type() == Type::Object, - "Cannot delete field for non-object FieldValue"); - FIREBASE_ASSERT_MESSAGE(!field_path.empty(), - "Cannot delete field for empty path on FieldValue"); + HARD_ASSERT(type() == Type::Object, + "Cannot delete field for non-object FieldValue"); + HARD_ASSERT(!field_path.empty(), + "Cannot delete field for empty path on FieldValue"); // Delete the value by recursively calling on child object. const std::string& child_name = field_path.first_segment(); const ObjectValue::Map& object_map = object_value_.internal_value; @@ -223,8 +222,8 @@ FieldValue FieldValue::Delete(const FieldPath& field_path) const { } absl::optional FieldValue::Get(const FieldPath& field_path) const { - FIREBASE_ASSERT_MESSAGE(type() == Type::Object, - "Cannot get field for non-object FieldValue"); + HARD_ASSERT(type() == Type::Object, + "Cannot get field for non-object FieldValue"); const FieldValue* current = this; for (const auto& path : field_path) { if (current->type() != Type::Object) { @@ -435,8 +434,7 @@ bool operator<(const FieldValue& lhs, const FieldValue& rhs) { case Type::Object: return lhs.object_value_ < rhs.object_value_; default: - FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION( - false, lhs.type(), "Unsupported type %d", lhs.type()); + HARD_FAIL("Unsupported type %s", lhs.type()); // return false if assertion does not abort the program. We will say // each unsupported type takes only one value thus everything is equal. return false; -- cgit v1.2.3