Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "lookupcache.hxx"
31 : : #include "document.hxx"
32 : : #include "queryentry.hxx"
33 : :
34 : 144 : ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry& rEntry ) :
35 : 144 : mfVal(0.0), mbAlloc(false), mbString(false)
36 : : {
37 [ - + + - ]: 144 : switch (rEntry.eOp)
38 : : {
39 : : case SC_EQUAL :
40 : 0 : meOp = EQUAL;
41 : 0 : break;
42 : : case SC_LESS_EQUAL :
43 : 96 : meOp = LESS_EQUAL;
44 : 96 : break;
45 : : case SC_GREATER_EQUAL :
46 : 48 : meOp = GREATER_EQUAL;
47 : 48 : break;
48 : : default:
49 : 0 : meOp = UNKNOWN;
50 : : SAL_WARN( "sc.core", "ScLookupCache::QueryCriteria not prepared for this ScQueryOp");
51 : : }
52 : :
53 : 144 : const ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
54 [ + + ]: 144 : if (rItem.meType == ScQueryEntry::ByString)
55 [ + - ]: 45 : setString(rItem.maString);
56 : : else
57 : 99 : setDouble(rItem.mfVal);
58 : 144 : }
59 : :
60 : 432 : ScLookupCache::QueryCriteria::QueryCriteria( const ScLookupCache::QueryCriteria & r ) :
61 : : mfVal( r.mfVal),
62 : : mbAlloc( false),
63 : : mbString( false),
64 : 432 : meOp( r.meOp)
65 : : {
66 [ + + ][ + - ]: 432 : if (r.mbString && r.mpStr)
67 : : {
68 [ + - ]: 135 : mpStr = new String( *r.mpStr);
69 : 135 : mbAlloc = mbString = true;
70 : : }
71 : 432 : }
72 : :
73 : 576 : ScLookupCache::QueryCriteria::~QueryCriteria()
74 : : {
75 : 576 : deleteString();
76 : 576 : }
77 : :
78 : 9 : ScLookupCache::ScLookupCache( ScDocument * pDoc, const ScRange & rRange ) :
79 : : maRange( rRange),
80 [ + - ]: 9 : mpDoc( pDoc)
81 : : {
82 : 9 : }
83 : :
84 : :
85 [ + - ]: 9 : ScLookupCache::~ScLookupCache()
86 : : {
87 [ - + ]: 18 : }
88 : :
89 : :
90 : 144 : ScLookupCache::Result ScLookupCache::lookup( ScAddress & o_rResultAddress,
91 : : const QueryCriteria & rCriteria, const ScAddress & rQueryAddress ) const
92 : : {
93 : : QueryMap::const_iterator it( maQueryMap.find( QueryKey( rQueryAddress,
94 [ + - ]: 144 : rCriteria.getQueryOp())));
95 [ + - ][ + - ]: 144 : if (it == maQueryMap.end())
96 : 144 : return NOT_CACHED;
97 [ # # ]: 0 : const QueryCriteriaAndResult& rResult = (*it).second;
98 [ # # ][ # # ]: 0 : if (!(rResult.maCriteria == rCriteria))
99 : 0 : return CRITERIA_DIFFERENT;
100 [ # # ]: 0 : if (rResult.maAddress.Row() < 0 )
101 : 0 : return NOT_AVAILABLE;
102 : 0 : o_rResultAddress = rResult.maAddress;
103 : 144 : return FOUND;
104 : : }
105 : :
106 : :
107 : 144 : bool ScLookupCache::insert( const ScAddress & rResultAddress,
108 : : const QueryCriteria & rCriteria, const ScAddress & rQueryAddress,
109 : : const bool bAvailable )
110 : : {
111 : 144 : QueryKey aKey( rQueryAddress, rCriteria.getQueryOp());
112 [ + - ]: 144 : QueryCriteriaAndResult aResult( rCriteria, rResultAddress);
113 [ + + ]: 144 : if (!bAvailable)
114 : 15 : aResult.maAddress.SetRow(-1);
115 : : bool bInserted = maQueryMap.insert( ::std::pair< const QueryKey,
116 [ + - ][ + - ]: 144 : QueryCriteriaAndResult>( aKey, aResult)).second;
[ + - ]
117 : :
118 [ + - ]: 144 : return bInserted;
119 : : }
120 : :
121 : :
122 : 9 : void ScLookupCache::Notify( SvtBroadcaster & /* rBC */ , const SfxHint & rHint )
123 : : {
124 [ + - ]: 9 : if (!mpDoc->IsInDtorClear())
125 : : {
126 [ + - ][ + - ]: 9 : const ScHint* p = PTR_CAST( ScHint, &rHint );
127 [ + - ][ + - ]: 9 : if (p && (p->GetId() & (SC_HINT_DATACHANGED | SC_HINT_DYING)))
[ + - ]
128 : : {
129 : 9 : mpDoc->RemoveLookupCache( *this);
130 [ + - ]: 9 : delete this;
131 : : }
132 : : }
133 : 9 : }
134 : :
135 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|