USe more const refs to avoid copies

This commit is contained in:
Thomas Goyne 2015-09-04 09:53:51 -07:00
parent dbac77f69b
commit 7de20ea3a6
2 changed files with 33 additions and 33 deletions

View File

@ -19,8 +19,8 @@
#include "object_store.hpp"
#include <realm/group.hpp>
#include <realm/table.hpp>
#include <realm/link_view.hpp>
#include <realm/table.hpp>
#include <realm/table_view.hpp>
#include <realm/util/assert.hpp>
@ -479,41 +479,41 @@ InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_versio
m_what = "Provided schema version " + std::to_string(old_version) + " is less than last set version " + std::to_string(new_version) + ".";
}
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string object_type, Property const& property) :
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
m_object_type(object_type), m_property(property)
{
m_what = "Primary key property '" + property.name + "' has duplicate values after migration.";
};
SchemaValidationException::SchemaValidationException(std::vector<ObjectSchemaValidationException> errors) :
SchemaValidationException::SchemaValidationException(std::vector<ObjectSchemaValidationException> const& errors) :
m_validation_errors(errors)
{
m_what ="Migration is required due to the following errors: ";
for (auto error : errors) {
for (auto const& error : errors) {
m_what += std::string("\n- ") + error.what();
}
}
PropertyTypeNotIndexableException::PropertyTypeNotIndexableException(std::string object_type, Property const& property) :
PropertyTypeNotIndexableException::PropertyTypeNotIndexableException(std::string const& object_type, Property const& property) :
ObjectSchemaPropertyException(object_type, property)
{
m_what = "Can't index property " + object_type + "." + property.name + ": indexing a property of type '" + string_for_property_type(property.type) + "' is currently not supported";
}
ExtraPropertyException::ExtraPropertyException(std::string object_type, Property const& property) :
ExtraPropertyException::ExtraPropertyException(std::string const& object_type, Property const& property) :
ObjectSchemaPropertyException(object_type, property)
{
m_what = "Property '" + property.name + "' has been added to latest object model.";
}
MissingPropertyException::MissingPropertyException(std::string object_type, Property const& property) :
MissingPropertyException::MissingPropertyException(std::string const& object_type, Property const& property) :
ObjectSchemaPropertyException(object_type, property)
{
m_what = "Property '" + property.name + "' is missing from latest object model.";
}
InvalidNullabilityException::InvalidNullabilityException(std::string object_type, Property const& property) :
InvalidNullabilityException::InvalidNullabilityException(std::string const& object_type, Property const& property) :
ObjectSchemaPropertyException(object_type, property)
{
#if REALM_NULL_STRINGS == 1
@ -532,13 +532,13 @@ InvalidNullabilityException::InvalidNullabilityException(std::string object_type
#endif
}
MissingObjectTypeException::MissingObjectTypeException(std::string object_type, Property const& property) :
MissingObjectTypeException::MissingObjectTypeException(std::string const& object_type, Property const& property) :
ObjectSchemaPropertyException(object_type, property)
{
m_what = "Target type '" + property.object_type + "' doesn't exist for property '" + property.name + "'.";
}
MismatchedPropertiesException::MismatchedPropertiesException(std::string object_type, Property const& old_property, Property const& new_property) :
MismatchedPropertiesException::MismatchedPropertiesException(std::string const& object_type, Property const& old_property, Property const& new_property) :
ObjectSchemaValidationException(object_type), m_old_property(old_property), m_new_property(new_property)
{
if (new_property.type != old_property.type) {
@ -553,7 +553,7 @@ MismatchedPropertiesException::MismatchedPropertiesException(std::string object_
}
}
ChangedPrimaryKeyException::ChangedPrimaryKeyException(std::string object_type, std::string old_primary, std::string new_primary) : ObjectSchemaValidationException(object_type), m_old_primary(old_primary), m_new_primary(new_primary)
ChangedPrimaryKeyException::ChangedPrimaryKeyException(std::string const& object_type, std::string const& old_primary, std::string const& new_primary) : ObjectSchemaValidationException(object_type), m_old_primary(old_primary), m_new_primary(new_primary)
{
if (old_primary.size()) {
m_what = "Property '" + old_primary + "' is no longer a primary key.";
@ -563,13 +563,13 @@ ChangedPrimaryKeyException::ChangedPrimaryKeyException(std::string object_type,
}
}
InvalidPrimaryKeyException::InvalidPrimaryKeyException(std::string object_type, std::string primary) :
InvalidPrimaryKeyException::InvalidPrimaryKeyException(std::string const& object_type, std::string const& primary) :
ObjectSchemaValidationException(object_type), m_primary_key(primary)
{
m_what = "Specified primary key property '" + primary + "' does not exist.";
}
DuplicatePrimaryKeysException::DuplicatePrimaryKeysException(std::string object_type) : ObjectSchemaValidationException(object_type)
DuplicatePrimaryKeysException::DuplicatePrimaryKeysException(std::string const& object_type) : ObjectSchemaValidationException(object_type)
{
m_what = "Duplicate primary keys for object '" + object_type + "'.";
}

View File

@ -19,14 +19,14 @@
#ifndef REALM_OBJECT_STORE_HPP
#define REALM_OBJECT_STORE_HPP
#include <vector>
#include <functional>
#include <realm/link_view.hpp>
#include <realm/group.hpp>
#include "object_schema.hpp"
#include "property.hpp"
#include <functional>
#include <realm/group.hpp>
#include <realm/link_view.hpp>
namespace realm {
class ObjectSchemaValidationException;
using Schema = std::vector<ObjectSchema>;
@ -137,7 +137,7 @@ namespace realm {
class DuplicatePrimaryKeyValueException : public MigrationException {
public:
DuplicatePrimaryKeyValueException(std::string object_type, Property const& property);
DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property);
std::string object_type() const { return m_object_type; }
Property const& property() const { return m_property; }
private:
@ -148,16 +148,16 @@ namespace realm {
// Schema validation exceptions
class SchemaValidationException : public ObjectStoreException {
public:
SchemaValidationException(std::vector<ObjectSchemaValidationException> errors);
std::vector<ObjectSchemaValidationException> &validation_errors() { return m_validation_errors; }
SchemaValidationException(std::vector<ObjectSchemaValidationException> const& errors);
std::vector<ObjectSchemaValidationException> const& validation_errors() const { return m_validation_errors; }
private:
std::vector<ObjectSchemaValidationException> m_validation_errors;
};
class ObjectSchemaValidationException : public ObjectStoreException {
public:
ObjectSchemaValidationException(std::string object_type) : m_object_type(object_type) {}
ObjectSchemaValidationException(std::string object_type, std::string message) :
ObjectSchemaValidationException(std::string const& object_type) : m_object_type(object_type) {}
ObjectSchemaValidationException(std::string const& object_type, std::string const& message) :
m_object_type(object_type) { m_what = message; }
std::string object_type() const { return m_object_type; }
protected:
@ -166,7 +166,7 @@ namespace realm {
class ObjectSchemaPropertyException : public ObjectSchemaValidationException {
public:
ObjectSchemaPropertyException(std::string object_type, Property const& property) :
ObjectSchemaPropertyException(std::string const& object_type, Property const& property) :
ObjectSchemaValidationException(object_type), m_property(property) {}
Property const& property() const { return m_property; }
private:
@ -175,37 +175,37 @@ namespace realm {
class PropertyTypeNotIndexableException : public ObjectSchemaPropertyException {
public:
PropertyTypeNotIndexableException(std::string object_type, Property const& property);
PropertyTypeNotIndexableException(std::string const& object_type, Property const& property);
};
class ExtraPropertyException : public ObjectSchemaPropertyException {
public:
ExtraPropertyException(std::string object_type, Property const& property);
ExtraPropertyException(std::string const& object_type, Property const& property);
};
class MissingPropertyException : public ObjectSchemaPropertyException {
public:
MissingPropertyException(std::string object_type, Property const& property);
MissingPropertyException(std::string const& object_type, Property const& property);
};
class InvalidNullabilityException : public ObjectSchemaPropertyException {
public:
InvalidNullabilityException(std::string object_type, Property const& property);
InvalidNullabilityException(std::string const& object_type, Property const& property);
};
class MissingObjectTypeException : public ObjectSchemaPropertyException {
public:
MissingObjectTypeException(std::string object_type, Property const& property);
MissingObjectTypeException(std::string const& object_type, Property const& property);
};
class DuplicatePrimaryKeysException : public ObjectSchemaValidationException {
public:
DuplicatePrimaryKeysException(std::string object_type);
DuplicatePrimaryKeysException(std::string const& object_type);
};
class MismatchedPropertiesException : public ObjectSchemaValidationException {
public:
MismatchedPropertiesException(std::string object_type, Property const& old_property, Property const& new_property);
MismatchedPropertiesException(std::string const& object_type, Property const& old_property, Property const& new_property);
Property const& old_property() const { return m_old_property; }
Property const& new_property() const { return m_new_property; }
private:
@ -214,7 +214,7 @@ namespace realm {
class ChangedPrimaryKeyException : public ObjectSchemaValidationException {
public:
ChangedPrimaryKeyException(std::string object_type, std::string old_primary, std::string new_primary);
ChangedPrimaryKeyException(std::string const& object_type, std::string const& old_primary, std::string const& new_primary);
std::string old_primary() const { return m_old_primary; }
std::string new_primary() const { return m_new_primary; }
private:
@ -223,7 +223,7 @@ namespace realm {
class InvalidPrimaryKeyException : public ObjectSchemaValidationException {
public:
InvalidPrimaryKeyException(std::string object_type, std::string primary_key);
InvalidPrimaryKeyException(std::string const& object_type, std::string const& primary_key);
std::string primary_key() const { return m_primary_key; }
private:
std::string m_primary_key;