LCOV - code coverage report
Current view: top level - unoxml/source/xpath - xpathobject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 48 87.5 %
Date: 2012-08-25 Functions: 12 12 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 77 48.1 %

           Branch data     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 <xpathobject.hxx>
      21                 :            : 
      22                 :            : #include <string.h>
      23                 :            : 
      24                 :            : #include "../dom/document.hxx"
      25                 :            : #include <nodelist.hxx>
      26                 :            : 
      27                 :            : 
      28                 :            : namespace XPath
      29                 :            : {
      30                 :      95146 :     static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
      31                 :            :     {
      32   [ -  +  +  +  :      95146 :         switch (pXPathObj->type)
          +  -  -  -  -  
                   -  - ]
      33                 :            :         {
      34                 :            :             case XPATH_UNDEFINED:
      35                 :          0 :                 return XPathObjectType_XPATH_UNDEFINED;
      36                 :            :             case XPATH_NODESET:
      37                 :      95132 :                 return XPathObjectType_XPATH_NODESET;
      38                 :            :             case XPATH_BOOLEAN:
      39                 :          4 :                 return XPathObjectType_XPATH_BOOLEAN;
      40                 :            :             case XPATH_NUMBER:
      41                 :          6 :                 return XPathObjectType_XPATH_NUMBER;
      42                 :            :             case XPATH_STRING:
      43                 :          4 :                 return XPathObjectType_XPATH_STRING;
      44                 :            :             case XPATH_POINT:
      45                 :          0 :                 return XPathObjectType_XPATH_POINT;
      46                 :            :             case XPATH_RANGE:
      47                 :          0 :                 return XPathObjectType_XPATH_RANGE;
      48                 :            :             case XPATH_LOCATIONSET:
      49                 :          0 :                 return XPathObjectType_XPATH_LOCATIONSET;
      50                 :            :             case XPATH_USERS:
      51                 :          0 :                 return XPathObjectType_XPATH_USERS;
      52                 :            :             case XPATH_XSLT_TREE:
      53                 :          0 :                 return XPathObjectType_XPATH_XSLT_TREE;
      54                 :            :             default:
      55                 :      95146 :                 return XPathObjectType_XPATH_UNDEFINED;
      56                 :            :         }
      57                 :            :     }
      58                 :            : 
      59                 :      95146 :     CXPathObject::CXPathObject(
      60                 :            :             ::rtl::Reference<DOM::CDocument> const& pDocument,
      61                 :            :             ::osl::Mutex & rMutex,
      62                 :            :             ::boost::shared_ptr<xmlXPathObject> const& pXPathObj)
      63                 :            :         : m_pDocument(pDocument)
      64                 :            :         , m_rMutex(rMutex)
      65                 :            :         , m_pXPathObj(pXPathObj)
      66         [ +  - ]:      95146 :         , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
      67                 :            :     {
      68                 :      95146 :     }
      69                 :            : 
      70                 :            :     /**
      71                 :            :         get object type
      72                 :            :     */
      73                 :         16 :     XPathObjectType CXPathObject::getObjectType() throw (RuntimeException)
      74                 :            :     {
      75                 :         16 :         return m_XPathObjectType;
      76                 :            :     }
      77                 :            : 
      78                 :            :     /**
      79                 :            :         get the nodes from a nodelist type object
      80                 :            :     */
      81                 :            :     Reference< XNodeList > SAL_CALL
      82                 :      95132 :     CXPathObject::getNodeList() throw (RuntimeException)
      83                 :            :     {
      84         [ +  - ]:      95132 :         ::osl::MutexGuard const g(m_rMutex);
      85                 :            : 
      86                 :            :         Reference< XNodeList > const xRet(
      87 [ +  - ][ +  - ]:      95132 :             new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
                 [ +  - ]
      88         [ +  - ]:      95132 :         return xRet;
      89                 :            :     }
      90                 :            : 
      91                 :            :      /**
      92                 :            :         get value of a boolean object
      93                 :            :      */
      94                 :          4 :     sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException)
      95                 :            :     {
      96         [ +  - ]:          4 :         ::osl::MutexGuard const g(m_rMutex);
      97                 :            : 
      98 [ +  - ][ +  - ]:          4 :         return (sal_Bool) xmlXPathCastToBoolean(m_pXPathObj.get());
      99                 :            :     }
     100                 :            : 
     101                 :            :     /**
     102                 :            :         get number as byte
     103                 :            :     */
     104                 :          2 :     sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException)
     105                 :            :     {
     106         [ +  - ]:          2 :         ::osl::MutexGuard const g(m_rMutex);
     107                 :            : 
     108 [ +  - ][ +  - ]:          2 :         return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
     109                 :            :     }
     110                 :            : 
     111                 :            :     /**
     112                 :            :         get number as short
     113                 :            :     */
     114                 :          2 :     sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException)
     115                 :            :     {
     116         [ +  - ]:          2 :         ::osl::MutexGuard const g(m_rMutex);
     117                 :            : 
     118 [ +  - ][ +  - ]:          2 :         return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
     119                 :            :     }
     120                 :            : 
     121                 :            :     /**
     122                 :            :         get number as long
     123                 :            :     */
     124                 :          6 :     sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException)
     125                 :            :     {
     126         [ +  - ]:          6 :         ::osl::MutexGuard const g(m_rMutex);
     127                 :            : 
     128 [ +  - ][ +  - ]:          6 :         return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
     129                 :            :     }
     130                 :            : 
     131                 :            :     /**
     132                 :            :         get number as hyper
     133                 :            :     */
     134                 :          2 :     sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException)
     135                 :            :     {
     136         [ +  - ]:          2 :         ::osl::MutexGuard const g(m_rMutex);
     137                 :            : 
     138 [ +  - ][ +  - ]:          2 :         return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
     139                 :            :     }
     140                 :            : 
     141                 :            :     /**
     142                 :            :         get number as float
     143                 :            :     */
     144                 :          2 :     float SAL_CALL CXPathObject::getFloat() throw (RuntimeException)
     145                 :            :     {
     146         [ +  - ]:          2 :         ::osl::MutexGuard const g(m_rMutex);
     147                 :            : 
     148 [ +  - ][ +  - ]:          2 :         return (float) xmlXPathCastToNumber(m_pXPathObj.get());
     149                 :            :     }
     150                 :            : 
     151                 :            :     /**
     152                 :            :         get number as double
     153                 :            :     */
     154                 :          2 :     double SAL_CALL CXPathObject::getDouble() throw (RuntimeException)
     155                 :            :     {
     156         [ +  - ]:          2 :         ::osl::MutexGuard const g(m_rMutex);
     157                 :            : 
     158 [ +  - ][ +  - ]:          2 :         return  xmlXPathCastToNumber(m_pXPathObj.get());
     159                 :            :     }
     160                 :            : 
     161                 :            :     /**
     162                 :            :         get string value
     163                 :            :     */
     164                 :         10 :     OUString SAL_CALL CXPathObject::getString() throw (RuntimeException)
     165                 :            :     {
     166         [ +  - ]:         10 :         ::osl::MutexGuard const g(m_rMutex);
     167                 :            : 
     168                 :            :         ::boost::shared_ptr<xmlChar const> str(
     169 [ +  - ][ +  - ]:         10 :             xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
     170                 :         10 :         sal_Char const*const pS(reinterpret_cast<sal_Char const*>(str.get()));
     171 [ +  - ][ +  - ]:         10 :         return OUString(pS, strlen(pS), RTL_TEXTENCODING_UTF8);
                 [ +  - ]
     172                 :            :     }
     173                 :            : 
     174                 :            : }
     175                 :            : 
     176                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10