Make List const-correct
This commit is contained in:
parent
1cbbf1958f
commit
6276266d67
14
src/list.cpp
14
src/list.cpp
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
using namespace realm;
|
using namespace realm;
|
||||||
|
|
||||||
List::List(std::shared_ptr<Realm> r, const ObjectSchema& s, LinkViewRef l)
|
List::List(std::shared_ptr<Realm> r, const ObjectSchema& s, LinkViewRef l) noexcept
|
||||||
: m_realm(std::move(r))
|
: m_realm(std::move(r))
|
||||||
, m_object_schema(&s)
|
, m_object_schema(&s)
|
||||||
, m_link_view(std::move(l))
|
, m_link_view(std::move(l))
|
||||||
|
@ -33,13 +33,13 @@ List::List(std::shared_ptr<Realm> r, const ObjectSchema& s, LinkViewRef l)
|
||||||
|
|
||||||
List::~List() = default;
|
List::~List() = default;
|
||||||
|
|
||||||
size_t List::size()
|
size_t List::size() const
|
||||||
{
|
{
|
||||||
verify_attached();
|
verify_attached();
|
||||||
return m_link_view->size();
|
return m_link_view->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Row List::get(size_t row_ndx)
|
Row List::get(size_t row_ndx) const
|
||||||
{
|
{
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_valid_row(row_ndx);
|
verify_valid_row(row_ndx);
|
||||||
|
@ -77,13 +77,13 @@ void List::remove(size_t row_ndx)
|
||||||
m_link_view->remove(row_ndx);
|
m_link_view->remove(row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query List::get_query()
|
Query List::get_query() const
|
||||||
{
|
{
|
||||||
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(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();
|
size_t size = m_link_view->size();
|
||||||
if (row_ndx > size || (!insertion && row_ndx == 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()) {
|
if (!m_link_view->is_attached()) {
|
||||||
throw std::runtime_error("LinkView is not attached");
|
throw std::runtime_error("LinkView is not attached");
|
||||||
|
@ -100,7 +100,7 @@ void List::verify_attached()
|
||||||
m_realm->verify_thread();
|
m_realm->verify_thread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::verify_in_tranaction()
|
void List::verify_in_tranaction() const
|
||||||
{
|
{
|
||||||
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.");
|
||||||
|
|
21
src/list.hpp
21
src/list.hpp
|
@ -29,20 +29,24 @@ class Realm;
|
||||||
|
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
List(std::shared_ptr<Realm> r, const ObjectSchema& s, LinkViewRef l);
|
List(std::shared_ptr<Realm> r, const ObjectSchema& s, LinkViewRef l) noexcept;
|
||||||
~List();
|
~List();
|
||||||
|
|
||||||
const ObjectSchema& get_object_schema() const { return *m_object_schema; }
|
const ObjectSchema& get_object_schema() const { return *m_object_schema; }
|
||||||
const std::shared_ptr<Realm>& realm() { return m_realm; }
|
const std::shared_ptr<Realm>& realm() const { return m_realm; }
|
||||||
|
|
||||||
size_t size();
|
size_t size() const;
|
||||||
Row get(size_t row_ndx);
|
Row get(size_t row_ndx) const;
|
||||||
void set(size_t row_ndx, size_t target_row_ndx);
|
void set(size_t row_ndx, size_t target_row_ndx);
|
||||||
|
|
||||||
void add(size_t target_row_ndx);
|
void add(size_t target_row_ndx);
|
||||||
void remove(size_t list_ndx);
|
void remove(size_t list_ndx);
|
||||||
void insert(size_t list_ndx, size_t target_row_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 <typename ValueType, typename ContextType>
|
template <typename ValueType, typename ContextType>
|
||||||
void add(ContextType ctx, ValueType value);
|
void add(ContextType ctx, ValueType value);
|
||||||
|
|
||||||
|
@ -52,16 +56,13 @@ public:
|
||||||
template <typename ValueType, typename ContextType>
|
template <typename ValueType, typename ContextType>
|
||||||
void set(ContextType ctx, ValueType value, size_t list_ndx);
|
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:
|
private:
|
||||||
std::shared_ptr<Realm> m_realm;
|
std::shared_ptr<Realm> m_realm;
|
||||||
const ObjectSchema* m_object_schema;
|
const ObjectSchema* m_object_schema;
|
||||||
LinkViewRef m_link_view;
|
LinkViewRef m_link_view;
|
||||||
|
|
||||||
|
void verify_valid_row(size_t row_ndx, bool insertion = false) const;
|
||||||
|
void verify_attached() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue