LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/forms - property_meta_data.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2012-12-27 Functions: 0 12 0.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 "property_description.hxx"
      22             : #include "forms/form_handler_factory.hxx"
      23             : #include "strings.hxx"
      24             : #include "xmloff/xmltoken.hxx"
      25             : #include "xmloff/xmlnmspe.hxx"
      26             : 
      27             : #include <tools/debug.hxx>
      28             : 
      29             : #include <boost/unordered_map.hpp>
      30             : 
      31             : //......................................................................................................................
      32             : namespace xmloff { namespace metadata
      33             : {
      34             : //......................................................................................................................
      35             : 
      36             :     using namespace ::xmloff::token;
      37             : 
      38             : #define FORM_SINGLE_PROPERTY( id, att ) \
      39             :     PropertyDescription( PROPERTY_##id, XML_NAMESPACE_FORM, att, &FormHandlerFactory::getFormPropertyHandler, PID_##id, NO_GROUP )
      40             : 
      41             :     //==================================================================================================================
      42             :     //= property meta data
      43             :     //==================================================================================================================
      44             :     //------------------------------------------------------------------------------------------------------------------
      45             :     namespace
      46             :     {
      47           0 :         const PropertyDescription* lcl_getPropertyMetaData()
      48             :         {
      49             :             static const PropertyDescription s_propertyMetaData[] =
      50             :             {
      51             :                 FORM_SINGLE_PROPERTY( DATE_MIN,        XML_MIN_VALUE        ),
      52             :                 FORM_SINGLE_PROPERTY( DATE_MAX,        XML_MAX_VALUE        ),
      53             :                 FORM_SINGLE_PROPERTY( DEFAULT_DATE,    XML_VALUE            ),
      54             :                 FORM_SINGLE_PROPERTY( DATE,            XML_CURRENT_VALUE    ),
      55             :                 FORM_SINGLE_PROPERTY( TIME_MIN,        XML_MIN_VALUE        ),
      56             :                 FORM_SINGLE_PROPERTY( TIME_MAX,        XML_MAX_VALUE        ),
      57             :                 FORM_SINGLE_PROPERTY( DEFAULT_TIME,    XML_VALUE            ),
      58             :                 FORM_SINGLE_PROPERTY( TIME,            XML_CURRENT_VALUE    ),
      59             : 
      60             :                 PropertyDescription()
      61           0 :             };
      62           0 :             return s_propertyMetaData;
      63             :         }
      64             :     }
      65             : 
      66             :     //------------------------------------------------------------------------------------------------------------------
      67             :     namespace
      68             :     {
      69             :         // TODO: instead of having all of the below static, it should be some per-instance data. This way, the
      70             :         // approach used here would scale much better.
      71             :         // That is, if you have multiple "meta data instances", which manage a small, but closed set of properties,
      72             :         // then looking looking through those multiple instances would probably be faster than searching within
      73             :         // one big instance, since in this case, every instance can quickly decide whether it is responsible
      74             :         // for some attribute or property, and otherwise delegate to the next instance.
      75             : 
      76             :         //..............................................................................................................
      77             :         typedef ::boost::unordered_map< ::rtl::OUString, const PropertyDescription*, ::rtl::OUStringHash > DescriptionsByName;
      78             : 
      79             :         //..............................................................................................................
      80           0 :         const DescriptionsByName& lcl_getPropertyDescriptions()
      81             :         {
      82             :             DBG_TESTSOLARMUTEX();
      83           0 :             static DescriptionsByName s_propertyDescriptionsByName;
      84           0 :             if ( s_propertyDescriptionsByName.empty() )
      85             :             {
      86           0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
      87           0 :                 while ( !desc->propertyName.isEmpty() )
      88             :                 {
      89           0 :                     s_propertyDescriptionsByName[ desc->propertyName ] = desc;
      90           0 :                     ++desc;
      91             :                 }
      92             :             }
      93           0 :             return s_propertyDescriptionsByName;
      94             :         }
      95             : 
      96             :         //..............................................................................................................
      97             :         typedef ::std::map< PropertyGroup, PropertyDescriptionList > IndexedPropertyGroups;
      98             : 
      99             :         //..............................................................................................................
     100           0 :         const IndexedPropertyGroups& lcl_getIndexedPropertyGroups()
     101             :         {
     102             :             DBG_TESTSOLARMUTEX();
     103           0 :             static IndexedPropertyGroups s_indexedPropertyGroups;
     104           0 :             if ( s_indexedPropertyGroups.empty() )
     105             :             {
     106           0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     107           0 :                 while ( !desc->propertyName.isEmpty() )
     108             :                 {
     109           0 :                     if ( desc->propertyGroup != NO_GROUP )
     110           0 :                         s_indexedPropertyGroups[ desc->propertyGroup ].push_back( desc );
     111           0 :                     ++desc;
     112             :                 }
     113             :             }
     114           0 :             return s_indexedPropertyGroups;
     115             :         }
     116             : 
     117             :         //..............................................................................................................
     118             :         typedef ::boost::unordered_map< ::rtl::OUString, XMLTokenEnum, ::rtl::OUStringHash > ReverseTokenLookup;
     119             : 
     120             :         //..............................................................................................................
     121           0 :         const ReverseTokenLookup& getReverseTokenLookup()
     122             :         {
     123             :             DBG_TESTSOLARMUTEX();
     124           0 :             static ReverseTokenLookup s_reverseTokenLookup;
     125           0 :             if ( s_reverseTokenLookup.empty() )
     126             :             {
     127           0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     128           0 :                 while ( !desc->propertyName.isEmpty() )
     129             :                 {
     130           0 :                     s_reverseTokenLookup[ token::GetXMLToken( desc->attribute.attributeToken ) ] = desc->attribute.attributeToken;
     131           0 :                     ++desc;
     132             :                 }
     133             :             }
     134           0 :             return s_reverseTokenLookup;
     135             :         }
     136             : 
     137             :         //..............................................................................................................
     138             :         struct AttributeHash : public ::std::unary_function< AttributeDescription, size_t >
     139             :         {
     140           0 :             size_t operator()( const AttributeDescription& i_attribute ) const
     141             :             {
     142           0 :                 return size_t( i_attribute.attributeToken * 100 ) + size_t( i_attribute.namespacePrefix );
     143             :             }
     144             :         };
     145             : 
     146             :         //..............................................................................................................
     147             :         typedef ::boost::unordered_multimap< AttributeDescription, PropertyGroup, AttributeHash > AttributeGroups;
     148             : 
     149             :         //..............................................................................................................
     150           0 :         const AttributeGroups& lcl_getAttributeGroups()
     151             :         {
     152             :             DBG_TESTSOLARMUTEX();
     153           0 :             static AttributeGroups s_attributeGroups;
     154           0 :             if ( s_attributeGroups.empty() )
     155             :             {
     156           0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     157           0 :                 while ( !desc->propertyName.isEmpty() )
     158             :                 {
     159           0 :                     if ( desc->propertyGroup != NO_GROUP )
     160           0 :                         s_attributeGroups.insert( AttributeGroups::value_type( desc->attribute, desc->propertyGroup ) );
     161           0 :                     ++desc;
     162             :                 }
     163             :             }
     164           0 :             return s_attributeGroups;
     165             :         }
     166             : 
     167             :         //..............................................................................................................
     168             :         typedef ::boost::unordered_map< AttributeDescription, PropertyGroups, AttributeHash > AttributesWithoutGroup;
     169             : 
     170             :         //..............................................................................................................
     171           0 :         const AttributesWithoutGroup& lcl_getAttributesWithoutGroups()
     172             :         {
     173             :             DBG_TESTSOLARMUTEX();
     174           0 :             static AttributesWithoutGroup s_attributesWithoutGroup;
     175           0 :             if ( s_attributesWithoutGroup.empty() )
     176             :             {
     177           0 :                 const PropertyDescription* desc = lcl_getPropertyMetaData();
     178           0 :                 while ( !desc->propertyName.isEmpty() )
     179             :                 {
     180           0 :                     if ( desc->propertyGroup == NO_GROUP )
     181             :                     {
     182           0 :                         PropertyDescriptionList singleElementList;
     183           0 :                         singleElementList.push_back( desc );
     184             : 
     185           0 :                         s_attributesWithoutGroup[ desc->attribute ].push_back( singleElementList );
     186             :                     }
     187           0 :                     ++desc;
     188             :                 }
     189             :             }
     190           0 :             return s_attributesWithoutGroup;
     191             :         }
     192             :     }
     193             : 
     194             :     //------------------------------------------------------------------------------------------------------------------
     195           0 :     const PropertyDescription* getPropertyDescription( const ::rtl::OUString& i_propertyName )
     196             :     {
     197           0 :         const DescriptionsByName& rAllDescriptions( lcl_getPropertyDescriptions() );
     198           0 :         DescriptionsByName::const_iterator pos = rAllDescriptions.find( i_propertyName );
     199           0 :         if ( pos != rAllDescriptions.end() )
     200           0 :             return pos->second;
     201           0 :         return NULL;
     202             :     }
     203             : 
     204             :     //------------------------------------------------------------------------------------------------------------------
     205           0 :     void getPropertyGroup( const PropertyGroup i_propertyGroup, PropertyDescriptionList& o_propertyDescriptions )
     206             :     {
     207             :         OSL_ENSURE( i_propertyGroup != NO_GROUP, "xmloff::metadata::getPropertyGroup: illegal group!" );
     208             : 
     209           0 :         const IndexedPropertyGroups& rPropertyGroups( lcl_getIndexedPropertyGroups() );
     210           0 :         const IndexedPropertyGroups::const_iterator pos = rPropertyGroups.find( i_propertyGroup );
     211           0 :         if ( pos != rPropertyGroups.end() )
     212           0 :             o_propertyDescriptions = pos->second;
     213           0 :     }
     214             : 
     215             :     //------------------------------------------------------------------------------------------------------------------
     216           0 :     void getPropertyGroupList( const AttributeDescription& i_attribute, PropertyGroups& o_propertyGroups )
     217             :     {
     218           0 :         const AttributeGroups& rAttributeGroups = lcl_getAttributeGroups();
     219             : 
     220             :         ::std::pair< AttributeGroups::const_iterator, AttributeGroups::const_iterator >
     221           0 :             range = rAttributeGroups.equal_range( i_attribute );
     222             : 
     223           0 :         if ( range.first == range.second )
     224             :         {
     225             :             // the attribute is not used for any non-trivial group, which means it is mapped directly to
     226             :             // a single property
     227           0 :             const AttributesWithoutGroup& attributesWithoutGroups( lcl_getAttributesWithoutGroups() );
     228           0 :             const AttributesWithoutGroup::const_iterator pos = attributesWithoutGroups.find( i_attribute );
     229           0 :             if ( pos != attributesWithoutGroups.end() )
     230           0 :                 o_propertyGroups = pos->second;
     231             :         }
     232             :         else
     233             :         {
     234           0 :             const IndexedPropertyGroups& rPropertyGroups = lcl_getIndexedPropertyGroups();
     235           0 :             for ( AttributeGroups::const_iterator group = range.first; group != range.second; ++group )
     236             :             {
     237           0 :                 const PropertyGroup propGroup = group->second;
     238           0 :                 const IndexedPropertyGroups::const_iterator groupPos = rPropertyGroups.find( propGroup );
     239           0 :                 if( groupPos == rPropertyGroups.end() )
     240             :                 {
     241             :                     SAL_WARN( "xmloff.forms", "getPropertyGroupList: inconsistency!" );
     242           0 :                     continue;
     243             :                 }
     244             : 
     245           0 :                 o_propertyGroups.push_back( groupPos->second );
     246             :             }
     247             :         }
     248           0 :     }
     249             : 
     250             :     //------------------------------------------------------------------------------------------------------------------
     251           0 :     AttributeDescription getAttributeDescription( const sal_uInt16 i_namespacePrefix, const ::rtl::OUString& i_attributeName )
     252             :     {
     253           0 :         AttributeDescription attribute;
     254           0 :         const ReverseTokenLookup& rTokenLookup( getReverseTokenLookup() );
     255           0 :         const ReverseTokenLookup::const_iterator pos = rTokenLookup.find( i_attributeName );
     256           0 :         if ( pos != rTokenLookup.end() )
     257             :         {
     258           0 :             attribute.namespacePrefix = i_namespacePrefix;
     259           0 :             attribute.attributeToken = pos->second;
     260             :         }
     261           0 :         return attribute;
     262             :     }
     263             : 
     264             : //......................................................................................................................
     265             : } } // namespace xmloff::metadata
     266             : //......................................................................................................................
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10