From 6276266d679173f2ad524a22343e275186fbf254 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 26 Jan 2016 14:43:49 -0800 Subject: [PATCH] Make List const-correct --- src/list.cpp | 14 +++++++------- src/list.hpp | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/list.cpp b/src/list.cpp index 08126704..593aac03 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -24,7 +24,7 @@ using namespace realm; -List::List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) +List::List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) noexcept : m_realm(std::move(r)) , m_object_schema(&s) , m_link_view(std::move(l)) @@ -33,13 +33,13 @@ List::List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) List::~List() = default; -size_t List::size() +size_t List::size() const { verify_attached(); return m_link_view->size(); } -Row List::get(size_t row_ndx) +Row List::get(size_t row_ndx) const { verify_attached(); verify_valid_row(row_ndx); @@ -77,13 +77,13 @@ void List::remove(size_t row_ndx) m_link_view->remove(row_ndx); } -Query List::get_query() +Query List::get_query() const { verify_attached(); return m_link_view->get_target_table().where(m_link_view); } -void List::verify_valid_row(size_t row_ndx, bool insertion) +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)) { @@ -92,7 +92,7 @@ void List::verify_valid_row(size_t row_ndx, bool insertion) } } -void List::verify_attached() +void List::verify_attached() const { if (!m_link_view->is_attached()) { throw std::runtime_error("LinkView is not attached"); @@ -100,7 +100,7 @@ void List::verify_attached() m_realm->verify_thread(); } -void List::verify_in_tranaction() +void List::verify_in_tranaction() const { if (!m_realm->is_in_transaction()) { throw std::runtime_error("Can only mutate a list within a transaction."); diff --git a/src/list.hpp b/src/list.hpp index 2c24482a..75d478b4 100644 --- a/src/list.hpp +++ b/src/list.hpp @@ -29,20 +29,24 @@ class Realm; class List { public: - List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l); + List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) noexcept; ~List(); const ObjectSchema& get_object_schema() const { return *m_object_schema; } - const std::shared_ptr& realm() { return m_realm; } + const std::shared_ptr& realm() const { return m_realm; } - size_t size(); - Row get(size_t row_ndx); + size_t size() const; + Row get(size_t row_ndx) const; void set(size_t row_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); + Query get_query() const; + void verify_in_tranaction() const; + + // These are implemented in object_accessor.hpp template void add(ContextType ctx, ValueType value); @@ -52,16 +56,13 @@ public: template void set(ContextType ctx, ValueType value, size_t list_ndx); - Query get_query(); - - void verify_valid_row(size_t row_ndx, bool insertion = false); - void verify_attached(); - void verify_in_tranaction(); - private: std::shared_ptr m_realm; const ObjectSchema* m_object_schema; LinkViewRef m_link_view; + + void verify_valid_row(size_t row_ndx, bool insertion = false) const; + void verify_attached() const; }; }