Reformat list.{hpp,cpp} to match core style

This commit is contained in:
Thomas Goyne 2016-01-26 12:00:36 -08:00
parent 5e71c4178e
commit 07c40b4517
2 changed files with 54 additions and 37 deletions

View File

@ -22,64 +22,75 @@
using namespace realm; using namespace realm;
size_t List::size() { size_t List::size()
{
verify_attached(); verify_attached();
return m_link_view->size(); return m_link_view->size();
} }
Row List::get(std::size_t row_ndx) { Row List::get(std::size_t row_ndx)
{
verify_attached(); verify_attached();
verify_valid_row(row_ndx); verify_valid_row(row_ndx);
return m_link_view->get(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_attached();
verify_in_tranaction(); verify_in_tranaction();
verify_valid_row(row_ndx); verify_valid_row(row_ndx);
m_link_view->set(row_ndx, target_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_attached();
verify_in_tranaction(); verify_in_tranaction();
m_link_view->add(target_row_ndx); 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_attached();
verify_in_tranaction(); verify_in_tranaction();
verify_valid_row(row_ndx, true); verify_valid_row(row_ndx, true);
m_link_view->insert(row_ndx, target_row_ndx); 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_attached();
verify_in_tranaction(); verify_in_tranaction();
verify_valid_row(row_ndx); verify_valid_row(row_ndx);
m_link_view->remove(row_ndx); m_link_view->remove(row_ndx);
} }
Query List::get_query() { Query List::get_query()
{
verify_attached(); verify_attached();
return m_link_view->get_target_table().where(m_link_view); 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(); size_t size = m_link_view->size();
if (row_ndx > size || (!insertion && row_ndx == 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()) { if (!m_link_view->is_attached()) {
throw std::runtime_error("Tableview is not attached"); throw std::runtime_error("Tableview is not attached");
} }
m_link_view->sync_if_needed(); m_link_view->sync_if_needed();
} }
void List::verify_in_tranaction() { void List::verify_in_tranaction()
{
if (!m_realm->is_in_transaction()) { if (!m_realm->is_in_transaction()) {
throw std::runtime_error("Can only mutate a list within a transaction."); throw std::runtime_error("Can only mutate a list within a transaction.");
} }

View File

@ -23,9 +23,15 @@
#include <realm/link_view.hpp> #include <realm/link_view.hpp>
namespace realm { namespace realm {
class ObjectSchema;
class List { class List {
public: public:
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {} 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; } const ObjectSchema& get_object_schema() const { return *m_object_schema; }
SharedRealm realm() { return m_realm; } SharedRealm realm() { return m_realm; }