This commit is contained in:
Ari Lazier 2015-12-08 12:37:38 -08:00
parent 5e7a952f48
commit 66fd4ce2f7
11 changed files with 54 additions and 27 deletions

View File

@ -293,10 +293,12 @@ public:
// Things that just mark the field as modified
bool set_int(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); }
bool set_int_unique(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); }
bool set_bool(size_t col, size_t row, bool) { return mark_dirty(row, col); }
bool set_float(size_t col, size_t row, float) { return mark_dirty(row, col); }
bool set_double(size_t col, size_t row, double) { return mark_dirty(row, col); }
bool set_string(size_t col, size_t row, StringData) { return mark_dirty(row, col); }
bool set_string_unique(size_t col, size_t row, StringData) { return mark_dirty(row, col); }
bool set_binary(size_t col, size_t row, BinaryData) { return mark_dirty(row, col); }
bool set_date_time(size_t col, size_t row, DateTime) { return mark_dirty(row, col); }
bool set_table(size_t col, size_t row) { return mark_dirty(row, col); }

View File

@ -21,6 +21,7 @@
#include <cstdlib>
#include <vector>
#include <stddef.h>
namespace realm {
class IndexSet {

View File

@ -63,7 +63,7 @@ void List::remove(std::size_t row_ndx) {
void List::verify_valid_row(std::size_t row_ndx, bool insertion) {
size_t size = m_link_view->size();
if (row_ndx > size || (!insertion && row_ndx == size)) {
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
throw std::out_of_range(std::string("Index ") + to_string(row_ndx) + " is outside of range 0..." + to_string(size) + ".");
}
}

View File

@ -520,7 +520,7 @@ bool ObjectStore::is_empty(const Group *group) {
InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) :
m_old_version(old_version), m_new_version(new_version)
{
m_what = "Provided schema version " + std::to_string(old_version) + " is less than last set version " + std::to_string(new_version) + ".";
m_what = "Provided schema version " + to_string(old_version) + " is less than last set version " + to_string(new_version) + ".";
}
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
@ -589,7 +589,7 @@ MismatchedPropertiesException::MismatchedPropertiesException(std::string const&
m_what = "Target object type for property '" + old_property.name + "' do not match. Old type '" + old_property.object_type + "', new type '" + new_property.object_type + "'";
}
else if (new_property.is_nullable != old_property.is_nullable) {
m_what = "Nullability for property '" + old_property.name + "' has changed from '" + std::to_string(old_property.is_nullable) + "' to '" + std::to_string(new_property.is_nullable) + "'.";
m_what = "Nullability for property '" + old_property.name + "' has changed from '" + to_string(old_property.is_nullable) + "' to '" + to_string(new_property.is_nullable) + "'.";
}
}

View File

@ -27,6 +27,8 @@
#include <realm/group.hpp>
#include <realm/link_view.hpp>
#include <sstream>
namespace realm {
class ObjectSchemaValidationException;
class Schema;
@ -233,6 +235,13 @@ namespace realm {
private:
std::string m_primary_key;
};
template<typename T>
std::string to_string(T value) {
std::ostringstream oss;
oss << value;
return oss.str();
}
}
#endif /* defined(REALM_OBJECT_STORE_HPP) */

View File

@ -29,6 +29,17 @@ namespace realm {
namespace query_builder {
using namespace parser;
template<typename T>
T stot(const std::string s) {
std::istringstream iss(s);
T value;
iss >> value;
if (iss.fail()) {
throw std::invalid_argument("Cannot convert string '" + s + "'");
}
return value;
}
// check a precondition and throw an exception if it is not met
// this should be used iff the condition being false indicates a bug in the caller
// of the function checking its preconditions
@ -262,12 +273,12 @@ void add_link_constraint_to_query(realm::Query &query,
auto link_argument(const PropertyExpression &propExpr, const parser::Expression &argExpr, Arguments &args)
{
return args.object_index_for_argument(std::stoi(argExpr.s));
return args.object_index_for_argument(stot<int>(argExpr.s));
}
auto link_argument(const parser::Expression &argExpr, const PropertyExpression &propExpr, Arguments &args)
{
return args.object_index_for_argument(std::stoi(argExpr.s));
return args.object_index_for_argument(stot<int>(argExpr.s));
}
@ -289,7 +300,7 @@ struct ValueGetter<DateTime, TableGetter> {
if (value.type != parser::Expression::Type::Argument) {
throw std::runtime_error("You must pass in a date argument to compare");
}
DateTime dt = args.datetime_for_argument(std::stoi(value.s));
DateTime dt = args.datetime_for_argument(stot<int>(value.s));
return dt.get_datetime();
}
};
@ -299,7 +310,7 @@ struct ValueGetter<bool, TableGetter> {
static bool convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.bool_for_argument(std::stoi(value.s));
return args.bool_for_argument(stot<int>(value.s));
}
if (value.type != parser::Expression::Type::True && value.type != parser::Expression::Type::False) {
throw std::runtime_error("Attempting to compare bool property to a non-bool value");
@ -313,9 +324,9 @@ struct ValueGetter<Double, TableGetter> {
static Double convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.double_for_argument(std::stoi(value.s));
return args.double_for_argument(stot<int>(value.s));
}
return std::stod(value.s);
return stot<double>(value.s);
}
};
@ -324,9 +335,9 @@ struct ValueGetter<Float, TableGetter> {
static Float convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.float_for_argument(std::stoi(value.s));
return args.float_for_argument(stot<int>(value.s));
}
return std::stof(value.s);
return stot<float>(value.s);
}
};
@ -335,9 +346,9 @@ struct ValueGetter<Int, TableGetter> {
static Int convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.long_for_argument(std::stoi(value.s));
return args.long_for_argument(stot<int>(value.s));
}
return std::stoll(value.s);
return stot<long long>(value.s);
}
};
@ -346,7 +357,7 @@ struct ValueGetter<String, TableGetter> {
static std::string convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.string_for_argument(std::stoi(value.s));
return args.string_for_argument(stot<int>(value.s));
}
if (value.type != parser::Expression::Type::String) {
throw std::runtime_error("Attempting to compare String property to a non-String value");
@ -360,7 +371,7 @@ struct ValueGetter<Binary, TableGetter> {
static std::string convert(TableGetter&&, const parser::Expression & value, Arguments &args)
{
if (value.type == parser::Expression::Type::Argument) {
return args.binary_for_argument(std::stoi(value.s));
return args.binary_for_argument(stot<int>(value.s));
}
throw std::runtime_error("Binary properties must be compared against a binary argument.");
}

View File

@ -67,11 +67,13 @@ class ArgumentConverter : public Arguments
std::vector<ValueType> m_arguments;
ContextType m_ctx;
ValueType &argument_at(size_t index) {
if (index >= m_arguments.size()) {
throw std::out_of_range((std::string)"Argument index " + std::to_string(index) + " out of range 0.." + std::to_string(m_arguments.size()-1));
}
return m_arguments[index];
ValueType &argument_at(size_t index) {
if (index >= m_arguments.size()) {
throw std::out_of_range((std::string)"Argument index " + to_string(index) + " out of range 0.." + to_string(m_arguments.size()-1));
}
return m_arguments[index];
}
};
}
};
}

