1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lookupcache.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "lookupcache.hxx"
35 #include "document.hxx"
40 static long nCacheCount
= 0;
44 ScLookupCache::ScLookupCache( ScDocument
* pDoc
, const ScRange
& rRange
) :
50 fprintf( stderr
, "\nctor ScLookupCache %ld: %d, %d, %d, %d, %d, %d; buckets: %lu, size: %lu\n",
52 (int)getRange().aStart
.Col(), (int)getRange().aStart
.Row(),
53 (int)getRange().aStart
.Tab(), (int)getRange().aEnd
.Col(),
54 (int)getRange().aEnd
.Row(), (int)getRange().aEnd
.Tab(),
55 (unsigned long)maQueryMap
.bucket_count(), (unsigned long)maQueryMap
.size());
60 ScLookupCache::~ScLookupCache()
63 fprintf( stderr
, "\ndtor ScLookupCache %ld: %d, %d, %d, %d, %d, %d; buckets: %lu, size: %lu\n",
65 (int)getRange().aStart
.Col(), (int)getRange().aStart
.Row(),
66 (int)getRange().aStart
.Tab(), (int)getRange().aEnd
.Col(),
67 (int)getRange().aEnd
.Row(), (int)getRange().aEnd
.Tab(),
68 (unsigned long)maQueryMap
.bucket_count(), (unsigned long)maQueryMap
.size());
74 ScLookupCache::Result
ScLookupCache::lookup( ScAddress
& o_rResultAddress
,
75 const QueryCriteria
& rCriteria
, const ScAddress
& rQueryAddress
) const
77 QueryMap::const_iterator
it( maQueryMap
.find( QueryKey( rQueryAddress
,
78 rCriteria
.getQueryOp())));
79 if (it
== maQueryMap
.end())
81 const QueryCriteriaAndResult
& rResult
= (*it
).second
;
82 if (!(rResult
.maCriteria
== rCriteria
))
83 return CRITERIA_DIFFERENT
;
84 if (rResult
.maAddress
.Row() < 0 )
86 o_rResultAddress
= rResult
.maAddress
;
91 bool ScLookupCache::insert( const ScAddress
& rResultAddress
,
92 const QueryCriteria
& rCriteria
, const ScAddress
& rQueryAddress
,
93 const bool bAvailable
)
96 size_t nBuckets
= maQueryMap
.bucket_count();
98 QueryKey
aKey( rQueryAddress
, rCriteria
.getQueryOp());
99 QueryCriteriaAndResult
aResult( rCriteria
, rResultAddress
);
101 aResult
.maAddress
.SetRow(-1);
102 bool bInserted
= maQueryMap
.insert( ::std::pair
< const QueryKey
,
103 QueryCriteriaAndResult
>( aKey
, aResult
)).second
;
105 if (nBuckets
!= maQueryMap
.bucket_count())
107 fprintf( stderr
, "\nbuck ScLookupCache: %d, %d, %d, %d, %d, %d; buckets: %lu, size: %lu\n",
108 (int)getRange().aStart
.Col(), (int)getRange().aStart
.Row(),
109 (int)getRange().aStart
.Tab(), (int)getRange().aEnd
.Col(),
110 (int)getRange().aEnd
.Row(), (int)getRange().aEnd
.Tab(),
111 (unsigned long)maQueryMap
.bucket_count(), (unsigned long)maQueryMap
.size());
118 void ScLookupCache::Notify( SvtBroadcaster
& /* rBC */ , const SfxHint
& rHint
)
120 if (!mpDoc
->IsInDtorClear())
122 const ScHint
* p
= PTR_CAST( ScHint
, &rHint
);
123 if (p
&& (p
->GetId() & (SC_HINT_DATACHANGED
| SC_HINT_DYING
)))
125 mpDoc
->RemoveLookupCache( *this);