LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/style - XMLConstantsPropertyHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 24 91.7 %
Date: 2012-12-27 Functions: 5 5 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             : #include <xmloff/xmluconv.hxx>
      21             : #include <rtl/ustrbuf.hxx>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : #include <xmloff/XMLConstantsPropertyHandler.hxx>
      24             : 
      25             : using namespace ::com::sun::star::uno;
      26             : using ::rtl::OUString;
      27             : using ::rtl::OUStringBuffer;
      28             : 
      29             : using ::xmloff::token::XMLTokenEnum;
      30             : 
      31        4011 : XMLConstantsPropertyHandler::XMLConstantsPropertyHandler(
      32             :     const SvXMLEnumMapEntry *pM,
      33             :     enum XMLTokenEnum eDflt ) :
      34             :         pMap( pM ),
      35        4011 :         eDefault( eDflt )
      36             : {
      37        4011 : }
      38             : 
      39        7913 : XMLConstantsPropertyHandler::~XMLConstantsPropertyHandler()
      40             : {
      41        7913 : }
      42             : 
      43         179 : sal_Bool XMLConstantsPropertyHandler::importXML(
      44             :     const OUString& rStrImpValue,
      45             :     Any& rValue,
      46             :     const SvXMLUnitConverter& ) const
      47             : {
      48             :     sal_uInt16 nEnum;
      49             :     sal_Bool bRet = SvXMLUnitConverter::convertEnum(
      50         179 :         nEnum, rStrImpValue, pMap );
      51             : 
      52         179 :     if( bRet )
      53         172 :         rValue <<= (sal_Int16)nEnum;
      54             : 
      55         179 :     return bRet;
      56             : }
      57             : 
      58          17 : sal_Bool XMLConstantsPropertyHandler::exportXML(
      59             :     OUString& rStrExpValue,
      60             :     const Any& rValue,
      61             :     const SvXMLUnitConverter& ) const
      62             : {
      63          17 :     OUStringBuffer aOut;
      64             : 
      65          17 :     sal_Bool bRet = false;
      66             : 
      67          17 :     sal_Int32 nEnum = 0;
      68             : 
      69          17 :     if( rValue.hasValue() && (rValue.getValueTypeClass() == TypeClass_ENUM))
      70             :     {
      71           0 :         nEnum = *((sal_Int32*)rValue.getValue());
      72           0 :         bRet = true;
      73             :     }
      74             :     else
      75             :     {
      76          17 :         bRet = (rValue >>= nEnum );
      77             :     }
      78             : 
      79          17 :     if( bRet )
      80             :     {
      81          17 :         if( (nEnum >= 0) && (nEnum <= 0xffff) )
      82             :         {
      83          17 :             sal_uInt16 nConst = static_cast<sal_uInt16>( nEnum );
      84             : 
      85             :             bRet = SvXMLUnitConverter::convertEnum(
      86          17 :                 aOut, nConst, pMap, eDefault );
      87             : 
      88          17 :             rStrExpValue = aOut.makeStringAndClear();
      89             :         }
      90             :         else
      91             :         {
      92             :             OSL_FAIL("XMLConstantsPropertyHandler::exportXML() constant is out of range for implementation using sal_uInt16");
      93             :         }
      94             :     }
      95             :     else
      96             :     {
      97             :         OSL_FAIL("XMLConstantsPropertyHandler::exportXML() could not convert any to sal_Int32");
      98             :     }
      99             : 
     100          17 :     return bRet;
     101             : }
     102             : 
     103             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10