Kaydet (Commit) af4aaa22 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Let's not derive from std::vector.

Change-Id: I512d97d36c344df097cc5a1ac90aa9d3d219c1e9
üst 9c451090
...@@ -195,9 +195,11 @@ SdrLinkList& ImpGetUserMakeObjUserDataHdl(); ...@@ -195,9 +195,11 @@ SdrLinkList& ImpGetUserMakeObjUserDataHdl();
class SdrOle2Obj; class SdrOle2Obj;
class AutoTimer; class AutoTimer;
class OLEObjCache : public std::vector<SdrOle2Obj*> class OLEObjCache
{ {
sal_uIntPtr nSize; std::vector<SdrOle2Obj*> maObjs;
size_t nSize;
AutoTimer* pTimer; AutoTimer* pTimer;
void UnloadOnDemand(); void UnloadOnDemand();
...@@ -210,6 +212,10 @@ public: ...@@ -210,6 +212,10 @@ public:
void InsertObj(SdrOle2Obj* pObj); void InsertObj(SdrOle2Obj* pObj);
void RemoveObj(SdrOle2Obj* pObj); void RemoveObj(SdrOle2Obj* pObj);
size_t size() const;
SdrOle2Obj* operator[](size_t nPos);
const SdrOle2Obj* operator[](size_t nPos) const;
}; };
......
...@@ -95,7 +95,6 @@ const LocaleDataWrapper* SdrGlobalData::GetLocaleData() ...@@ -95,7 +95,6 @@ const LocaleDataWrapper* SdrGlobalData::GetLocaleData()
OLEObjCache::OLEObjCache() OLEObjCache::OLEObjCache()
: std::vector<SdrOle2Obj*>()
{ {
nSize = officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::get(); nSize = officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::get();
pTimer = new AutoTimer(); pTimer = new AutoTimer();
...@@ -116,15 +115,15 @@ OLEObjCache::~OLEObjCache() ...@@ -116,15 +115,15 @@ OLEObjCache::~OLEObjCache()
void OLEObjCache::UnloadOnDemand() void OLEObjCache::UnloadOnDemand()
{ {
if ( nSize < size() ) if (nSize < maObjs.size())
{ {
// more objects than configured cache size try to remove objects // more objects than configured cache size try to remove objects
// of course not the freshly inserted one at nIndex=0 // of course not the freshly inserted one at nIndex=0
sal_uIntPtr nCount2 = size(); size_t nCount2 = maObjs.size();
sal_uIntPtr nIndex = nCount2-1; size_t nIndex = nCount2-1;
while( nIndex && nCount2 > nSize ) while( nIndex && nCount2 > nSize )
{ {
SdrOle2Obj* pUnloadObj = (*this)[nIndex--]; SdrOle2Obj* pUnloadObj = maObjs[nIndex--];
if ( pUnloadObj ) if ( pUnloadObj )
{ {
try try
...@@ -140,9 +139,9 @@ void OLEObjCache::UnloadOnDemand() ...@@ -140,9 +139,9 @@ void OLEObjCache::UnloadOnDemand()
uno::Reference< frame::XModel > xUnloadModel( xUnloadObj->getComponent(), uno::UNO_QUERY ); uno::Reference< frame::XModel > xUnloadModel( xUnloadObj->getComponent(), uno::UNO_QUERY );
if ( xUnloadModel.is() ) if ( xUnloadModel.is() )
{ {
for ( sal_uIntPtr nCheckInd = 0; nCheckInd < size(); nCheckInd++ ) for (size_t nCheckInd = 0; nCheckInd < maObjs.size(); nCheckInd++)
{ {
SdrOle2Obj* pCacheObj = (*this)[nCheckInd]; SdrOle2Obj* pCacheObj = maObjs[nCheckInd];
if ( pCacheObj && pCacheObj != pUnloadObj ) if ( pCacheObj && pCacheObj != pUnloadObj )
{ {
uno::Reference< frame::XModel > xParentModel = pCacheObj->GetParentXModel(); uno::Reference< frame::XModel > xParentModel = pCacheObj->GetParentXModel();
...@@ -166,22 +165,22 @@ void OLEObjCache::UnloadOnDemand() ...@@ -166,22 +165,22 @@ void OLEObjCache::UnloadOnDemand()
void OLEObjCache::InsertObj(SdrOle2Obj* pObj) void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
{ {
if ( !empty() ) if (!maObjs.empty())
{ {
SdrOle2Obj* pExistingObj = front(); SdrOle2Obj* pExistingObj = maObjs.front();
if ( pObj == pExistingObj ) if ( pObj == pExistingObj )
// the object is already on the top, nothing has to be changed // the object is already on the top, nothing has to be changed
return; return;
} }
// get the old position of the object to know whether it is already in container // get the old position of the object to know whether it is already in container
iterator it = std::find( begin(), end(), pObj ); std::vector<SdrOle2Obj*>::iterator it = std::find(maObjs.begin(), maObjs.end(), pObj);
bool bFound = it != end(); bool bFound = it != maObjs.end();
if( it != end() ) if (bFound)
erase( it ); maObjs.erase(it);
// insert object into first position // insert object into first position
insert(begin(), pObj); maObjs.insert(maObjs.begin(), pObj);
if ( !bFound ) if ( !bFound )
{ {
...@@ -192,9 +191,24 @@ void OLEObjCache::InsertObj(SdrOle2Obj* pObj) ...@@ -192,9 +191,24 @@ void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
void OLEObjCache::RemoveObj(SdrOle2Obj* pObj) void OLEObjCache::RemoveObj(SdrOle2Obj* pObj)
{ {
iterator it = std::find( begin(), end(), pObj ); std::vector<SdrOle2Obj*>::iterator it = std::find(maObjs.begin(), maObjs.end(), pObj);
if( it != end() ) if (it != maObjs.end())
erase( it ); maObjs.erase(it);
}
size_t OLEObjCache::size() const
{
return maObjs.size();
}
SdrOle2Obj* OLEObjCache::operator[](size_t nPos)
{
return maObjs[nPos];
}
const SdrOle2Obj* OLEObjCache::operator[](size_t nPos) const
{
return maObjs[nPos];
} }
bool OLEObjCache::UnloadObj(SdrOle2Obj* pObj) bool OLEObjCache::UnloadObj(SdrOle2Obj* pObj)
......
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