summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/inc/dbcolect.hxx42
-rw-r--r--sc/source/core/tool/dbcolect.cxx137
-rw-r--r--sc/source/filter/xml/XMLExportDatabaseRanges.cxx4
-rw-r--r--sc/source/filter/xml/xmldrani.cxx2
-rw-r--r--sc/source/ui/docshell/docsh5.cxx2
-rw-r--r--sc/source/ui/unoobj/datauno.cxx3
6 files changed, 129 insertions, 61 deletions
diff --git a/sc/inc/dbcolect.hxx b/sc/inc/dbcolect.hxx
index c766793a5..280c59e77 100644
--- a/sc/inc/dbcolect.hxx
+++ b/sc/inc/dbcolect.hxx
@@ -161,8 +161,9 @@ public:
class SC_DLLPUBLIC ScDBCollection
{
public:
- typedef ::boost::ptr_vector<ScDBData> AnonDBsType;
-
+ /**
+ * Stores global named database ranges.
+ */
class NamedDBs
{
friend class ScDBCollection;
@@ -191,12 +192,37 @@ public:
bool operator== (const NamedDBs& r) const;
};
+ /**
+ * Stores global anonymous database ranges.
+ */
+ class AnonDBs
+ {
+ typedef ::boost::ptr_vector<ScDBData> DBsType;
+ DBsType maDBs;
+ public:
+ typedef DBsType::iterator iterator;
+ typedef DBsType::const_iterator const_iterator;
+
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+ const ScDBData* findAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) const;
+ const ScDBData* findByRange(const ScRange& rRange) const;
+ ScDBData* getByRange(const ScRange& rRange);
+ void insert(ScDBData* p);
+ void erase(iterator itr);
+ bool empty() const;
+ size_t size() const;
+ bool operator== (const AnonDBs& r) const;
+ };
+
private:
Link aRefreshHandler;
ScDocument* pDoc;
sal_uInt16 nEntryIndex; // counter for unique indices
NamedDBs maNamedDBs;
- AnonDBsType maAnonDBs;
+ AnonDBs maAnonDBs;
public:
ScDBCollection(ScDocument* pDocument);
@@ -205,6 +231,9 @@ public:
NamedDBs& getNamedDBs();
const NamedDBs& getNamedDBs() const;
+ AnonDBs& getAnonDBs();
+ const AnonDBs& getAnonDBs() const;
+
const ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly);
const ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
@@ -226,13 +255,6 @@ public:
{ aRefreshHandler = rLink; }
const Link& GetRefreshHandler() const { return aRefreshHandler; }
- const ScDBData* findAnonAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) const;
- const ScDBData* findAnonByRange(const ScRange& rRange) const;
- ScDBData* getAnonByRange(const ScRange& rRange);
- void insertAnonRange(ScDBData* pData);
-
- const AnonDBsType& getAnonRanges() const;
-
bool empty() const;
bool operator== (const ScDBCollection& r) const;
};
diff --git a/sc/source/core/tool/dbcolect.cxx b/sc/source/core/tool/dbcolect.cxx
index 64e055c5e..135a88fe4 100644
--- a/sc/source/core/tool/dbcolect.cxx
+++ b/sc/source/core/tool/dbcolect.cxx
@@ -744,6 +744,83 @@ bool ScDBCollection::NamedDBs::operator== (const NamedDBs& r) const
return maDBs == r.maDBs;
}
+ScDBCollection::AnonDBs::iterator ScDBCollection::AnonDBs::begin()
+{
+ return maDBs.begin();
+}
+
+ScDBCollection::AnonDBs::iterator ScDBCollection::AnonDBs::end()
+{
+ return maDBs.end();
+}
+
+ScDBCollection::AnonDBs::const_iterator ScDBCollection::AnonDBs::begin() const
+{
+ return maDBs.begin();
+}
+
+ScDBCollection::AnonDBs::const_iterator ScDBCollection::AnonDBs::end() const
+{
+ return maDBs.end();
+}
+
+const ScDBData* ScDBCollection::AnonDBs::findAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) const
+{
+ DBsType::const_iterator itr = find_if(
+ maDBs.begin(), maDBs.end(), FindByCursor(nCol, nRow, nTab, bStartOnly));
+ return itr == maDBs.end() ? NULL : &(*itr);
+}
+
+const ScDBData* ScDBCollection::AnonDBs::findByRange(const ScRange& rRange) const
+{
+ DBsType::const_iterator itr = find_if(
+ maDBs.begin(), maDBs.end(), FindByRange(rRange));
+ return itr == maDBs.end() ? NULL : &(*itr);
+}
+
+ScDBData* ScDBCollection::AnonDBs::getByRange(const ScRange& rRange)
+{
+ const ScDBData* pData = findByRange(rRange);
+ if (!pData)
+ {
+ // Insert a new db data. They all have identical names.
+ rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME));
+ ::std::auto_ptr<ScDBData> pNew(new ScDBData(
+ aName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(),
+ rRange.aEnd.Col(), rRange.aEnd.Row(), true, false));
+ pData = pNew.get();
+ maDBs.push_back(pNew);
+ }
+ return const_cast<ScDBData*>(pData);
+}
+
+void ScDBCollection::AnonDBs::insert(ScDBData* p)
+{
+ rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME));
+ ::std::auto_ptr<ScDBData> pNew(p);
+ maDBs.push_back(pNew);
+}
+
+void ScDBCollection::AnonDBs::erase(iterator itr)
+{
+ maDBs.erase(itr);
+}
+
+bool ScDBCollection::AnonDBs::empty() const
+{
+ return maDBs.empty();
+}
+
+size_t ScDBCollection::AnonDBs::size() const
+{
+ return maDBs.size();
+}
+
+bool ScDBCollection::AnonDBs::operator== (const AnonDBs& r) const
+{
+ return maDBs == r.maDBs;
+}
+
ScDBCollection::ScDBCollection(ScDocument* pDocument) :
pDoc(pDocument), nEntryIndex(SC_START_INDEX_DB_COLL), maNamedDBs(*this, *pDocument) {}
@@ -760,6 +837,16 @@ const ScDBCollection::NamedDBs& ScDBCollection::getNamedDBs() const
return maNamedDBs;
}
+ScDBCollection::AnonDBs& ScDBCollection::getAnonDBs()
+{
+ return maAnonDBs;
+}
+
+const ScDBCollection::AnonDBs& ScDBCollection::getAnonDBs() const
+{
+ return maAnonDBs;
+}
+
const ScDBData* ScDBCollection::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const
{
// First, search the global named db ranges.
@@ -775,7 +862,7 @@ const ScDBData* ScDBCollection::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab
return pNoNameData;
// Check the global anonymous db ranges.
- const ScDBData* pData = findAnonAtCursor(nCol, nRow, nTab, bStartOnly);
+ const ScDBData* pData = getAnonDBs().findAtCursor(nCol, nRow, nTab, bStartOnly);
if (pData)
return pData;
@@ -797,7 +884,7 @@ ScDBData* ScDBCollection::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_
return pNoNameData;
// Check the global anonymous db ranges.
- const ScDBData* pData = findAnonAtCursor(nCol, nRow, nTab, bStartOnly);
+ const ScDBData* pData = getAnonDBs().findAtCursor(nCol, nRow, nTab, bStartOnly);
if (pData)
return const_cast<ScDBData*>(pData);
@@ -820,7 +907,7 @@ const ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1
return pNoNameData;
// Lastly, check the global anonymous db ranges.
- return findAnonByRange(aRange);
+ return maAnonDBs.findByRange(aRange);
}
ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
@@ -839,7 +926,7 @@ ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCO
return pNoNameData;
// Lastly, check the global anonymous db ranges.
- const ScDBData* pData = findAnonByRange(aRange);
+ const ScDBData* pData = getAnonDBs().findByRange(aRange);
if (pData)
return const_cast<ScDBData*>(pData);
@@ -936,48 +1023,6 @@ ScDBData* ScDBCollection::GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab )
return pDoc->GetAnonymousDBData(nTab); // "unbenannt" nur zurueck, wenn sonst nichts gefunden
}
-const ScDBData* ScDBCollection::findAnonAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) const
-{
- AnonDBsType::const_iterator itr = find_if(
- maAnonDBs.begin(), maAnonDBs.end(), FindByCursor(nCol, nRow, nTab, bStartOnly));
- return itr == maAnonDBs.end() ? NULL : &(*itr);
-}
-
-const ScDBData* ScDBCollection::findAnonByRange(const ScRange& rRange) const
-{
- AnonDBsType::const_iterator itr = find_if(
- maAnonDBs.begin(), maAnonDBs.end(), FindByRange(rRange));
- return itr == maAnonDBs.end() ? NULL : &(*itr);
-}
-
-ScDBData* ScDBCollection::getAnonByRange(const ScRange& rRange)
-{
- const ScDBData* pData = findAnonByRange(rRange);
- if (!pData)
- {
- // Insert a new db data. They all have identical names.
- rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME));
- ::std::auto_ptr<ScDBData> pNew(new ScDBData(
- aName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(),
- rRange.aEnd.Col(), rRange.aEnd.Row(), true, false));
- pData = pNew.get();
- maAnonDBs.push_back(pNew);
- }
- return const_cast<ScDBData*>(pData);
-}
-
-void ScDBCollection::insertAnonRange(ScDBData* pData)
-{
- rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME));
- ::std::auto_ptr<ScDBData> pNew(pData);
- maAnonDBs.push_back(pNew);
-}
-
-const ScDBCollection::AnonDBsType& ScDBCollection::getAnonRanges() const
-{
- return maAnonDBs;
-}
-
bool ScDBCollection::empty() const
{
return maNamedDBs.empty() && maAnonDBs.empty();
diff --git a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
index 7d3608fcc..25fa489a7 100644
--- a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
+++ b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
@@ -1108,7 +1108,7 @@ void ScXMLExportDatabaseRanges::WriteDatabaseRanges()
ScDBCollection* pDBCollection = pDoc->GetDBCollection();
if (pDBCollection)
{
- if (!pDBCollection->getNamedDBs().empty() || !pDBCollection->getAnonRanges().empty())
+ if (!pDBCollection->getNamedDBs().empty() || !pDBCollection->getAnonDBs().empty())
bHasRanges = true;
}
@@ -1127,7 +1127,7 @@ void ScXMLExportDatabaseRanges::WriteDatabaseRanges()
::std::for_each(rNamedDBs.begin(), rNamedDBs.end(), func);
// Add global anonymous DB ranges.
- const ScDBCollection::AnonDBsType& rAnonDBs = pDBCollection->getAnonRanges();
+ const ScDBCollection::AnonDBs& rAnonDBs = pDBCollection->getAnonDBs();
::std::for_each(rAnonDBs.begin(), rAnonDBs.end(), func);
}
diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx
index 741032c14..b9cea6aad 100644
--- a/sc/source/filter/xml/xmldrani.cxx
+++ b/sc/source/filter/xml/xmldrani.cxx
@@ -499,7 +499,7 @@ void ScXMLDatabaseRangeContext::EndElement()
if (pData.get())
{
setAutoFilterFlags(*pDoc, *pData);
- pDoc->GetDBCollection()->insertAnonRange(pData.release());
+ pDoc->GetDBCollection()->getAnonDBs().insert(pData.release());
}
return;
}
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 7d1c26103..46da7863e 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -340,7 +340,7 @@ ScDBData* ScDocShell::GetAnonymousDBData(const ScRange& rRange)
if (!pColl)
return NULL;
- ScDBData* pData = pColl->getAnonByRange(rRange);
+ ScDBData* pData = pColl->getAnonDBs().getByRange(rRange);
if (!pData)
return NULL;
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index 59ede6d81..8da9833ec 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -2295,7 +2295,8 @@ uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex )
lang::WrappedTargetException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
- if (nIndex < 0 || nIndex > ::std::numeric_limits<size_t>::max())
+ sal_Int32 nUpper = ::std::numeric_limits<size_t>::max();
+ if (nIndex < 0 || nIndex > nUpper)
throw lang::IndexOutOfBoundsException();
uno::Reference<sheet::XDatabaseRange> xRange(GetObjectByIndex_Impl(static_cast<size_t>(nIndex)));