LCOV - code coverage report
Current view: top level - filter/source/config/cache - cacheitem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 85 157 54.1 %
Date: 2015-06-13 12:38:46 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             : #include <osl/diagnose.h>
      30             : #include <comphelper/sequence.hxx>
      31             : 
      32             : 
      33             : namespace filter{
      34             :     namespace config{
      35             : 
      36     1403113 : CacheItem::CacheItem()
      37     1403113 :     : SequenceAsHashMap()
      38             : {
      39     1403113 : }
      40             : 
      41             : 
      42             : 
      43       20944 : void CacheItem::update(const CacheItem& rUpdateItem)
      44             : {
      45      314160 :     for(const_iterator pItUpdate  = rUpdateItem.begin();
      46      209440 :                        pItUpdate != rUpdateItem.end()  ;
      47             :                      ++pItUpdate                       )
      48             :     {
      49       83776 :         iterator pItThis = this->find(pItUpdate->first);
      50       83776 :         if (pItThis == this->end())
      51       62832 :             (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
      52             :         else
      53       20944 :             pItThis->second = pItUpdate->second; // change value of existing prop
      54             :     }
      55       20944 : }
      56             : 
      57             : 
      58             : 
      59           1 : void CacheItem::validateUINames(const OUString& sActLocale)
      60             : {
      61           1 :     if (sActLocale.isEmpty())
      62           1 :         return;
      63             : 
      64             :     // 1) check UINames first
      65           1 :     const_iterator pUINames = find(PROPNAME_UINAMES);
      66           1 :     const_iterator pUIName  = find(PROPNAME_UINAME );
      67             : 
      68           1 :     ::comphelper::SequenceAsHashMap lUINames;
      69           1 :     if (pUINames != end())
      70           1 :         lUINames << pUINames->second;
      71             : 
      72           2 :     OUString sUIName;
      73           1 :     if (pUIName != end())
      74           1 :         pUIName->second >>= sUIName;
      75             : 
      76           1 :     if (!sUIName.isEmpty())
      77             :     {
      78             :         // 1a) set UIName inside list of UINames for current locale
      79           1 :         lUINames[sActLocale] <<= sUIName;
      80             :     }
      81           0 :     else if (lUINames.size()>0)
      82             :     {
      83             :         // 1b) or get it from this list, if it not exist!
      84           0 :         lUINames[sActLocale] >>= sUIName;
      85             :     }
      86             : 
      87           1 :     (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
      88           2 :     (*this)[PROPNAME_UINAME ] <<= sUIName;
      89             : }
      90             : 
      91             : 
      92             : 
      93       23916 : css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList()
      94             : {
      95       23916 :     sal_Int32 c = (sal_Int32)size();
      96       23916 :     sal_Int32 i = 0;
      97             : 
      98       23916 :     css::uno::Sequence< css::beans::PropertyValue > lList(c);
      99       23916 :     css::beans::PropertyValue*                      pList = lList.getArray();
     100             : 
     101      947124 :     for (const_iterator pProp  = begin();
     102      631416 :                         pProp != end()  ;
     103             :                       ++pProp           )
     104             :     {
     105      291792 :         const OUString& rName  = pProp->first;
     106      291792 :         const css::uno::Any&   rValue = pProp->second;
     107             : 
     108      291792 :         if (!rValue.hasValue())
     109       15229 :             continue;
     110             : 
     111      276563 :         pList[i].Name  = rName ;
     112      276563 :         pList[i].Value = rValue;
     113      276563 :         ++i;
     114             :     }
     115       23916 :     lList.realloc(i);
     116             : 
     117       23916 :     return lList;
     118             : }
     119             : 
     120             : 
     121             : 
     122     2114026 : bool isSubSet(const css::uno::Any& aSubSet,
     123             :                   const css::uno::Any& aSet   )
     124             : {
     125     2114026 :     css::uno::Type aT1 = aSubSet.getValueType();
     126     4228052 :     css::uno::Type aT2 = aSet.getValueType();
     127             : 
     128     2114026 :     if (!aT1.equals(aT2))
     129             :     {
     130             :         _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
     131           0 :         return false;
     132             :     }
     133             : 
     134     2114026 :     css::uno::TypeClass aTypeClass = aT1.getTypeClass();
     135     2114026 :     switch(aTypeClass)
     136             :     {
     137             : 
     138             :         case css::uno::TypeClass_BOOLEAN :
     139             :         case css::uno::TypeClass_BYTE :
     140             :         case css::uno::TypeClass_SHORT :
     141             :         case css::uno::TypeClass_UNSIGNED_SHORT :
     142             :         case css::uno::TypeClass_LONG :
     143             :         case css::uno::TypeClass_UNSIGNED_LONG :
     144             :         case css::uno::TypeClass_HYPER :
     145             :         case css::uno::TypeClass_UNSIGNED_HYPER :
     146             :         case css::uno::TypeClass_FLOAT :
     147             :         case css::uno::TypeClass_DOUBLE :
     148             :         {
     149      232848 :             bool bIs = (aSubSet == aSet);
     150             :             _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs ? "TRUE" : "FALSE")
     151      232848 :             return bIs;
     152             :         }
     153             : 
     154             : 
     155             :         case css::uno::TypeClass_STRING :
     156             :         {
     157     1706739 :             OUString v1;
     158     1706739 :             OUString v2;
     159             : 
     160     1706739 :             if (
     161     3413478 :                 (aSubSet >>= v1) &&
     162     1706739 :                 (aSet    >>= v2)
     163             :                )
     164             :             {
     165     1706739 :                 bool bIs = (v1.equals(v2));
     166             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
     167     1706739 :                 return bIs;
     168           0 :             }
     169             :         }
     170           0 :         break;
     171             : 
     172             : 
     173             :         case css::uno::TypeClass_ANY :
     174             :         {
     175           0 :             css::uno::Any v1;
     176           0 :             css::uno::Any v2;
     177             : 
     178           0 :             if (
     179           0 :                 (aSubSet >>= v1) &&
     180           0 :                 (aSet    >>= v2)
     181             :                )
     182             :             {
     183           0 :                 bool bIs = (isSubSet(v1, v2));
     184             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
     185           0 :                 return bIs;
     186           0 :             }
     187             :         }
     188           0 :         break;
     189             : 
     190             : 
     191             :         case css::uno::TypeClass_STRUCT :
     192             :         {
     193           0 :             css::beans::PropertyValue p1;
     194           0 :             css::beans::PropertyValue p2;
     195             : 
     196           0 :             if (
     197           0 :                 (aSubSet >>= p1) &&
     198           0 :                 (aSet    >>= p2)
     199             :                )
     200             :             {
     201             :                 bool bIs = (
     202           0 :                                 (p1.Name.equals(p2.Name)     ) &&
     203           0 :                                 (isSubSet(p1.Value, p2.Value))
     204           0 :                                );
     205             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs ? "TRUE" : "FALSE")
     206           0 :                 return bIs;
     207             :             }
     208             : 
     209           0 :             css::beans::NamedValue n1;
     210           0 :             css::beans::NamedValue n2;
     211             : 
     212           0 :             if (
     213           0 :                 (aSubSet >>= n1) &&
     214           0 :                 (aSet    >>= n2)
     215             :                )
     216             :             {
     217             :                 bool bIs = (
     218           0 :                                 (n1.Name.equals(n2.Name)     ) &&
     219           0 :                                 (isSubSet(n1.Value, n2.Value))
     220           0 :                                );
     221             :                 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs ? "TRUE" : "FALSE")
     222           0 :                 return bIs;
     223           0 :             }
     224             :         }
     225           0 :         break;
     226             : 
     227             : 
     228             :         case css::uno::TypeClass_SEQUENCE :
     229             :         {
     230      174439 :             css::uno::Sequence< OUString > uno_s1;
     231      174439 :             css::uno::Sequence< OUString > uno_s2;
     232             : 
     233      174439 :             if (
     234      348878 :                 (aSubSet >>= uno_s1) &&
     235      174439 :                 (aSet    >>= uno_s2)
     236             :                )
     237             :             {
     238      174439 :                 OUStringList stl_s1(comphelper::sequenceToContainer<OUStringList>(uno_s1));
     239      348878 :                 OUStringList stl_s2(comphelper::sequenceToContainer<OUStringList>(uno_s2));
     240             : 
     241      538476 :                 for (OUStringList::const_iterator it1  = stl_s1.begin();
     242      358984 :                                                   it1 != stl_s1.end()  ;
     243             :                                                 ++it1                  )
     244             :                 {
     245      174439 :                     if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end())
     246             :                     {
     247             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1))
     248      169386 :                         return false;
     249             :                     }
     250             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1))
     251             :                 }
     252             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
     253      179492 :                 return true;
     254             :             }
     255             : 
     256           0 :             css::uno::Sequence< css::beans::PropertyValue > uno_p1;
     257           0 :             css::uno::Sequence< css::beans::PropertyValue > uno_p2;
     258             : 
     259           0 :             if (
     260           0 :                 (aSubSet >>= uno_p1) &&
     261           0 :                 (aSet    >>= uno_p2)
     262             :                )
     263             :             {
     264           0 :                 ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
     265           0 :                 ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
     266             : 
     267           0 :                 for (::comphelper::SequenceAsHashMap::const_iterator it1  = stl_p1.begin();
     268           0 :                                                                      it1 != stl_p1.end()  ;
     269             :                                                                    ++it1                  )
     270             :                 {
     271           0 :                     ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first);
     272           0 :                     if (it2 == stl_p2.end())
     273             :                     {
     274             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     275           0 :                         return false;
     276             :                     }
     277           0 :                     if (!isSubSet(it1->second, it2->second))
     278             :                     {
     279             :                         _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))
     280           0 :                         return false;
     281             :                     }
     282             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     283             :                 }
     284             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
     285           0 :                 return true;
     286             :             }
     287             : 
     288           0 :             css::uno::Sequence< css::beans::NamedValue > uno_n1;
     289           0 :             css::uno::Sequence< css::beans::NamedValue > uno_n2;
     290             : 
     291           0 :             if (
     292           0 :                 (aSubSet >>= uno_n1) &&
     293           0 :                 (aSet    >>= uno_n2)
     294             :                )
     295             :             {
     296           0 :                 ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
     297           0 :                 ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
     298             : 
     299           0 :                 for (::comphelper::SequenceAsHashMap::const_iterator it1  = stl_n1.begin();
     300           0 :                                                                      it1 != stl_n1.end()  ;
     301             :                                                                    ++it1                  )
     302             :                 {
     303           0 :                     ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first);
     304           0 :                     if (it2 == stl_n2.end())
     305             :                     {
     306             :                         _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     307           0 :                         return false;
     308             :                     }
     309           0 :                     if (!isSubSet(it1->second, it2->second))
     310             :                     {
     311             :                         _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))
     312           0 :                         return false;
     313             :                     }
     314             :                     _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
     315             :                 }
     316             :                 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
     317           0 :                 return true;
     318           0 :             }
     319             :         }
     320           0 :         break;
     321           0 :         default: break;
     322             :     }
     323             : 
     324             :     OSL_FAIL("isSubSet() ... this point should not be reached!");
     325     2114026 :     return false;
     326             : }
     327             : 
     328             : 
     329             : 
     330     2095946 : bool CacheItem::haveProps(const CacheItem& lProps) const
     331             : {
     332     6857238 :     for (const_iterator pIt  = lProps.begin();
     333     4571492 :                         pIt != lProps.end()  ;
     334             :                       ++pIt                  )
     335             :     {
     336             :         // i) one required property does not exist at this item => return false
     337     2114026 :         const_iterator pItThis = this->find(pIt->first);
     338     2114026 :         if (pItThis == this->end())
     339             :         {
     340             :             _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     341     1924226 :             return false;
     342             :         }
     343             : 
     344             :         // ii) one item does not have the right value => return false
     345     2114026 :         if (!isSubSet(pIt->second, pItThis->second))
     346             :         {
     347             :             _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     348     1924226 :             return false;
     349             :         }
     350             :     }
     351             : 
     352             :     // this method was not breaked before =>
     353             :     // the given property set seems to match with our
     354             :     // own properties in its minimum => return TRUE
     355             :     _FILTER_CONFIG_LOG_("CacheItem::haveProps() ... => return TRUE\n")
     356      171720 :     return true;
     357             : }
     358             : 
     359             : 
     360             : 
     361      171720 : bool CacheItem::dontHaveProps(const CacheItem& lProps) const
     362             : {
     363      515160 :     for (const_iterator pIt  = lProps.begin();
     364      343440 :                         pIt != lProps.end()  ;
     365             :                       ++pIt                  )
     366             :     {
     367             :         // i) one item does not exists in general
     368             :         //    => continue with next one, because
     369             :         //    "excluding" means ... "dont have it".
     370             :         //    And "not exists" match to "dont have it".
     371           0 :         const_iterator pItThis = this->find(pIt->first);
     372           0 :         if (pItThis == this->end())
     373             :         {
     374             :             _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     375           0 :             continue;
     376             :         }
     377             : 
     378             :         // ii) one item have the right value => return false
     379             :         //     because this item has the requested property ...
     380             :         //     But we checked for "dont have it" here.
     381           0 :         if (isSubSet(pIt->second, pItThis->second))
     382             :         {
     383             :             _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
     384           0 :             return false;
     385             :         }
     386             :     }
     387             : 
     388             :     // this method was not breaked before =>
     389             :     // That means: this item has no matching property
     390             :     // of the given set. It "dont have" it ... => return true.
     391             :     _FILTER_CONFIG_LOG_("CacheItem::dontHaveProps() ... => return TRUE\n")
     392      171720 :     return true;
     393             : }
     394             : 
     395      827967 : FlatDetectionInfo::FlatDetectionInfo() :
     396      827967 :     bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
     397             : 
     398             :     } // namespace config
     399             : } // namespace filter
     400             : 
     401             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11