View File

@ -133,8 +133,8 @@ public:
struct OutOfBoundsIndexException : public std::out_of_range
{
OutOfBoundsIndexException(size_t r, size_t c) : requested(r), valid_count(c),
std::out_of_range((std::string)"Requested index " + std::to_string(r) +
" greater than max " + std::to_string(c)) {}
std::out_of_range((std::string)"Requested index " + to_string(r) +
" greater than max " + to_string(c)) {}
const size_t requested;
const size_t valid_count;
};

View File

@ -21,6 +21,7 @@
#include <string>
#include <vector>
#include <string>
namespace realm {
class ObjectSchema;

View File

@ -47,7 +47,7 @@ Realm::Config::Config(const Config& c)
, migration_function(c.migration_function)
{
if (c.schema) {
schema = std::make_unique<Schema>(*c.schema);
schema.reset(new Schema(*c.schema));
}
}
@ -68,14 +68,14 @@ Realm::Realm(Config config)
{
try {
if (m_config.read_only) {
m_read_only_group = std::make_unique<Group>(m_config.path, m_config.encryption_key.data(), Group::mode_ReadOnly);
m_read_only_group.reset(new Group(m_config.path, m_config.encryption_key.data(), Group::mode_ReadOnly));
m_group = m_read_only_group.get();
}
else {
m_history = realm::make_client_history(m_config.path, m_config.encryption_key.data());
SharedGroup::DurabilityLevel durability = m_config.in_memory ? SharedGroup::durability_MemOnly :
SharedGroup::durability_Full;
m_shared_group = std::make_unique<SharedGroup>(*m_history, durability, m_config.encryption_key.data(), !m_config.disable_format_upgrade);
m_shared_group.reset(new SharedGroup(*m_history, durability, m_config.encryption_key.data()));
}
}
catch (util::File::PermissionDenied const& ex) {
@ -157,7 +157,7 @@ SharedRealm Realm::get_shared_realm(Config config)
if (auto existing = s_global_cache.get_any_realm(realm->config().path)) {
// if there is an existing realm at the current path steal its schema/column mapping
// FIXME - need to validate that schemas match
realm->m_config.schema = std::make_unique<Schema>(*existing->m_config.schema);
realm->m_config.schema.reset(new Schema(*existing->m_config.schema));
#if __APPLE__
realm->m_notifier = existing->m_notifier;
@ -170,7 +170,7 @@ SharedRealm Realm::get_shared_realm(Config config)
#endif
// otherwise get the schema from the group
realm->m_config.schema = std::make_unique<Schema>(ObjectStore::schema_from_group(realm->read_group()));
realm->m_config.schema.reset(new Schema(ObjectStore::schema_from_group(realm->read_group())));
// if a target schema is supplied, verify that it matches or migrate to
// it, as neeeded

View File

@ -25,6 +25,7 @@
#include <mutex>
#include <thread>
#include <vector>
#include <mutex>
namespace realm {
class ClientHistory;