LCOV - code coverage report
Current view: top level - xmloff/source/forms - property_meta_data.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 86 57.0 %
Date: 2012-08-25 Functions: 8 12 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 55 170 32.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            :  ************************************************************************/
      27                 :            : 
      28                 :            : 
      29                 :            : #include "property_description.hxx"
      30                 :            : #include "forms/form_handler_factory.hxx"
      31                 :            : #include "strings.hxx"
      32                 :            : #include "xmloff/xmltoken.hxx"
      33                 :            : #include "xmloff/xmlnmspe.hxx"
      34                 :            : 
      35                 :            : #include <tools/debug.hxx>
      36                 :            : 
      37                 :            : #include <boost/unordered_map.hpp>
      38                 :            : 
      39                 :            : //......................................................................................................................
      40                 :            : namespace xmloff { namespace metadata
      41                 :            : {
      42                 :            : //......................................................................................................................
      43                 :            : 
      44                 :            :     using namespace ::xmloff::token;
      45                 :            : 
      46                 :            : #define FORM_SINGLE_PROPERTY( id, att ) \
      47                 :            :     PropertyDescription( PROPERTY_##id, XML_NAMESPACE_FORM, att, &FormHandlerFactory::getFormPropertyHandler, PID_##id, NO_GROUP )
      48                 :            : 
      49                 :            :     //==================================================================================================================
      50                 :            :     //= property meta data
      51                 :            :     //==================================================================================================================
      52                 :            :     //------------------------------------------------------------------------------------------------------------------
      53                 :            :     namespace
      54                 :            :     {
      55                 :         14 :         const PropertyDescription* lcl_getPropertyMetaData()
      56                 :            :         {
      57                 :            :             static const PropertyDescription s_propertyMetaData[] =
      58                 :            :             {
      59                 :            :                 FORM_SINGLE_PROPERTY( DATE_MIN,        XML_MIN_VALUE        ),
      60                 :            :                 FORM_SINGLE_PROPERTY( DATE_MAX,        XML_MAX_VALUE        ),
      61                 :            :                 FORM_SINGLE_PROPERTY( DEFAULT_DATE,    XML_VALUE            ),
      62                 :            :                 FORM_SINGLE_PROPERTY( DATE,            XML_CURRENT_VALUE    ),
      63                 :            :                 FORM_SINGLE_PROPERTY( TIME_MIN,        XML_MIN_VALUE        ),
      64                 :            :                 FORM_SINGLE_PROPERTY( TIME_MAX,        XML_MAX_VALUE        ),
      65                 :            :                 FORM_SINGLE_PROPERTY( DEFAULT_TIME,    XML_VALUE            ),
      66                 :            :                 FORM_SINGLE_PROPERTY( TIME,            XML_CURRENT_VALUE    ),
      67                 :            : 
      68                 :            :                 PropertyDescription()
      69 [ +  + ][ +  - ]:         94 :             };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
           [ #  #  #  #  
           #  # ][ +  + ]
      70                 :         14 :             return s_propertyMetaData;
      71                 :            :         }
      72                 :            :     }
      73                 :            : 
      74                 :            :     //------------------------------------------------------------------------------------------------------------------
      75                 :            :     namespace
      76                 :            :     {
      77                 :            :         // TODO: instead of having all of the below static, it should be some per-instance data. This way, the
      78                 :            :         // approach used here would scale much better.
      79                 :            :         // That is, if you have multiple "meta data instances", which manage a small, but closed set of properties,
      80                 :            :         // then looking looking through those multiple instances would probably be faster than searching within
      81                 :            :         // one big instance, since in this case, every instance can quickly decide whether it is responsible
      82                 :            :         // for some attribute or property, and otherwise delegate to the next instance.
      83                 :            : 
      84                 :            :         //..............................................................................................................
      85                 :            :         typedef ::boost::unordered_map< ::rtl::OUString, const PropertyDescription*, ::rtl::OUStringHash > DescriptionsByName;
      86                 :            : 
      87                 :            :         //..............................................................................................................
      88                 :          0 :         const DescriptionsByName& lcl_getPropertyDescriptions()
      89                 :            :         {
      90                 :            :             DBG_TESTSOLARMUTEX();
      91 [ #  # ][ #  # ]:          0 :             static DescriptionsByName s_propertyDescriptionsByName;
         [ #  # ][ #  # ]
      92         [ #  # ]:          0 :             if ( s_propertyDescriptionsByName.empty() )
      93                 :            :             {
      94                 :          0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
      95         [ #  # ]:          0 :                 while ( !desc->propertyName.isEmpty() )
      96                 :            :                 {
      97                 :          0 :                     s_propertyDescriptionsByName[ desc->propertyName ] = desc;
      98                 :          0 :                     ++desc;
      99                 :            :                 }
     100                 :            :             }
     101                 :          0 :             return s_propertyDescriptionsByName;
     102                 :            :         }
     103                 :            : 
     104                 :            :         //..............................................................................................................
     105                 :            :         typedef ::std::map< PropertyGroup, PropertyDescriptionList > IndexedPropertyGroups;
     106                 :            : 
     107                 :            :         //..............................................................................................................
     108                 :          0 :         const IndexedPropertyGroups& lcl_getIndexedPropertyGroups()
     109                 :            :         {
     110                 :            :             DBG_TESTSOLARMUTEX();
     111 [ #  # ][ #  # ]:          0 :             static IndexedPropertyGroups s_indexedPropertyGroups;
         [ #  # ][ #  # ]
     112         [ #  # ]:          0 :             if ( s_indexedPropertyGroups.empty() )
     113                 :            :             {
     114         [ #  # ]:          0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     115         [ #  # ]:          0 :                 while ( !desc->propertyName.isEmpty() )
     116                 :            :                 {
     117         [ #  # ]:          0 :                     if ( desc->propertyGroup != NO_GROUP )
     118 [ #  # ][ #  # ]:          0 :                         s_indexedPropertyGroups[ desc->propertyGroup ].push_back( desc );
     119                 :          0 :                     ++desc;
     120                 :            :                 }
     121                 :            :             }
     122                 :          0 :             return s_indexedPropertyGroups;
     123                 :            :         }
     124                 :            : 
     125                 :            :         //..............................................................................................................
     126                 :            :         typedef ::boost::unordered_map< ::rtl::OUString, XMLTokenEnum, ::rtl::OUStringHash > ReverseTokenLookup;
     127                 :            : 
     128                 :            :         //..............................................................................................................
     129                 :        231 :         const ReverseTokenLookup& getReverseTokenLookup()
     130                 :            :         {
     131                 :            :             DBG_TESTSOLARMUTEX();
     132 [ +  + ][ +  - ]:        231 :             static ReverseTokenLookup s_reverseTokenLookup;
         [ +  - ][ #  # ]
     133         [ +  + ]:        231 :             if ( s_reverseTokenLookup.empty() )
     134                 :            :             {
     135                 :          8 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     136         [ +  + ]:         72 :                 while ( !desc->propertyName.isEmpty() )
     137                 :            :                 {
     138                 :         64 :                     s_reverseTokenLookup[ token::GetXMLToken( desc->attribute.attributeToken ) ] = desc->attribute.attributeToken;
     139                 :         64 :                     ++desc;
     140                 :            :                 }
     141                 :            :             }
     142                 :        231 :             return s_reverseTokenLookup;
     143                 :            :         }
     144                 :            : 
     145                 :            :         //..............................................................................................................
     146                 :            :         struct AttributeHash : public ::std::unary_function< AttributeDescription, size_t >
     147                 :            :         {
     148                 :         27 :             size_t operator()( const AttributeDescription& i_attribute ) const
     149                 :            :             {
     150                 :         27 :                 return size_t( i_attribute.attributeToken * 100 ) + size_t( i_attribute.namespacePrefix );
     151                 :            :             }
     152                 :            :         };
     153                 :            : 
     154                 :            :         //..............................................................................................................
     155                 :            :         typedef ::boost::unordered_multimap< AttributeDescription, PropertyGroup, AttributeHash > AttributeGroups;
     156                 :            : 
     157                 :            :         //..............................................................................................................
     158                 :          3 :         const AttributeGroups& lcl_getAttributeGroups()
     159                 :            :         {
     160                 :            :             DBG_TESTSOLARMUTEX();
     161 [ +  - ][ +  - ]:          3 :             static AttributeGroups s_attributeGroups;
         [ +  - ][ #  # ]
     162         [ +  - ]:          3 :             if ( s_attributeGroups.empty() )
     163                 :            :             {
     164                 :          3 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     165         [ +  + ]:         27 :                 while ( !desc->propertyName.isEmpty() )
     166                 :            :                 {
     167         [ -  + ]:         24 :                     if ( desc->propertyGroup != NO_GROUP )
     168         [ #  # ]:          0 :                         s_attributeGroups.insert( AttributeGroups::value_type( desc->attribute, desc->propertyGroup ) );
     169                 :         24 :                     ++desc;
     170                 :            :                 }
     171                 :            :             }
     172                 :          3 :             return s_attributeGroups;
     173                 :            :         }
     174                 :            : 
     175                 :            :         //..............................................................................................................
     176                 :            :         typedef ::boost::unordered_map< AttributeDescription, PropertyGroups, AttributeHash > AttributesWithoutGroup;
     177                 :            : 
     178                 :            :         //..............................................................................................................
     179                 :          3 :         const AttributesWithoutGroup& lcl_getAttributesWithoutGroups()
     180                 :            :         {
     181                 :            :             DBG_TESTSOLARMUTEX();
     182 [ +  - ][ +  - ]:          3 :             static AttributesWithoutGroup s_attributesWithoutGroup;
         [ +  - ][ #  # ]
     183         [ +  - ]:          3 :             if ( s_attributesWithoutGroup.empty() )
     184                 :            :             {
     185         [ +  - ]:          3 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     186         [ +  + ]:         27 :                 while ( !desc->propertyName.isEmpty() )
     187                 :            :                 {
     188         [ +  - ]:         24 :                     if ( desc->propertyGroup == NO_GROUP )
     189                 :            :                     {
     190         [ +  - ]:         24 :                         PropertyDescriptionList singleElementList;
     191         [ +  - ]:         24 :                         singleElementList.push_back( desc );
     192                 :            : 
     193 [ +  - ][ +  - ]:         24 :                         s_attributesWithoutGroup[ desc->attribute ].push_back( singleElementList );
     194                 :            :                     }
     195                 :         24 :                     ++desc;
     196                 :            :                 }
     197                 :            :             }
     198                 :          3 :             return s_attributesWithoutGroup;
     199                 :            :         }
     200                 :            :     }
     201                 :            : 
     202                 :            :     //------------------------------------------------------------------------------------------------------------------
     203                 :          0 :     const PropertyDescription* getPropertyDescription( const ::rtl::OUString& i_propertyName )
     204                 :            :     {
     205         [ #  # ]:          0 :         const DescriptionsByName& rAllDescriptions( lcl_getPropertyDescriptions() );
     206         [ #  # ]:          0 :         DescriptionsByName::const_iterator pos = rAllDescriptions.find( i_propertyName );
     207 [ #  # ][ #  # ]:          0 :         if ( pos != rAllDescriptions.end() )
     208         [ #  # ]:          0 :             return pos->second;
     209                 :          0 :         return NULL;
     210                 :            :     }
     211                 :            : 
     212                 :            :     //------------------------------------------------------------------------------------------------------------------
     213                 :          0 :     void getPropertyGroup( const PropertyGroup i_propertyGroup, PropertyDescriptionList& o_propertyDescriptions )
     214                 :            :     {
     215                 :            :         OSL_ENSURE( i_propertyGroup != NO_GROUP, "xmloff::metadata::getPropertyGroup: illegal group!" );
     216                 :            : 
     217         [ #  # ]:          0 :         const IndexedPropertyGroups& rPropertyGroups( lcl_getIndexedPropertyGroups() );
     218         [ #  # ]:          0 :         const IndexedPropertyGroups::const_iterator pos = rPropertyGroups.find( i_propertyGroup );
     219         [ #  # ]:          0 :         if ( pos != rPropertyGroups.end() )
     220         [ #  # ]:          0 :             o_propertyDescriptions = pos->second;
     221                 :          0 :     }
     222                 :            : 
     223                 :            :     //------------------------------------------------------------------------------------------------------------------
     224                 :          3 :     void getPropertyGroupList( const AttributeDescription& i_attribute, PropertyGroups& o_propertyGroups )
     225                 :            :     {
     226         [ +  - ]:          3 :         const AttributeGroups& rAttributeGroups = lcl_getAttributeGroups();
     227                 :            : 
     228                 :            :         ::std::pair< AttributeGroups::const_iterator, AttributeGroups::const_iterator >
     229         [ +  - ]:          3 :             range = rAttributeGroups.equal_range( i_attribute );
     230                 :            : 
     231         [ +  - ]:          3 :         if ( range.first == range.second )
     232                 :            :         {
     233                 :            :             // the attribute is not used for any non-trivial group, which means it is mapped directly to
     234                 :            :             // a single property
     235         [ +  - ]:          3 :             const AttributesWithoutGroup& attributesWithoutGroups( lcl_getAttributesWithoutGroups() );
     236         [ +  - ]:          3 :             const AttributesWithoutGroup::const_iterator pos = attributesWithoutGroups.find( i_attribute );
     237 [ +  - ][ +  - ]:          3 :             if ( pos != attributesWithoutGroups.end() )
     238 [ +  - ][ +  - ]:          3 :                 o_propertyGroups = pos->second;
     239                 :            :         }
     240                 :            :         else
     241                 :            :         {
     242         [ #  # ]:          0 :             const IndexedPropertyGroups& rPropertyGroups = lcl_getIndexedPropertyGroups();
     243         [ #  # ]:          0 :             for ( AttributeGroups::const_iterator group = range.first; group != range.second; ++group )
     244                 :            :             {
     245         [ #  # ]:          0 :                 const PropertyGroup propGroup = group->second;
     246         [ #  # ]:          0 :                 const IndexedPropertyGroups::const_iterator groupPos = rPropertyGroups.find( propGroup );
     247         [ #  # ]:          0 :                 if( groupPos == rPropertyGroups.end() )
     248                 :            :                 {
     249                 :            :                     SAL_WARN( "xmloff.forms", "getPropertyGroupList: inconsistency!" );
     250                 :          0 :                     continue;
     251                 :            :                 }
     252                 :            : 
     253         [ #  # ]:          0 :                 o_propertyGroups.push_back( groupPos->second );
     254                 :            :             }
     255                 :            :         }
     256                 :          3 :     }
     257                 :            : 
     258                 :            :     //------------------------------------------------------------------------------------------------------------------
     259                 :        231 :     AttributeDescription getAttributeDescription( const sal_uInt16 i_namespacePrefix, const ::rtl::OUString& i_attributeName )
     260                 :            :     {
     261                 :        231 :         AttributeDescription attribute;
     262         [ +  - ]:        231 :         const ReverseTokenLookup& rTokenLookup( getReverseTokenLookup() );
     263         [ +  - ]:        231 :         const ReverseTokenLookup::const_iterator pos = rTokenLookup.find( i_attributeName );
     264 [ +  - ][ +  + ]:        231 :         if ( pos != rTokenLookup.end() )
     265                 :            :         {
     266                 :          3 :             attribute.namespacePrefix = i_namespacePrefix;
     267         [ +  - ]:        231 :             attribute.attributeToken = pos->second;
     268                 :            :         }
     269                 :        231 :         return attribute;
     270                 :            :     }
     271                 :            : 
     272                 :            : //......................................................................................................................
     273                 :            : } } // namespace xmloff::metadata
     274                 :            : //......................................................................................................................
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10