Kaydet (Commit) 3f204714 authored tarafından Noel Grandin's avatar Noel Grandin

use std::unique_ptr in FlatFndBox

and extend o3tl::make_unique to cope with arrays

Change-Id: I84caa46ab5060f9777bfe275f229499cb0b407be
Reviewed-on: https://gerrit.libreoffice.org/38794Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 8ae592a7
......@@ -12,6 +12,7 @@
#include <memory>
#include <utility>
#include <type_traits>
namespace o3tl
{
......@@ -27,6 +28,21 @@ typename std::unique_ptr<T> make_unique(Args&& ... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
/**
* for arrays
*/
template <class T>
typename std::enable_if
<
std::is_array<T>::value,
std::unique_ptr<T>
>::type
make_unique(std::size_t n)
{
typedef typename std::remove_extent<T>::type RT;
return std::unique_ptr<T>(new RT[n]);
}
}
#endif
......
......@@ -747,7 +747,6 @@ void MoveCell(SwDoc* pDoc, const SwTableBox* pSource, const SwTableBox* pTar,
FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
pDoc(pDocPtr),
rBoxRef(rBox),
pArr(nullptr),
nRow(0),
nCol(0)
{ // If the array is symmetric
......@@ -760,9 +759,8 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
// Create linear array
size_t nCount = static_cast<size_t>(nRows) * nCols;
pArr = new const FndBox_*[nCount];
FndBox_** ppTmp = const_cast<FndBox_**>(pArr);
memset(ppTmp, 0, sizeof(const FndBox_*) * nCount);
pArr = o3tl::make_unique<FndBox_ const *[]>(nCount);
memset(pArr.get(), 0, sizeof(const FndBox_*) * nCount);
FillFlat( rBoxRef );
}
......@@ -770,8 +768,6 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
FlatFndBox::~FlatFndBox()
{
FndBox_** ppTmp = const_cast<FndBox_**>(pArr);
delete [] ppTmp;
}
/// All Lines of a Box need to have same number of Boxes
......@@ -890,7 +886,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox)
{
// save it
sal_uInt16 nOff = nRow * nCols + nCol;
*(pArr + nOff) = pBox;
pArr[nOff] = pBox;
// Save the Formula/Format/Value values
const SwFrameFormat* pFormat = pBox->GetBox()->GetFrameFormat();
......@@ -931,7 +927,7 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox)
const FndBox_* FlatFndBox::GetBox(sal_uInt16 n_Col, sal_uInt16 n_Row) const
{
sal_uInt16 nOff = n_Row * nCols + n_Col;
const FndBox_* pTmp = *(pArr + nOff);
const FndBox_* pTmp = pArr[nOff];
OSL_ENSURE(n_Col < nCols && n_Row < nRows && pTmp, "invalid array access");
return pTmp;
......
......@@ -140,7 +140,7 @@ private:
SwDoc* pDoc;
const FndBox_& rBoxRef;
const FndBox_** pArr;
std::unique_ptr<FndBox_ const *[]> pArr;
std::vector<std::unique_ptr<SfxItemSet>> ppItemSets;
sal_uInt16 nRows;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment