bdash pr fixes

This commit is contained in:
Ari Lazier 2016-01-04 18:13:09 -08:00
parent 24be3ab825
commit 518133e769
12 changed files with 124 additions and 124 deletions

View File

@ -21,7 +21,7 @@ JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pro
return JSValueMakeNumber(ctx, size);
}
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(RJSValidatedPositiveIndex(indexStr))));
return RJSObjectCreate(ctx, Object(list->realm(), list->get_object_schema(), list->get(RJSValidatedPositiveIndex(indexStr))));
}
catch (std::out_of_range &exp) {
// getters for nonexistent properties in JS should always return undefined
@ -103,7 +103,7 @@ JSValueRef ListPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObjec
return JSValueMakeUndefined(ctx);
}
size_t index = size - 1;
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->get_object_schema(), list->get(index)));
list->remove(index);
return obj;
}
@ -140,7 +140,7 @@ JSValueRef ListShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj
list->verify_in_tranaction();
return JSValueMakeUndefined(ctx);
}
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(0)));
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->get_object_schema(), list->get(0)));
list->remove(0);
return obj;
}
@ -168,7 +168,7 @@ JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb
std::vector<JSObjectRef> removedObjects(remove);
for (size_t i = 0; i < remove; i++) {
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->get_object_schema(), list->get(index)));
list->remove(index);
}
for (size_t i = 2; i < argumentCount; i++) {

View File

@ -45,7 +45,7 @@ bool ObjectSetProperty(JSContextRef ctx, JSObjectRef jsObject, JSStringRef jsPro
void ObjectPropertyNames(JSContextRef ctx, JSObjectRef jsObject, JSPropertyNameAccumulatorRef propertyNames) {
Object *obj = RJSGetInternal<Object *>(jsObject);
for (auto &prop : obj->object_schema().properties) {
for (auto &prop : obj->get_object_schema().properties) {
JSStringRef propertyName = RJSStringForString(prop.name);
JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
JSStringRelease(propertyName);
@ -58,7 +58,7 @@ JSClassRef RJSObjectClass() {
}
JSObjectRef RJSObjectCreate(JSContextRef ctx, Object object) {
JSValueRef prototype = RJSPrototypes(object.realm().get())[object.object_schema().name];
JSValueRef prototype = RJSPrototypes(object.realm().get())[object.get_object_schema().name];
JSObjectRef jsObject = RJSWrapObject(ctx, RJSObjectClass(), new Object(object), prototype);
return jsObject;
}

View File

@ -332,7 +332,7 @@ JSValueRef RealmDelete(JSContextRef ctx, JSObjectRef function, JSObjectRef thisO
throw std::runtime_error("Can only delete objects within a transaction.");
}
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object->object_schema().name);
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object->get_object_schema().name);
table->move_last_over(object->row().get_index());
return NULL;

View File

@ -23,7 +23,7 @@ JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef
}
return RJSObjectCreate(ctx, Object(results->get_realm(),
results->object_schema(),
results->get_object_schema(),
results->get(RJSValidatedPositiveIndex(indexStr))));
}
catch (std::out_of_range &exp) {
@ -76,9 +76,9 @@ JSValueRef SortByProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef th
Results *results = RJSGetInternal<Results *>(thisObject);
RJSValidateArgumentRange(argumentCount, 1, 2);
std::string propName = RJSValidatedStringForValue(ctx, arguments[0]);
const Property *prop = results->object_schema().property_for_name(propName);
const Property *prop = results->get_object_schema().property_for_name(propName);
if (!prop) {
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->object_schema().name + "'");
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->get_object_schema().name + "'");
}
bool ascending = true;

View File

@ -27,7 +27,7 @@ namespace realm {
public:
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {}
const ObjectSchema &object_schema() const { return *m_object_schema; }
const ObjectSchema &get_object_schema() const { return *m_object_schema; }
SharedRealm realm() { return m_realm; }
size_t size();

View File

@ -28,7 +28,7 @@ namespace realm {
static inline Object create(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, ValueType value, bool try_update);
SharedRealm realm() { return m_realm; }
const ObjectSchema &object_schema() { return *m_object_schema; }
const ObjectSchema &get_object_schema() { return *m_object_schema; }
Row row() { return m_row; }
private:
@ -309,19 +309,19 @@ namespace realm {
template<typename ValueType, typename ContextType>
void List::add(ContextType ctx, ValueType value)
{
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, get_object_schema().name, false));
}
template<typename ValueType, typename ContextType>
void List::insert(ContextType ctx, ValueType value, size_t list_ndx)
{
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, get_object_schema().name, false));
}
template<typename ValueType, typename ContextType>
void List::set(ContextType ctx, ValueType value, size_t list_ndx)
{
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, get_object_schema().name, false));
}
}

