Reformat list.{hpp,cpp} to match core style
This commit is contained in:
parent
5e71c4178e
commit
07c40b4517
33
src/list.cpp
33
src/list.cpp
|
@ -22,64 +22,75 @@
|
|||
|
||||
using namespace realm;
|
||||
|
||||
size_t List::size() {
|
||||
size_t List::size()
|
||||
{
|
||||
verify_attached();
|
||||
return m_link_view->size();
|
||||
}
|
||||
|
||||
Row List::get(std::size_t row_ndx) {
|
||||
Row List::get(std::size_t row_ndx)
|
||||
{
|
||||
verify_attached();
|
||||
verify_valid_row(row_ndx);
|
||||
return m_link_view->get(row_ndx);
|
||||
}
|
||||
|
||||
void List::set(std::size_t row_ndx, std::size_t target_row_ndx) {
|
||||
void List::set(std::size_t row_ndx, std::size_t target_row_ndx)
|
||||
{
|
||||
verify_attached();
|
||||
verify_in_tranaction();
|
||||
verify_valid_row(row_ndx);
|
||||
m_link_view->set(row_ndx, target_row_ndx);
|
||||
}
|
||||
|
||||
void List::add(std::size_t target_row_ndx) {
|
||||
void List::add(std::size_t target_row_ndx)
|
||||
{
|
||||
verify_attached();
|
||||
verify_in_tranaction();
|
||||
m_link_view->add(target_row_ndx);
|
||||
}
|
||||
|
||||
void List::insert(std::size_t row_ndx, std::size_t target_row_ndx) {
|
||||
void List::insert(std::size_t row_ndx, std::size_t target_row_ndx)
|
||||
{
|
||||
verify_attached();
|
||||
verify_in_tranaction();
|
||||
verify_valid_row(row_ndx, true);
|
||||
m_link_view->insert(row_ndx, target_row_ndx);
|
||||
}
|
||||
|
||||
void List::remove(std::size_t row_ndx) {
|
||||
void List::remove(std::size_t row_ndx)
|
||||
{
|
||||
verify_attached();
|
||||
verify_in_tranaction();
|
||||
verify_valid_row(row_ndx);
|
||||
m_link_view->remove(row_ndx);
|
||||
}
|
||||
|
||||
Query List::get_query() {
|
||||
Query List::get_query()
|
||||
{
|
||||
verify_attached();
|
||||
return m_link_view->get_target_table().where(m_link_view);
|
||||
}
|
||||
|
||||
void List::verify_valid_row(std::size_t row_ndx, bool insertion) {
|
||||
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("Index " + std::to_string(row_ndx) + " is outside of range 0..." +
|
||||
std::to_string(size) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
void List::verify_attached() {
|
||||
void List::verify_attached()
|
||||
{
|
||||
if (!m_link_view->is_attached()) {
|
||||
throw std::runtime_error("Tableview is not attached");
|
||||
}
|
||||
m_link_view->sync_if_needed();
|
||||
}
|
||||
|
||||
void List::verify_in_tranaction() {
|
||||
void List::verify_in_tranaction()
|
||||
{
|
||||
if (!m_realm->is_in_transaction()) {
|
||||
throw std::runtime_error("Can only mutate a list within a transaction.");
|
||||
}
|
||||
|
|
58
src/list.hpp
58
src/list.hpp
|
@ -23,41 +23,47 @@
|
|||
#include <realm/link_view.hpp>
|
||||
|
||||
namespace realm {
|
||||
class List {
|
||||
public:
|
||||
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {}
|
||||
class ObjectSchema;
|
||||
class List {
|
||||
public:
|
||||
List(SharedRealm& r, const ObjectSchema& s, LinkViewRef l)
|
||||
: m_realm(r)
|
||||
, m_object_schema(&s)
|
||||
, m_link_view(l)
|
||||
{
|
||||
}
|
||||
|
||||
const ObjectSchema &get_object_schema() const { return *m_object_schema; }
|
||||
SharedRealm realm() { return m_realm; }
|
||||
const ObjectSchema& get_object_schema() const { return *m_object_schema; }
|
||||
SharedRealm realm() { return m_realm; }
|
||||
|
||||
size_t size();
|
||||
Row get(std::size_t row_ndx);
|
||||
void set(std::size_t row_ndx, std::size_t target_row_ndx);
|
||||
size_t size();
|
||||
Row get(std::size_t row_ndx);
|
||||
void set(std::size_t row_ndx, std::size_t target_row_ndx);
|
||||
|
||||
void add(size_t target_row_ndx);
|
||||
void remove(size_t list_ndx);
|
||||
void insert(size_t list_ndx, size_t target_row_ndx);
|
||||
void add(size_t target_row_ndx);
|
||||
void remove(size_t list_ndx);
|
||||
void insert(size_t list_ndx, size_t target_row_ndx);
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
void add(ContextType ctx, ValueType value);
|
||||
template <typename ValueType, typename ContextType>
|
||||
void add(ContextType ctx, ValueType value);
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
void insert(ContextType ctx, ValueType value, size_t list_ndx);
|
||||
template <typename ValueType, typename ContextType>
|
||||
void insert(ContextType ctx, ValueType value, size_t list_ndx);
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
void set(ContextType ctx, ValueType value, size_t list_ndx);
|
||||
template <typename ValueType, typename ContextType>
|
||||
void set(ContextType ctx, ValueType value, size_t list_ndx);
|
||||
|
||||
Query get_query();
|
||||
Query get_query();
|
||||
|
||||
void verify_valid_row(std::size_t row_ndx, bool insertion = false);
|
||||
void verify_attached();
|
||||
void verify_in_tranaction();
|
||||
void verify_valid_row(std::size_t row_ndx, bool insertion = false);
|
||||
void verify_attached();
|
||||
void verify_in_tranaction();
|
||||
|
||||
private:
|
||||
SharedRealm m_realm;
|
||||
const ObjectSchema *m_object_schema;
|
||||
LinkViewRef m_link_view;
|
||||
};
|
||||
private:
|
||||
SharedRealm m_realm;
|
||||
const ObjectSchema* m_object_schema;
|
||||
LinkViewRef m_link_view;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* REALM_LIST_HPP */
|
||||
|
|
Loading…
Reference in New Issue