LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/xmloff - xmlprmap.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 22 95.5 %
Date: 2013-07-09 Functions: 12 12 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             : #ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
      21             : #define _XMLOFF_PROPERTYSETMAPPER_HXX
      22             : 
      23             : #include "sal/config.h"
      24             : #include "xmloff/dllapi.h"
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : 
      29             : #include <vector>
      30             : #include <xmloff/uniref.hxx>
      31             : #include <xmloff/maptype.hxx>
      32             : #include <xmloff/xmltypes.hxx>
      33             : #include <xmloff/prhdlfac.hxx>
      34             : 
      35             : #include <tools/debug.hxx>
      36             : 
      37             : class SvXMLUnitConverter;
      38             : class XMLPropertyHandler;
      39             : 
      40             : ///////////////////////////////////////////////////////////////////////////
      41             : //
      42             : /** Helper-class for XML-im/export:
      43             :     - Holds a pointer to a given array of XMLPropertyMapEntry
      44             :     - Provides several methods to access data from this array
      45             :     - Holds a Sequence of XML-names (for properties)
      46             :     - The filter takes all properties of the XPropertySet which are also
      47             :       in the XMLPropertyMapEntry and which are have not a default value
      48             :       and put them into a vector of XMLPropertyStae
      49             :     - this class knows how to compare, im/export properties
      50             : 
      51             :     Attention: At all methods, which get an index as parameter, there is no
      52             :                range validation to save runtime !!
      53             : */
      54     2161801 : struct XMLPropertySetMapperEntry_Impl
      55             : {
      56             :     OUString sXMLAttributeName;
      57             :     OUString sAPIPropertyName;
      58             :     sal_uInt16 nXMLNameSpace;
      59             :     sal_Int32  nType;
      60             :     sal_Int16  nContextId;
      61             :     SvtSaveOptions::ODFDefaultVersion   nEarliestODFVersionForExport;
      62             :     const XMLPropertyHandler *pHdl;
      63             : 
      64             :     XMLPropertySetMapperEntry_Impl(
      65             :         const XMLPropertyMapEntry& rMapEntry,
      66             :         const UniReference< XMLPropertyHandlerFactory >& rFactory );
      67             : 
      68             :     XMLPropertySetMapperEntry_Impl(
      69             :         const XMLPropertySetMapperEntry_Impl& rEntry );
      70             : 
      71     1840582 :     sal_uInt32 GetPropType() const { return nType & XML_TYPE_PROP_MASK; }
      72             : };
      73             : 
      74             : class XMLOFF_DLLPUBLIC XMLPropertySetMapper : public UniRefBase
      75             : {
      76             :     ::std::vector< XMLPropertySetMapperEntry_Impl > aMapEntries;
      77             :     ::std::vector< UniReference < XMLPropertyHandlerFactory > > aHdlFactories;
      78             : 
      79             : public:
      80             :     /** The last element of the XMLPropertyMapEntry-array must contain NULL-values */
      81             :     XMLPropertySetMapper(
      82             :             const XMLPropertyMapEntry* pEntries,
      83             :             const UniReference< XMLPropertyHandlerFactory >& rFactory );
      84             :     virtual ~XMLPropertySetMapper();
      85             : 
      86             :     void AddMapperEntry( const UniReference < XMLPropertySetMapper >& rMapper );
      87             : 
      88             :     /** Return number of entries in input-array */
      89      110925 :     sal_Int32   GetEntryCount() const { return aMapEntries.size(); }
      90             : 
      91             :     /** Returns the flags of an entry */
      92      161951 :     sal_uInt32 GetEntryFlags( sal_Int32 nIndex ) const
      93             :     {
      94             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
      95      161951 :         return aMapEntries[nIndex].nType & ~MID_FLAG_MASK;
      96             :     }
      97             : 
      98             :     /** Returns the type of an entry */
      99         992 :     sal_uInt32 GetEntryType( sal_Int32 nIndex,
     100             :                                    sal_Bool bWithFlags = sal_True ) const
     101             :     {
     102             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     103         992 :         sal_uInt32 nType = aMapEntries[nIndex].nType;
     104         992 :         if( !bWithFlags )
     105           0 :             nType = nType & MID_FLAG_MASK;
     106         992 :         return nType;
     107             :     }
     108             : 
     109             :     /** Returns the namespace-key of an entry */
     110        4883 :     sal_uInt16 GetEntryNameSpace( sal_Int32 nIndex ) const
     111             :     {
     112             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     113        4883 :         return aMapEntries[nIndex].nXMLNameSpace;
     114             :     }
     115             : 
     116             :     /** Returns the 'local' XML-name of the entry */
     117        4883 :     const OUString& GetEntryXMLName( sal_Int32 nIndex ) const
     118             :     {
     119             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     120        4883 :         return aMapEntries[nIndex].sXMLAttributeName;
     121             :     }
     122             : 
     123             :     /** Returns the entry API name */
     124      218039 :     const OUString& GetEntryAPIName( sal_Int32 nIndex ) const
     125             :     {
     126             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     127      218039 :         return aMapEntries[nIndex].sAPIPropertyName;
     128             :     }
     129             : 
     130             :     /** returns the entry context id. -1 is a valid index here. */
     131      134950 :     sal_Int16 GetEntryContextId( sal_Int32 nIndex ) const
     132             :     {
     133             :         DBG_ASSERT( (nIndex >= -1) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     134      134950 :         return nIndex == -1 ? 0 : aMapEntries[nIndex].nContextId;
     135             :     }
     136             : 
     137             :     /** returns the earliest odf version for which this property should be exported. */
     138       33896 :     SvtSaveOptions::ODFDefaultVersion GetEarliestODFVersionForExport( sal_Int32 nIndex ) const
     139             :     {
     140             :         DBG_ASSERT( (nIndex >= -1) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     141       33896 :         return nIndex == -1 ? SvtSaveOptions::ODFVER_UNKNOWN : aMapEntries[nIndex].nEarliestODFVersionForExport;
     142             :     }
     143             : 
     144             :     /** Returns the index of an entry with the given XML-name and namespace
     145             :         If there is no matching entry the method returns -1 */
     146             :     sal_Int32 GetEntryIndex( sal_uInt16 nNamespace,
     147             :                                    const OUString& rStrName,
     148             :                                    sal_uInt32 nPropType,
     149             :                                    sal_Int32 nStartAt = -1 ) const;
     150             : 
     151             :     /** Retrieves a PropertyHandler for that property which placed at nIndex in the XMLPropertyMapEntry-array */
     152       25442 :     const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nIndex ) const
     153             :     {
     154             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     155       25442 :         return aMapEntries[nIndex].pHdl;
     156             :     }
     157             : 
     158             :     /** import/export
     159             :         This methods calls the respective im/export-method of the respective PropertyHandler. */
     160             :     virtual sal_Bool exportXML( OUString& rStrExpValue,
     161             :                                 const XMLPropertyState& rProperty,
     162             :                                 const SvXMLUnitConverter& rUnitConverter ) const;
     163             :     virtual sal_Bool importXML( const OUString& rStrImpValue,
     164             :                                 XMLPropertyState& rProperty,
     165             :                                 const SvXMLUnitConverter& rUnitConverter ) const;
     166             : 
     167             :     /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
     168             :     sal_Int32 FindEntryIndex( const sal_Char* sApiName,
     169             :                               sal_uInt16 nNameSpace,
     170             :                               const OUString& sXMLName ) const;
     171             : 
     172             :     /** searches for an entry that matches the given ContextId or gives -1 if nothing found */
     173             :     sal_Int32 FindEntryIndex( const sal_Int16 nContextId ) const;
     174             : 
     175             :     /** Remove an entry */
     176             :     void RemoveEntry( sal_Int32 nIndex );
     177             : };
     178             : 
     179             : #endif // _XMLOFF_PROPERTYSETMAPPER_HXX
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10