View File

@ -23,64 +23,64 @@
#include <string>
namespace realm {
class Schema;
class Schema;
namespace parser {
struct Expression
{
enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None;
std::string s;
};
namespace parser {
struct Expression
{
enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None;
std::string s;
};
struct Predicate
{
enum class Type
{
Comparison,
Or,
And,
True,
False
} type = Type::And;
struct Predicate
{
enum class Type
{
Comparison,
Or,
And,
True,
False
} type = Type::And;
enum class Operator
{
None,
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
BeginsWith,
EndsWith,
Contains
};
enum class Operator
{
None,
Equal,
NotEqual,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
BeginsWith,
EndsWith,
Contains
};
struct Comparison
{
Operator op = Operator::None;
Expression expr[2];
};
struct Comparison
{
Operator op = Operator::None;
Expression expr[2];
};
struct Compound
{
std::vector<Predicate> sub_predicates;
};
struct Compound
{
std::vector<Predicate> sub_predicates;
};
Comparison cmpr;
Compound cpnd;
Comparison cmpr;
Compound cpnd;
bool negate = false;
bool negate = false;
Predicate(Type t, bool n = false) : type(t), negate(n) {}
};
Predicate(Type t, bool n = false) : type(t), negate(n) {}
};
Predicate parse(const std::string &query);
void analyzeGrammar();
bool testGrammar();
}
Predicate parse(const std::string &query);
void analyzeGrammar();
bool testGrammar();
}
}
#endif // REALM_PARSER_HPP

View File

@ -230,7 +230,7 @@ void add_binary_constraint_to_query(realm::Query &query,
void add_link_constraint_to_query(realm::Query &query,
Predicate::Operator op,
PropertyExpression &prop_expr,
const PropertyExpression &prop_expr,
size_t row_index) {
precondition(prop_expr.indexes.empty(), "KeyPath queries not supported for object comparisons.");
switch (op) {
@ -260,12 +260,12 @@ void add_link_constraint_to_query(realm::Query &query,
}
}
auto link_argument(PropertyExpression &propExpr, parser::Expression &argExpr, Arguments &args)
auto link_argument(const PropertyExpression &propExpr, const parser::Expression &argExpr, Arguments &args)
{
return args.object_index_for_argument(std::stoi(argExpr.s));
}
auto link_argument(parser::Expression &argExpr, PropertyExpression &propExpr, Arguments &args)
auto link_argument(const parser::Expression &argExpr, const PropertyExpression &propExpr, Arguments &args)
{
return args.object_index_for_argument(std::stoi(argExpr.s));
}
@ -376,7 +376,7 @@ auto value_of_type_for_query(TableGetter&& tables, Value&& value, Arguments &arg
template <typename A, typename B>
void do_add_comparison_to_query(Query &query, const Schema &schema, const ObjectSchema &object_schema, Predicate::Operator op,
PropertyExpression &expr, A &lhs, B &rhs, Arguments &args)
const PropertyExpression &expr, A &lhs, B &rhs, Arguments &args)
{
auto type = expr.prop->type;
switch (type) {
@ -418,9 +418,9 @@ void do_add_comparison_to_query(Query &query, const Schema &schema, const Object
}
}
void add_comparison_to_query(Query &query, Predicate &pred, Arguments &args, const Schema &schema, const std::string &type)
void add_comparison_to_query(Query &query, const Predicate &pred, Arguments &args, const Schema &schema, const std::string &type)
{
Predicate::Comparison &cmpr = pred.cmpr;
const Predicate::Comparison &cmpr = pred.cmpr;
auto t0 = cmpr.expr[0].type, t1 = cmpr.expr[1].type;
auto object_schema = schema.find(type);
if (t0 == parser::Expression::Type::KeyPath && t1 != parser::Expression::Type::KeyPath) {
@ -436,7 +436,7 @@ void add_comparison_to_query(Query &query, Predicate &pred, Arguments &args, con
}
}
void update_query_with_predicate(Query &query, Predicate &pred, Arguments &arguments, const Schema &schema, const std::string &type)
void update_query_with_predicate(Query &query, const Predicate &pred, Arguments &arguments, const Schema &schema, const std::string &type)
{
if (pred.negate) {
query.Not();
@ -484,7 +484,7 @@ void update_query_with_predicate(Query &query, Predicate &pred, Arguments &argum
}
}
void apply_predicate(Query &query, Predicate &predicate, Arguments &arguments, const Schema &schema, std::string objectType)
void apply_predicate(Query &query, const Predicate &predicate, Arguments &arguments, const Schema &schema, const std::string &objectType)
{
update_query_with_predicate(query, predicate, arguments, schema, objectType);

View File

@ -24,57 +24,57 @@
#include "object_accessor.hpp"
namespace realm {
class Query;
class Schema;
class Query;
class Schema;
namespace query_builder {
class Arguments;
namespace query_builder {
class Arguments;
void apply_predicate(Query &query, parser::Predicate &predicate, Arguments &arguments, const Schema &schema, std::string objectType);
void apply_predicate(Query &query, const parser::Predicate &predicate, Arguments &arguments, const Schema &schema, const std::string &objectType);
class Arguments
{
public:
virtual bool bool_for_argument(size_t argument_index) = 0;
virtual long long long_for_argument(size_t argument_index) = 0;
virtual float float_for_argument(size_t argument_index) = 0;
virtual double double_for_argument(size_t argument_index) = 0;
virtual std::string string_for_argument(size_t argument_index) = 0;
virtual std::string binary_for_argument(size_t argument_index) = 0;
virtual DateTime datetime_for_argument(size_t argument_index) = 0;
virtual size_t object_index_for_argument(size_t argument_index) = 0;
virtual bool is_argument_null(size_t argument_index) = 0;
};
class Arguments
{
public:
virtual bool bool_for_argument(size_t argument_index) = 0;
virtual long long long_for_argument(size_t argument_index) = 0;
virtual float float_for_argument(size_t argument_index) = 0;
virtual double double_for_argument(size_t argument_index) = 0;
virtual std::string string_for_argument(size_t argument_index) = 0;
virtual std::string binary_for_argument(size_t argument_index) = 0;
virtual DateTime datetime_for_argument(size_t argument_index) = 0;
virtual size_t object_index_for_argument(size_t argument_index) = 0;
virtual bool is_argument_null(size_t argument_index) = 0;
};
template<typename ValueType, typename ContextType>
class ArgumentConverter : public Arguments
{
public:
ArgumentConverter(ContextType context, std::vector<ValueType> arguments) : m_arguments(arguments), m_ctx(context) {};
template<typename ValueType, typename ContextType>
class ArgumentConverter : public Arguments
{
public:
ArgumentConverter(ContextType context, std::vector<ValueType> arguments) : m_arguments(arguments), m_ctx(context) {};
using Accessor = realm::NativeAccessor<ValueType, ContextType>;
virtual bool bool_for_argument(size_t argument_index) { return Accessor::to_bool(m_ctx, argument_at(argument_index)); }
virtual long long long_for_argument(size_t argument_index) { return Accessor::to_long(m_ctx, argument_at(argument_index)); }
virtual float float_for_argument(size_t argument_index) { return Accessor::to_float(m_ctx, argument_at(argument_index)); }
virtual double double_for_argument(size_t argument_index) { return Accessor::to_double(m_ctx, argument_at(argument_index)); }
virtual std::string string_for_argument(size_t argument_index) { return Accessor::to_string(m_ctx, argument_at(argument_index)); }
virtual std::string binary_for_argument(size_t argument_index) { return Accessor::to_binary(m_ctx, argument_at(argument_index)); }
virtual DateTime datetime_for_argument(size_t argument_index) { return Accessor::to_datetime(m_ctx, argument_at(argument_index)); }
virtual size_t object_index_for_argument(size_t argument_index) { return Accessor::to_existing_object_index(m_ctx, argument_at(argument_index)); }
virtual bool is_argument_null(size_t argument_index) { return Accessor::is_null(m_ctx, argument_at(argument_index)); }
using Accessor = realm::NativeAccessor<ValueType, ContextType>;
virtual bool bool_for_argument(size_t argument_index) { return Accessor::to_bool(m_ctx, argument_at(argument_index)); }
virtual long long long_for_argument(size_t argument_index) { return Accessor::to_long(m_ctx, argument_at(argument_index)); }
virtual float float_for_argument(size_t argument_index) { return Accessor::to_float(m_ctx, argument_at(argument_index)); }
virtual double double_for_argument(size_t argument_index) { return Accessor::to_double(m_ctx, argument_at(argument_index)); }
virtual std::string string_for_argument(size_t argument_index) { return Accessor::to_string(m_ctx, argument_at(argument_index)); }
virtual std::string binary_for_argument(size_t argument_index) { return Accessor::to_binary(m_ctx, argument_at(argument_index)); }
virtual DateTime datetime_for_argument(size_t argument_index) { return Accessor::to_datetime(m_ctx, argument_at(argument_index)); }
virtual size_t object_index_for_argument(size_t argument_index) { return Accessor::to_existing_object_index(m_ctx, argument_at(argument_index)); }
virtual bool is_argument_null(size_t argument_index) { return Accessor::is_null(m_ctx, argument_at(argument_index)); }
private:
std::vector<ValueType> m_arguments;
ContextType m_ctx;
private:
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 " + std::to_string(index) + " out of range 0.." + std::to_string(m_arguments.size()-1));
}
return m_arguments[index];
}
};
}
}
#endif // REALM_QUERY_BUILDER_HPP

View File

@ -315,12 +315,12 @@ TableView Results::get_tableview()
Results Results::sort(realm::SortOrder&& sort) const
{
return Results(m_realm, object_schema(), get_query(), std::move(sort));
return Results(m_realm, get_object_schema(), get_query(), std::move(sort));
}
Results Results::filter(Query&& q) const
{
return Results(m_realm, object_schema(), get_query().and_query(std::move(q)), get_sort());
return Results(m_realm, get_object_schema(), get_query().and_query(std::move(q)), get_sort());
}
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table)

View File

@ -46,8 +46,8 @@ public:
// or a wrapper around a query and a sort order which creates and updates
// the tableview as needed
Results() = default;
Results(SharedRealm r, const ObjectSchema &o, Table& table);
Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s = {});
Results(SharedRealm r, const ObjectSchema& o, Table& table);
Results(SharedRealm r, const ObjectSchema& o, Query q, SortOrder s = {});
// Results is copyable and moveable
Results(Results const&) = default;
@ -59,7 +59,7 @@ public:
SharedRealm get_realm() const { return m_realm; }
// Object schema describing the vendored object type
const ObjectSchema &object_schema() const { return *m_object_schema; }
const ObjectSchema &get_object_schema() const { return *m_object_schema; }
// Get a query which will match the same rows as is contained in this Results
// Returned query will not be valid if the current mode is Empty
@ -72,7 +72,7 @@ public:
TableView get_tableview();
// Get the object type which will be returned by get()
StringData get_object_type() const noexcept { return object_schema().name; }
StringData get_object_type() const noexcept { return get_object_schema().name; }
// Get the size of this results
// Can be either O(1) or O(N) depending on the state of things

View File

@ -220,7 +220,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
return {
{"type", RJSTypeGet(realm::PropertyTypeObject)},
{"id", store_object(js_object)},
{"schema", serialize_object_schema(object->object_schema())}
{"schema", serialize_object_schema(object->get_object_schema())}
};
}
else if (JSValueIsObjectOfClass(m_context, value, RJSListClass())) {
@ -229,7 +229,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
{"type", RJSTypeGet(realm::PropertyTypeArray)},
{"id", store_object(js_object)},
{"size", list->size()},
{"schema", serialize_object_schema(list->object_schema())}
{"schema", serialize_object_schema(list->get_object_schema())}
};
}
else if (JSValueIsObjectOfClass(m_context, value, RJSResultsClass())) {
@ -238,7 +238,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
{"type", RealmObjectTypesResults},
{"id", store_object(js_object)},
{"size", results->size()},
{"schema", serialize_object_schema(results->object_schema())}
{"schema", serialize_object_schema(results->get_object_schema())}
};
}
else if (RJSIsValueArray(m_context, value)) {