summaryrefslogtreecommitdiff
path: root/editeng/inc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-01-15 11:57:08 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-01-15 14:28:11 +0100
commitbf6cf27763b88583b7562c41c791fff45308362d (patch)
tree219033e6965ee7d4e7ce7f15c15e37f97a57e01c /editeng/inc
parent6da480d086a599f6a0159c5244ce8fe0ae4131b8 (diff)
editeng: return ParaPortion from the list as a ref.
Change operator[] for getRef(..) method, so instead of returning a pointer, return a reference to ParaPortion instead. This also needs changes to the code, because we now need to make sure before hand that the ParaPortion is really available in the list and when this is not possible or convenient, the change the call to use existing "SafeGetObject" instead. Add "exists" to check if the object is available in the ParaPortionList. In addition add "lastIndex" method to return the index of the last ParaPortion in the list (shortcut for Count() - 1). Change-Id: Id52c38f996468af51c75d50185110ec8502169e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162071 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'editeng/inc')
-rw-r--r--editeng/inc/ParagraphPortionList.hxx23
1 files changed, 19 insertions, 4 deletions
diff --git a/editeng/inc/ParagraphPortionList.hxx b/editeng/inc/ParagraphPortionList.hxx
index aa7862afa8d7..7ee252132d4e 100644
--- a/editeng/inc/ParagraphPortionList.hxx
+++ b/editeng/inc/ParagraphPortionList.hxx
@@ -38,18 +38,33 @@ public:
tools::Long GetYOffset(const ParaPortion* pPPortion) const;
sal_Int32 FindParagraph(tools::Long nYOffset) const;
- const ParaPortion* SafeGetObject(sal_Int32 nPos) const;
- ParaPortion* SafeGetObject(sal_Int32 nPos);
+ const ParaPortion* SafeGetObject(sal_Int32 nPos) const
+ {
+ return exists(nPos) ? maPortions[nPos].get() : nullptr;
+ }
+
+ ParaPortion* SafeGetObject(sal_Int32 nPos)
+ {
+ return exists(nPos) ? maPortions[nPos].get() : nullptr;
+ }
sal_Int32 GetPos(const ParaPortion* p) const;
- ParaPortion* operator[](sal_Int32 nPos);
- const ParaPortion* operator[](sal_Int32 nPos) const;
+
+ ParaPortion& getRef(sal_Int32 nPosition) { return *maPortions[nPosition]; }
+ ParaPortion const& getRef(sal_Int32 nPosition) const { return *maPortions[nPosition]; }
std::unique_ptr<ParaPortion> Release(sal_Int32 nPos);
void Remove(sal_Int32 nPos);
void Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p);
void Append(std::unique_ptr<ParaPortion> p);
sal_Int32 Count() const;
+ sal_Int32 lastIndex() const { return Count() - 1; }
+
+ bool exists(sal_Int32 nPosition) const
+ {
+ return nPosition >= 0 && o3tl::make_unsigned(nPosition) < maPortions.size()
+ && maPortions[nPosition];
+ }
ParaPortionContainerType::iterator begin() { return maPortions.begin(); }
ParaPortionContainerType::iterator end() { return maPortions.end(); }