Merge pull request #34 from realm/al-android

Support compilation for android with gcc/remove apple specific code
This commit is contained in:
Ari Lazier 2016-03-04 10:33:20 -08:00
commit d163d68b83
18 changed files with 91 additions and 31 deletions

2
external/pegtl vendored

@ -1 +1 @@
Subproject commit 49a5b0a49e154b362ef9cf1e756dd8673ddd4efe
Subproject commit 3c4128a7e7e1288eb746418ea60c41477358f26a

View File

@ -199,6 +199,22 @@ void RealmCoordinator::clear_cache()
}
}
void RealmCoordinator::clear_all_caches()
{
std::vector<std::weak_ptr<RealmCoordinator>> to_clear;
{
std::lock_guard<std::mutex> lock(s_coordinator_mutex);
for (auto iter : s_coordinators_per_path) {
to_clear.push_back(iter.second);
}
}
for (auto weak_coordinator : to_clear) {
if (auto coordinator = weak_coordinator.lock()) {
coordinator->clear_cache();
}
}
}
void RealmCoordinator::send_commit_notifications()
{
REALM_ASSERT(!m_config.read_only);

View File

@ -65,7 +65,10 @@ public:
// Should only be called in test code, as continuing to use the previously
// cached instances will have odd results
static void clear_cache();
// Clears all caches on existing coordinators
static void clear_all_caches();
// Explicit constructor/destructor needed for the unique_ptrs to forward-declared types
RealmCoordinator();
~RealmCoordinator();

View File

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

View File

@ -17,10 +17,9 @@
////////////////////////////////////////////////////////////////////////////
#include "list.hpp"
#include "results.hpp"
#include "shared_realm.hpp"
#include <realm/util/to_string.hpp>
#include <stdexcept>
using namespace realm;
@ -45,8 +44,8 @@ void List::verify_valid_row(size_t row_ndx, bool insertion) const
{
size_t size = m_link_view->size();
if (row_ndx > size || (!insertion && row_ndx == size)) {
throw std::out_of_range("Index " + std::to_string(row_ndx) + " is outside of range 0..." +
std::to_string(size) + ".");
throw std::out_of_range("Index " + util::to_string(row_ndx) + " is outside of range 0..." +
util::to_string(size) + ".");
}
}

View File

@ -1,6 +1,20 @@
/* Copyright 2015 Realm Inc - All Rights Reserved
* Proprietary and Confidential
*/
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#ifndef REALM_OBJECT_ACCESSOR_HPP
#define REALM_OBJECT_ACCESSOR_HPP

View File

@ -17,7 +17,6 @@
////////////////////////////////////////////////////////////////////////////
#include "object_schema.hpp"
#include "object_store.hpp"
#include "property.hpp"

View File

@ -26,7 +26,7 @@
namespace realm {
class Group;
struct Property;
class Property;
class ObjectSchema {
public:

View File

@ -25,6 +25,7 @@
#include <realm/table.hpp>
#include <realm/table_view.hpp>
#include <realm/util/assert.hpp>
#include <realm/util/to_string.hpp>
#include <string.h>
@ -504,7 +505,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 " + util::to_string(old_version) + " is less than last set version " + util::to_string(new_version) + ".";
}
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
@ -573,7 +574,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 '" + util::to_string(old_property.is_nullable) + "' to '" + util::to_string(new_property.is_nullable) + "'.";
}
}

View File

@ -19,7 +19,7 @@
#ifndef REALM_OBJECT_STORE_HPP
#define REALM_OBJECT_STORE_HPP
#include "object_schema.hpp"
#include "schema.hpp"
#include "property.hpp"
#include <functional>
@ -27,6 +27,8 @@
#include <realm/group.hpp>
#include <realm/link_view.hpp>
#include <sstream>
namespace realm {
class ObjectSchemaValidationException;
class Schema;

View File

@ -227,7 +227,7 @@ template<> struct action< or_op >
template<> struct action< rule > { \
static void apply( const input & in, ParserState & state ) { \
DEBUG_PRINT_TOKEN(in.string()); \
state.add_expression(Expression{type, in.string()}); }};
state.add_expression(Expression(type, in.string())); }};
EXPRESSION_ACTION(dq_string_content, Expression::Type::String)
EXPRESSION_ACTION(sq_string_content, Expression::Type::String)

View File

@ -30,6 +30,7 @@ struct Expression
{
enum class Type { None, Number, String, KeyPath, Argument, True, False } type;
std::string s;
Expression(Type t = Type::None, std::string s = "") : type(t), s(s) {}
};
struct Predicate

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
@ -272,12 +283,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));
}
@ -299,7 +310,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();
}
};
@ -309,7 +320,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");
@ -323,9 +334,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);
}
};
@ -334,9 +345,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);
}
};
@ -345,9 +356,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);
}
};
@ -356,7 +367,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");
@ -370,7 +381,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

@ -20,6 +20,7 @@
#define REALM_QUERY_BUILDER_HPP
#include <string>
#include <realm/util/to_string.hpp>
#include "parser.hpp"
#include "object_accessor.hpp"
@ -69,7 +70,7 @@ class ArgumentConverter : public Arguments
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));
throw std::out_of_range((std::string)"Argument index " + util::to_string(index) + " out of range 0.." + util::to_string(m_arguments.size()-1));
}
return m_arguments[index];
}

View File

@ -25,6 +25,7 @@
#include <realm/table_view.hpp>
#include <realm/table.hpp>
#include <realm/util/optional.hpp>
#include <realm/util/to_string.hpp>
namespace realm {
template<typename T> class BasicRowExpr;
@ -161,8 +162,8 @@ public:
struct OutOfBoundsIndexException : public std::out_of_range
{
OutOfBoundsIndexException(size_t r, size_t 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 " + util::to_string(r) +
" greater than max " + util::to_string(c)),
requested(r), valid_count(c) {}
const size_t requested;
const size_t valid_count;

View File

@ -19,6 +19,7 @@
#ifndef REALM_SCHEMA_HPP
#define REALM_SCHEMA_HPP
#include "object_schema.hpp"
#include "property.hpp"
#include <string>

View File

@ -81,6 +81,9 @@ void Realm::open_with_config(const Config& config,
read_only_group = std::make_unique<Group>(config.path, config.encryption_key.data(), Group::mode_ReadOnly);
}
else {
if (config.encryption_key.data() && config.encryption_key.size() != 64) {
throw InvalidEncryptionKeyException();
}
history = realm::make_client_history(config.path, config.encryption_key.data());
SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly :
SharedGroup::durability_Full;

View File

@ -19,6 +19,8 @@
#ifndef REALM_REALM_HPP
#define REALM_REALM_HPP
#include "schema.hpp"
#include <realm/handover_defs.hpp>
#include <memory>
@ -26,6 +28,7 @@
#include <string>
#include <thread>
#include <vector>
#include <mutex>
namespace realm {
class BindingContext;
@ -33,7 +36,6 @@ namespace realm {
class Group;
class Realm;
class RealmDelegate;
class Schema;
class SharedGroup;
typedef std::shared_ptr<Realm> SharedRealm;
typedef std::weak_ptr<Realm> WeakRealm;
@ -229,6 +231,11 @@ namespace realm {
public:
UnitializedRealmException(std::string message) : std::runtime_error(message) {}
};
class InvalidEncryptionKeyException : public std::runtime_error {
public:
InvalidEncryptionKeyException() : std::runtime_error("Encryption key must be 64 bytes.") {}
};
}
#endif /* defined(REALM_REALM_HPP) */