diff options
-rw-r--r-- | sc/inc/column.hxx | 1 | ||||
-rw-r--r-- | sc/inc/document.hxx | 1 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/datacache.cxx | 19 | ||||
-rw-r--r-- | sc/source/core/data/column4.cxx | 59 | ||||
-rw-r--r-- | sc/source/core/data/document10.cxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/table7.cxx | 10 |
7 files changed, 101 insertions, 0 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index d76f3f0bd992..db72912cbcb2 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -673,6 +673,7 @@ public: void EnsureFormulaCellResults( SCROW nRow1, SCROW nRow2 ); void StoreToCache(SvStream& rStrm) const; + void RestoreFromCache(SvStream& rStrm); #if DUMP_COLUMN_STORAGE void DumpColumnStorage() const; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index a32eac54bf1e..e832cc381099 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2305,6 +2305,7 @@ public: std::unique_ptr<sc::ColumnIterator> GetColumnIterator( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const; SC_DLLPUBLIC void StoreTabToCache(SCTAB nTab, SvStream& rStrm) const; + SC_DLLPUBLIC void RestoreTabFromCache(SCTAB nTab, SvStream& rStream); #if DUMP_COLUMN_STORAGE SC_DLLPUBLIC void DumpColumnStorage( SCTAB nTab, SCCOL nCol ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index a4d828c1f96a..94f45581c503 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -1010,6 +1010,8 @@ public: void StoreToCache(SvStream& rStrm) const; + void RestoreFromCache(SvStream& rStrm); + #if DUMP_COLUMN_STORAGE void DumpColumnStorage( SCCOL nCol ) const; #endif diff --git a/sc/qa/unit/datacache.cxx b/sc/qa/unit/datacache.cxx index 492e31c3fa3e..cdbd8db05e98 100644 --- a/sc/qa/unit/datacache.cxx +++ b/sc/qa/unit/datacache.cxx @@ -49,6 +49,15 @@ void ScCacheTest::testCacheSimple() SvMemoryStream aStrm; aDoc.StoreTabToCache(0, aStrm); + + aStrm.Seek(0); + + ScDocument aNewDoc; + aNewDoc.InsertTab(0, "test"); + aNewDoc.RestoreTabFromCache(0, aStrm); + + for (SCROW nRow = 0; nRow < 10; ++nRow) + ASSERT_DOUBLES_EQUAL(nRow, aNewDoc.GetValue(0, nRow, 0)); } void ScCacheTest::testCacheString() @@ -62,6 +71,16 @@ void ScCacheTest::testCacheString() SvMemoryStream aStrm; aDoc.StoreTabToCache(0, aStrm); + + aStrm.Seek(0); + + ScDocument aNewDoc; + aNewDoc.InsertTab(0, "test"); + aNewDoc.RestoreTabFromCache(0, aStrm); + + CPPUNIT_ASSERT_EQUAL(OUString("TestString"), aNewDoc.GetString(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("asjdaonfdssda"), aNewDoc.GetString(0, 1, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("da"), aNewDoc.GetString(0, 2, 0)); } CPPUNIT_TEST_SUITE_REGISTRATION(ScCacheTest); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index e7104a856d99..ee1324cf6651 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -1708,4 +1708,63 @@ void ScColumn::StoreToCache(SvStream& rStrm) const sc::ParseBlock(maCells.begin(), maCells, aFunc, (SCROW)0, nLastRow); } +void ScColumn::RestoreFromCache(SvStream& rStrm) +{ + sal_uInt64 nStoredCol = 0; + rStrm.ReadUInt64(nStoredCol); + if (nStoredCol != static_cast<sal_uInt64>(nCol)) + throw std::exception(); + + sal_uInt64 nLastRow = 0; + rStrm.ReadUInt64(nLastRow); + sal_uInt64 nReadRow = 0; + while (nReadRow < nLastRow) + { + sal_uInt64 nStartRow = 0; + sal_uInt64 nDataSize = 0; + rStrm.ReadUInt64(nStartRow); + rStrm.ReadUInt64(nDataSize); + sal_uInt8 nType = 0; + rStrm.ReadUChar(nType); + switch (nType) + { + case 0: + // nothing to do + maCells.set_empty(nStartRow, nDataSize); + break; + case 1: + { + // nDataSize double values + std::vector<double> aValues(nDataSize); + for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow) + { + rStrm.ReadDouble(aValues[nRow]); + } + maCells.set(nStartRow, aValues.begin(), aValues.end()); + } + break; + case 2: + { + std::vector<svl::SharedString> aStrings(nDataSize); + svl::SharedStringPool& rPool = pDocument->GetSharedStringPool(); + for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow) + { + sal_Int32 nStrLength = 0; + rStrm.ReadInt32(nStrLength); + std::unique_ptr<char[]> pStr(new char[nStrLength]); + rStrm.ReadBytes(pStr.get(), nStrLength); + OString aOStr(pStr.get(), nStrLength); + OUString aStr = OStringToOUString(aOStr, RTL_TEXTENCODING_UTF8); + aStrings[nRow] = rPool.intern(aStr); + } + maCells.set(nStartRow, aStrings.begin(), aStrings.end()); + + } + break; + } + + nReadRow += nDataSize; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index bd6f6e862cf5..1c7ffedb7b7e 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -948,4 +948,13 @@ void ScDocument::StoreTabToCache(SCTAB nTab, SvStream& rStrm) const pTab->StoreToCache(rStrm); } +void ScDocument::RestoreTabFromCache(SCTAB nTab, SvStream& rStrm) +{ + ScTable* pTab = FetchTable(nTab); + if (!pTab) + return; + + pTab->RestoreFromCache(rStrm); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index 340dc7476fae..2c9753b3bfcd 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -433,4 +433,14 @@ void ScTable::StoreToCache(SvStream& rStrm) const } } +void ScTable::RestoreFromCache(SvStream& rStrm) +{ + sal_uInt64 nCols = 0; + rStrm.ReadUInt64(nCols); + for (SCCOL nCol = 0; nCol < static_cast<SCCOL>(nCols); ++nCol) + { + aCol[nCol].RestoreFromCache(rStrm); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |