LCOV - code coverage report
Current view: top level - libreoffice/unoxml/source/xpath - xpathobject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 48 20.8 %
Date: 2012-12-27 Functions: 3 12 25.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 <xpathobject.hxx>
      21             : 
      22             : #include <string.h>
      23             : 
      24             : #include "../dom/document.hxx"
      25             : #include <nodelist.hxx>
      26             : 
      27             : 
      28             : namespace XPath
      29             : {
      30       22105 :     static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
      31             :     {
      32       22105 :         switch (pXPathObj->type)
      33             :         {
      34             :             case XPATH_UNDEFINED:
      35           0 :                 return XPathObjectType_XPATH_UNDEFINED;
      36             :             case XPATH_NODESET:
      37       22105 :                 return XPathObjectType_XPATH_NODESET;
      38             :             case XPATH_BOOLEAN:
      39           0 :                 return XPathObjectType_XPATH_BOOLEAN;
      40             :             case XPATH_NUMBER:
      41           0 :                 return XPathObjectType_XPATH_NUMBER;
      42             :             case XPATH_STRING:
      43           0 :                 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           0 :                 return XPathObjectType_XPATH_UNDEFINED;
      56             :         }
      57             :     }
      58             : 
      59       22105 :     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       22105 :         , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
      67             :     {
      68       22105 :     }
      69             : 
      70             :     /**
      71             :         get object type
      72             :     */
      73           0 :     XPathObjectType CXPathObject::getObjectType() throw (RuntimeException)
      74             :     {
      75           0 :         return m_XPathObjectType;
      76             :     }
      77             : 
      78             :     /**
      79             :         get the nodes from a nodelist type object
      80             :     */
      81             :     Reference< XNodeList > SAL_CALL
      82       22105 :     CXPathObject::getNodeList() throw (RuntimeException)
      83             :     {
      84       22105 :         ::osl::MutexGuard const g(m_rMutex);
      85             : 
      86             :         Reference< XNodeList > const xRet(
      87       22105 :             new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
      88       22105 :         return xRet;
      89             :     }
      90             : 
      91             :      /**
      92             :         get value of a boolean object
      93             :      */
      94           0 :     sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException)
      95             :     {
      96           0 :         ::osl::MutexGuard const g(m_rMutex);
      97             : 
      98           0 :         return (sal_Bool) xmlXPathCastToBoolean(m_pXPathObj.get());
      99             :     }
     100             : 
     101             :     /**
     102             :         get number as byte
     103             :     */
     104           0 :     sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException)
     105             :     {
     106           0 :         ::osl::MutexGuard const g(m_rMutex);
     107             : 
     108           0 :         return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
     109             :     }
     110             : 
     111             :     /**
     112             :         get number as short
     113             :     */
     114           0 :     sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException)
     115             :     {
     116           0 :         ::osl::MutexGuard const g(m_rMutex);
     117             : 
     118           0 :         return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
     119             :     }
     120             : 
     121             :     /**
     122             :         get number as long
     123             :     */
     124           0 :     sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException)
     125             :     {
     126           0 :         ::osl::MutexGuard const g(m_rMutex);
     127             : 
     128           0 :         return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
     129             :     }
     130             : 
     131             :     /**
     132             :         get number as hyper
     133             :     */
     134           0 :     sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException)
     135             :     {
     136           0 :         ::osl::MutexGuard const g(m_rMutex);
     137             : 
     138           0 :         return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
     139             :     }
     140             : 
     141             :     /**
     142             :         get number as float
     143             :     */
     144           0 :     float SAL_CALL CXPathObject::getFloat() throw (RuntimeException)
     145             :     {
     146           0 :         ::osl::MutexGuard const g(m_rMutex);
     147             : 
     148           0 :         return (float) xmlXPathCastToNumber(m_pXPathObj.get());
     149             :     }
     150             : 
     151             :     /**
     152             :         get number as double
     153             :     */
     154           0 :     double SAL_CALL CXPathObject::getDouble() throw (RuntimeException)
     155             :     {
     156           0 :         ::osl::MutexGuard const g(m_rMutex);
     157             : 
     158           0 :         return  xmlXPathCastToNumber(m_pXPathObj.get());
     159             :     }
     160             : 
     161             :     /**
     162             :         get string value
     163             :     */
     164           0 :     OUString SAL_CALL CXPathObject::getString() throw (RuntimeException)
     165             :     {
     166           0 :         ::osl::MutexGuard const g(m_rMutex);
     167             : 
     168             :         ::boost::shared_ptr<xmlChar const> str(
     169           0 :             xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
     170           0 :         sal_Char const*const pS(reinterpret_cast<sal_Char const*>(str.get()));
     171           0 :         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