negate if statements

This commit is contained in:
Ari Lazier 2016-06-13 14:07:50 -07:00
parent cd20d870dd
commit 2b48ebb30a
1 changed files with 9 additions and 7 deletions

View File

@ -122,14 +122,16 @@ struct NativeAccessor {
} }
static size_t to_existing_object_index(ContextType ctx, SharedRealm realm, ValueType &value) { static size_t to_existing_object_index(ContextType ctx, SharedRealm realm, ValueType &value) {
ObjectType object = Value::validated_to_object(ctx, value); ObjectType object = Value::validated_to_object(ctx, value);
if (Object::template is_instance<RealmObjectClass<T>>(ctx, object)) { if (!Object::template is_instance<RealmObjectClass<T>>(ctx, object)) {
auto realm_object = get_internal<T, RealmObjectClass<T>>(object); throw std::runtime_error("object is not a Realm Object");
if (realm_object->realm() == realm) {
return realm_object->row().get_index();
}
throw std::runtime_error("Realm object is from another Realm");
} }
throw std::runtime_error("object is not a Realm Object");
auto realm_object = get_internal<T, RealmObjectClass<T>>(object);
if (realm_object->realm() != realm) {
throw std::runtime_error("Realm object is from another Realm");
}
return realm_object->row().get_index();
} }
static ValueType from_object(ContextType ctx, realm::Object realm_object) { static ValueType from_object(ContextType ctx, realm::Object realm_object) {
return RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)); return RealmObjectClass<T>::create_instance(ctx, std::move(realm_object));