LCOV - code coverage report
Current view: top level - filter/source/config/cache - cacheitem.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 85 157 54.1 %
Date: 2014-04-11 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "cacheitem.hxx"
      22             : #include "macros.hxx"
      23             : #include "constant.hxx"
      24             : 
      25             : #include <com/sun/star/uno/Sequence.h>
      26             : 
      27             : #include <com/sun/star/beans/PropertyValue.hpp>
      28             : 
      29             : 
      30             : namespace filter{
      31             :     namespace config{
      32             : 
      33      812875 : CacheItem::CacheItem()
      34      812875 :     : SequenceAsHashMap()
      35             : {
      36      812875 : }
      37             : 
      38             : 
      39             : 
      40       11573 : void CacheItem::update(const CacheItem& rUpdateItem)
      41             : {
      42      173595 :     for(const_iterator pItUpdate  = rUpdateItem.begin();
      43      115730 :                        pItUpdate != rUpdateItem.end()  ;
      44             :                      ++pItUpdate                       )
      45             :     {
      46       46292 :         iterator pItThis = this->find(pItUpdate->first);
      47       46292 :         if (pItThis == this->end())
      48       34719 :             (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
      49             :         else
      50       11573 :             pItThis->second = pItUpdate->second; // change value of existing prop
      51             :     }
      52       11573 : }
      53             : 
      54             : 
      55             : 
      56           1 : void CacheItem::validateUINames(const OUString& sActLocale)
      57             : {
      58           1 :     if (sActLocale.isEmpty())
      59           1 :         return;
      60             : 
      61             :     // 1) check UINames first
      62           1 :     const_iterator pUINames = find(PROPNAME_UINAMES);
      63           1 :     const_iterator pUIName  = find(PROPNAME_UINAME );
      64             : 
      65           1 :     ::comphelper::SequenceAsHashMap lUINames;
      66           1 :     if (pUINames != end())
      67           1 :         lUINames << pUINames->second;
      68             : 
      69           2 :     OUString sUIName;
      70           1 :     if (pUIName != end())
      71           1 :         pUIName->second >>= sUIName;
      72             : 
      73           1 :     if (!sUIName.isEmpty())
      74             :     {
      75             :         // 1a) set UIName inside list of UINames for current locale
      76           1 :         lUINames[sActLocale] <<= sUIName;
      77             :     }
      78           0 :     else if (lUINames.size()>0)
      79             :     {
      80             :         // 1b) or get it from this list, if it not exist!
      81           0 :         lUINames[sActLocale] >>= sUIName;
      82             :     }
      83             : 
      84           1 :     (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
      85           2 :     (*this)[PROPNAME_UINAME ] <<= sUIName;
      86             : }
      87             : 
      88             : 
      89             : 
      90       20362 : css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList()
      91             : {
      92       20362 :     sal_Int32 c = (sal_Int32)size();
      93       20362 :     sal_Int32 i = 0;
      94             : 
      95       20362 :     css::uno::Sequence< css::beans::PropertyValue > lList(c);
      96       20362 :     css::beans::PropertyValue*                      pList = lList.getArray();
      97             : 
      98      807156 :     for (const_iterator pProp  = begin();
      99      538104 :                         pProp != end()  ;
     100             :                       ++pProp           )
     101             :     {
     102      248690 :         const OUString& rName  = pProp->first;
     103      248690 :         const css::uno::Any&   rValue = pProp->second;
     104             : 
     105      248690 :         if (!rValue.hasValue())
     106       11734 :             continue;
     107             : 
     108      236956 :         pList[i].Name  = rName ;
     109      236956 :         pList[i].Value = rValue;
     110      236956 :         ++i;
     111             :     }
     112       20362 :     lList.realloc(i);
     113             : 
     114       20362 :     return lList;
     115             : }
     116             : 
     117             : 
     118             : 
     119     1525464 : sal_Bool isSubSet(const css::uno::Any& aSubSet,
     120             :                   const css::uno::Any& aSet   )
     121             : {
     122     1525464 :     css::uno::Type aT1 = aSubSet.getValueType();
     123     3050928 :     css::uno::Type aT2 = aSet.getValueType();
     124             : 
     125     1525464 :     if (!aT1.equals(aT2))
     126             :     {
     127             :         _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
     128           0 :         return sal_False;
     129             :     }
     130             : 
     131     1525464 :     css::uno::TypeClass aTypeClass = aT1.getTypeClass();
     132     1525464 :     switch(aTypeClass)
     133             :     {
     134             : 
     135             :         case css::uno::TypeClass_BOOLEAN :
     136             :         case css::uno::TypeClass_BYTE :
     137             :         case css::uno::TypeClass_SHORT :
     138             :         case css::uno::TypeClass_UNSIGNED_SHORT :
     139             :         case css::uno::TypeClass_LONG :
     140             :         case css::uno::TypeClass_UNSIGNED_LONG :
     141             :         case css::uno::TypeClass_HYPER :
     142             :         case css::uno::TypeClass_UNSIGNED_HYPER :
     143             :         case css::uno::TypeClass_FLOAT :
     144             :         case css::uno::TypeClass_DOUBLE :
     145             :         {
     146      188696 :             sal_Bool bIs = (aSubSet == aSet);
     147             :             _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs ? "TRUE" : "FALSE")
     148      188696 :             return bIs;
     149             :         }
     150             : 
     151             : 
     152             :         case css::uno::TypeClass_STRING :
     153             :         {
     154     1227290 :             OUString v1;
     155     1227290 :             OUString v2;
     156             : 
     157     1227290 :             if (
     158     2454580 :                 (aSubSet >>= v1) &&
     159     1227290 :                 (aSet    >>= v2)
     160             :                )
     161             :             {
     162     1227290 :                 sal_Bool bIs = (v1.equals(v2));
     163             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
     164     1227290 :                 return bIs;
     165           0 :             }
     166             :         }
     167           0 :         break;
     168             : 
     169             : 
     170             :         case css::uno::TypeClass_ANY :
     171             :         {
     172           0 :             css::uno::Any v1;
     173           0 :             css::uno::Any v2;
     174             : 
     175           0 :             if (
     176           0 :                 (aSubSet >>= v1) &&
     177           0 :                 (aSet    >>= v2)
     178             :                )
     179             :             {
     180           0 :                 sal_Bool bIs = (isSubSet(v1, v2));
     181             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
     182           0 :                 return bIs;
     183           0 :             }
     184             :         }
     185           0 :         break;
     186             : 
     187             : 
     188             :         case css::uno::TypeClass_STRUCT :
     189             :         {
     190           0 :             css::beans::PropertyValue p1;
     191           0 :             css::beans::PropertyValue p2;
     192             : 
     193           0 :             if (
     194           0 :                 (aSubSet >>= p1) &&
     195           0 :                 (aSet    >>= p2)
     196             :                )
     197             :             {
     198             :                 sal_Bool bIs = (
     199           0 :                                 (p1.Name.equals(p2.Name)     ) &&
     200           0 :                                 (isSubSet(p1.Value, p2.Value))
     201           0 :                                );
     202             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs ? "TRUE" : "FALSE")
     203           0 :                 return bIs;
     204             :             }
     205             : 
     206           0 :             css::beans::NamedValue n1;
     207           0 :             css::beans::NamedValue n2;
     208             : 
     209           0 :             if (
     210           0 :                 (aSubSet >>= n1) &&
     211           0 :                 (aSet    >>= n2)
     212             :                )
     213             :             {
     214             :                 sal_Bool bIs = (
     215           0 :                                 (n1.Name.equals(n2.Name)     ) &&
     216           0 :                                 (isSubSet(n1.Value, n2.Value))
     217           0 :                                );
     218             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs ? "TRUE" : "FALSE")
     219           0 :                 return bIs;
     220           0 :             }
     221             :         }
     222           0 :         break;
     223             : 
     224             : 
     225             :         case css::uno::TypeClass_SEQUENCE :
     226             :         {
     227      109478 :             css::uno::Sequence< OUString > uno_s1;
     228      109478 :             css::uno::Sequence< OUString > uno_s2;
     229             : 
     230      109478 :             if (
     231      218956 :                 (aSubSet >>= uno_s1) &&
     232      109478 :                 (aSet    >>= uno_s2)
     233             :                )
     234             :             {
     235      109478 :                 OUStringList stl_s1(uno_s1);
     236      218956 :                 OUStringList stl_s2(uno_s2);
     237             : 
     238      337764 :                 for (OUStringList::const_iterator it1  = stl_s1.begin();
     239      225176 :                                                   it1 != stl_s1.end()  ;
     240             :                                                 ++it1                  )
     241             :                 {
     242      109478 :                     if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end())
     243             :                     {
     244             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1))
     245      106368 :                         return sal_False;
     246             :                     }
     247             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1))
     248             :                 }
     249             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
     250      112588 :                 return sal_True;
     251             :             }
     252             : 
     253           0 :             css::uno::Sequence< css::beans::PropertyValue > uno_p1;
     254           0 :             css::uno::Sequence< css::beans::PropertyValue > uno_p2;
     255             : 
     256           0 :             if (
     257           0 :                 (aSubSet >>= uno_p1) &&
     258           0 :                 (aSet    >>= uno_p2)
     259             :                )
     260             :             {
     261           0 :                 ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
     262           0 :                 ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
     263             : 
     264           0 :                 for (::comphelper::SequenceAsHashMap::const_iterator it1  = stl_p1.begin();
     265           0 :                                                                      it1 != stl_p1.end()  ;
     266             :                                                                    ++it1                  )
     267             :                 {
     268           0 :                     ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first);
     269           0 :                     if (it2 == stl_p2.end())
     270             :                     {
     271             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     272           0 :                         return sal_False;
     273             :                     }
     274           0 :                     if (!isSubSet(it1->second, it2->second))
     275             :                     {
     276             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" but has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     277           0 :                         return sal_False;
     278             :                     }
     279             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     280             :                 }
     281             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
     282           0 :                 return sal_True;
     283             :             }
     284             : 
     285           0 :             css::uno::Sequence< css::beans::NamedValue > uno_n1;
     286           0 :             css::uno::Sequence< css::beans::NamedValue > uno_n2;
     287             : 
     288           0 :             if (
     289           0 :                 (aSubSet >>= uno_n1) &&
     290           0 :                 (aSet    >>= uno_n2)
     291             :                )
     292             :             {
     293           0 :                 ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
     294           0 :                 ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
     295             : 
     296           0 :                 for (::comphelper::SequenceAsHashMap::const_iterator it1  = stl_n1.begin();
     297           0 :                                                                      it1 != stl_n1.end()  ;
     298             :                                                                    ++it1                  )
     299             :                 {
     300           0 :                     ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first);
     301           0 :                     if (it2 == stl_n2.end())
     302             :                     {
     303             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     304           0 :                         return sal_False;
     305             :                     }
     306           0 :                     if (!isSubSet(it1->second, it2->second))
     307             :                     {
     308             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" but has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     309           0 :                         return sal_False;
     310             :                     }
     311             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     312             :                 }
     313             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
     314           0 :                 return sal_True;
     315           0 :             }
     316             :         }
     317           0 :         break;
     318           0 :         default: break;
     319             :     }
     320             : 
     321             :     OSL_FAIL("isSubSet() ... this point should not be reached!");
     322     1525464 :     return sal_False;
     323             : }
     324             : 
     325             : 
     326             : 
     327     1509740 : sal_Bool CacheItem::haveProps(const CacheItem& lProps) const
     328             : {
     329     4859016 :     for (const_iterator pIt  = lProps.begin();
     330     3239344 :                         pIt != lProps.end()  ;
     331             :                       ++pIt                  )
     332             :     {
     333             :         // i) one required property does not exist at this item => return false
     334     1525464 :         const_iterator pItThis = this->find(pIt->first);
     335     1525464 :         if (pItThis == this->end())
     336             :         {
     337             :             _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     338     1415532 :             return sal_False;
     339             :         }
     340             : 
     341             :         // ii) one item does not have the right value => return false
     342     1525464 :         if (!isSubSet(pIt->second, pItThis->second))
     343             :         {
     344             :             _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     345     1415532 :             return sal_False;
     346             :         }
     347             :     }
     348             : 
     349             :     // this method was not breaked before =>
     350             :     // the given property set seems to match with our
     351             :     // own properties in its minimum => return TRUE
     352             :     _FILTER_CONFIG_LOG_("CacheItem::haveProps() ... => return TRUE\n")
     353       94208 :     return sal_True;
     354             : }
     355             : 
     356             : 
     357             : 
     358       94208 : sal_Bool CacheItem::dontHaveProps(const CacheItem& lProps) const
     359             : {
     360      282624 :     for (const_iterator pIt  = lProps.begin();
     361      188416 :                         pIt != lProps.end()  ;
     362             :                       ++pIt                  )
     363             :     {
     364             :         // i) one item does not exists in general
     365             :         //    => continue with next one, because
     366             :         //    "excluding" means ... "dont have it".
     367             :         //    And "not exists" match to "dont have it".
     368           0 :         const_iterator pItThis = this->find(pIt->first);
     369           0 :         if (pItThis == this->end())
     370             :         {
     371             :             _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     372           0 :             continue;
     373             :         }
     374             : 
     375             :         // ii) one item have the right value => return false
     376             :         //     because this item has the requested property ...
     377             :         //     But we checked for "dont have it" here.
     378           0 :         if (isSubSet(pIt->second, pItThis->second))
     379             :         {
     380             :             _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     381           0 :             return sal_False;
     382             :         }
     383             :     }
     384             : 
     385             :     // this method was not breaked before =>
     386             :     // That means: this item has no matching property
     387             :     // of the given set. It "dont have" it ... => return true.
     388             :     _FILTER_CONFIG_LOG_("CacheItem::dontHaveProps() ... => return TRUE\n")
     389       94208 :     return sal_True;
     390             : }
     391             : 
     392      480713 : FlatDetectionInfo::FlatDetectionInfo() :
     393      480713 :     bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
     394             : 
     395             :     } // namespace config
     396             : } // namespace filter
     397             : 
     398             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10