integrate new results class
This commit is contained in:
parent
e05ec4ea83
commit
c9405da94f
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "shared_realm.hpp"
|
#include "shared_realm.hpp"
|
||||||
|
#include "schema.hpp"
|
||||||
#include "list.hpp"
|
#include "list.hpp"
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
|
|
29
results.cpp
29
results.cpp
|
@ -20,19 +20,21 @@ using namespace realm;
|
||||||
#define REALM_FALLTHROUGH
|
#define REALM_FALLTHROUGH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Results::Results(SharedRealm r, Query q, SortOrder s)
|
Results::Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s)
|
||||||
: m_realm(std::move(r))
|
: m_realm(std::move(r))
|
||||||
, m_query(std::move(q))
|
, m_query(std::move(q))
|
||||||
, m_table(m_query.get_table().get())
|
, m_table(m_query.get_table().get())
|
||||||
, m_sort(std::move(s))
|
, m_sort(std::move(s))
|
||||||
, m_mode(Mode::Query)
|
, m_mode(Mode::Query)
|
||||||
|
, object_schema(o)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Results::Results(SharedRealm r, Table& table)
|
Results::Results(SharedRealm r, const ObjectSchema &o, Table& table)
|
||||||
: m_realm(std::move(r))
|
: m_realm(std::move(r))
|
||||||
, m_table(&table)
|
, m_table(&table)
|
||||||
, m_mode(Mode::Table)
|
, m_mode(Mode::Table)
|
||||||
|
, object_schema(o)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,9 +148,9 @@ size_t Results::index_of(Row const& row)
|
||||||
throw DetatchedAccessorException{};
|
throw DetatchedAccessorException{};
|
||||||
}
|
}
|
||||||
if (m_table && row.get_table() != m_table) {
|
if (m_table && row.get_table() != m_table) {
|
||||||
throw IncorrectTableException{
|
throw IncorrectTableException(object_schema.name,
|
||||||
ObjectStore::object_type_for_table_name(m_table->get_name()),
|
ObjectStore::object_type_for_table_name(row.get_table()->get_name()),
|
||||||
ObjectStore::object_type_for_table_name(row.get_table()->get_name())};
|
"Attempting to get the index of a Row of the wrong type");
|
||||||
}
|
}
|
||||||
return index_of(row.get_index());
|
return index_of(row.get_index());
|
||||||
}
|
}
|
||||||
|
@ -298,23 +300,18 @@ TableView Results::get_tableview()
|
||||||
REALM_UNREACHABLE();
|
REALM_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringData Results::get_object_type() const noexcept
|
|
||||||
{
|
|
||||||
return ObjectStore::object_type_for_table_name(m_table->get_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
Results Results::sort(realm::SortOrder&& sort) const
|
Results Results::sort(realm::SortOrder&& sort) const
|
||||||
{
|
{
|
||||||
return Results(m_realm, get_query(), std::move(sort));
|
return Results(m_realm, object_schema, get_query(), std::move(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
Results Results::filter(Query&& q) const
|
Results Results::filter(Query&& q) const
|
||||||
{
|
{
|
||||||
return Results(m_realm, get_query().and_query(std::move(q)), get_sort());
|
return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort());
|
||||||
}
|
}
|
||||||
|
|
||||||
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) {
|
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) :
|
||||||
column_index = column;
|
column_index(column), column_name(table->get_column_name(column)), column_type(table->get_column_type(column)),
|
||||||
column_name = table->get_column_name(column);
|
std::runtime_error((std::string)"Operation not supported on '" + table->get_column_name(column).data() + "' columns")
|
||||||
column_type = table->get_column_type(column);
|
{
|
||||||
}
|
}
|
||||||
|
|
41
results.hpp
41
results.hpp
|
@ -32,8 +32,8 @@ public:
|
||||||
// or a wrapper around a query and a sort order which creates and updates
|
// or a wrapper around a query and a sort order which creates and updates
|
||||||
// the tableview as needed
|
// the tableview as needed
|
||||||
Results() = default;
|
Results() = default;
|
||||||
Results(SharedRealm r, Table& table);
|
Results(SharedRealm r, const ObjectSchema &o, Table& table);
|
||||||
Results(SharedRealm r, Query q, SortOrder s = {});
|
Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s = {});
|
||||||
|
|
||||||
// Results is copyable and moveable
|
// Results is copyable and moveable
|
||||||
Results(Results const&) = default;
|
Results(Results const&) = default;
|
||||||
|
@ -41,6 +41,12 @@ public:
|
||||||
Results& operator=(Results const&) = default;
|
Results& operator=(Results const&) = default;
|
||||||
Results& operator=(Results&&) = default;
|
Results& operator=(Results&&) = default;
|
||||||
|
|
||||||
|
// Get the Realm
|
||||||
|
SharedRealm get_realm() const { return m_realm; }
|
||||||
|
|
||||||
|
// Object schema describing the vendored object type
|
||||||
|
ObjectSchema object_schema;
|
||||||
|
|
||||||
// Get a query which will match the same rows as is contained in this Results
|
// 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
|
// Returned query will not be valid if the current mode is Empty
|
||||||
Query get_query() const;
|
Query get_query() const;
|
||||||
|
@ -52,7 +58,7 @@ public:
|
||||||
TableView get_tableview();
|
TableView get_tableview();
|
||||||
|
|
||||||
// Get the object type which will be returned by get()
|
// Get the object type which will be returned by get()
|
||||||
StringData get_object_type() const noexcept;
|
StringData get_object_type() const noexcept { return object_schema.name; }
|
||||||
|
|
||||||
// Get the size of this results
|
// Get the size of this results
|
||||||
// Can be either O(1) or O(N) depending on the state of things
|
// Can be either O(1) or O(N) depending on the state of things
|
||||||
|
@ -104,25 +110,36 @@ public:
|
||||||
|
|
||||||
// The Results object has been invalidated (due to the Realm being invalidated)
|
// The Results object has been invalidated (due to the Realm being invalidated)
|
||||||
// All non-noexcept functions can throw this
|
// All non-noexcept functions can throw this
|
||||||
struct InvalidatedException {};
|
struct InvalidatedException : public std::runtime_error
|
||||||
|
{
|
||||||
|
InvalidatedException() : std::runtime_error("Access to invalidated Results objects") {}
|
||||||
|
};
|
||||||
|
|
||||||
// The input index parameter was out of bounds
|
// The input index parameter was out of bounds
|
||||||
struct OutOfBoundsIndexException {
|
struct OutOfBoundsIndexException : public std::out_of_range
|
||||||
size_t requested;
|
{
|
||||||
size_t valid_count;
|
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)) {}
|
||||||
|
const size_t requested;
|
||||||
|
const size_t valid_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The input Row object is not attached
|
// The input Row object is not attached
|
||||||
struct DetatchedAccessorException { };
|
struct DetatchedAccessorException : public std::runtime_error {
|
||||||
|
DetatchedAccessorException() : std::runtime_error("Atempting to access an invalid object") {}
|
||||||
|
};
|
||||||
|
|
||||||
// The input Row object belongs to a different table
|
// The input Row object belongs to a different table
|
||||||
struct IncorrectTableException {
|
struct IncorrectTableException : public std::runtime_error {
|
||||||
StringData expected;
|
IncorrectTableException(StringData e, StringData a, const std::string &error) :
|
||||||
StringData actual;
|
expected(e), actual(a), std::runtime_error(error) {}
|
||||||
|
const StringData expected;
|
||||||
|
const StringData actual;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The requested aggregate operation is not supported for the column type
|
// The requested aggregate operation is not supported for the column type
|
||||||
struct UnsupportedColumnTypeException {
|
struct UnsupportedColumnTypeException : public std::runtime_error {
|
||||||
size_t column_index;
|
size_t column_index;
|
||||||
StringData column_name;
|
StringData column_name;
|
||||||
DataType column_type;
|
DataType column_type;
|
||||||
|
|
|
@ -105,10 +105,6 @@ namespace realm {
|
||||||
// Realm after closing it will produce undefined behavior.
|
// Realm after closing it will produce undefined behavior.
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
// Close this Realm and remove it from the cache. Continuing to use a
|
|
||||||
// Realm after closing it will produce undefined behavior.
|
|
||||||
void close();
|
|
||||||
|
|
||||||
~Realm();
|
~Realm();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue