LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/registry_tdprovider - methoddescription.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 34 85.3 %
Date: 2012-12-27 Functions: 11 12 91.7 %
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 "methoddescription.hxx"
      22             : 
      23             : #include "com/sun/star/container/NoSuchElementException.hpp"
      24             : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      25             : #include "com/sun/star/reflection/XParameter.hpp"
      26             : #include "com/sun/star/reflection/XTypeDescription.hpp"
      27             : #include "com/sun/star/uno/Reference.hxx"
      28             : #include "com/sun/star/uno/RuntimeException.hpp"
      29             : #include "com/sun/star/uno/Sequence.hxx"
      30             : #include "cppuhelper/implbase1.hxx"
      31             : #include "cppuhelper/weak.hxx"
      32             : #include "osl/mutex.hxx"
      33             : #include "registry/reader.hxx"
      34             : #include "registry/types.h"
      35             : #include "rtl/ustring.hxx"
      36             : #include "sal/types.h"
      37             : 
      38             : using stoc::registry_tdprovider::MethodDescription;
      39             : 
      40             : namespace {
      41             : 
      42             : class Parameter: public cppu::WeakImplHelper1< css::reflection::XParameter > {
      43             : public:
      44        1320 :     Parameter(
      45             :         css::uno::Reference< css::container::XHierarchicalNameAccess > const &
      46             :             manager,
      47             :         rtl::OUString const & name, rtl::OUString const & typeName,
      48             :         RTParamMode mode, sal_Int32 position):
      49             :         m_manager(manager), m_name(name),
      50             :         m_typeName(typeName.replace('/', '.')), m_mode(mode),
      51        1320 :         m_position(position) {}
      52             : 
      53        2448 :     virtual ~Parameter() {}
      54             : 
      55        1320 :     virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException)
      56        1320 :     { return m_name; }
      57             : 
      58             :     virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
      59             :     getType() throw (css::uno::RuntimeException);
      60             : 
      61        1320 :     virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException)
      62        1320 :     { return (m_mode & RT_PARAM_IN) != 0; }
      63             : 
      64        1320 :     virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException)
      65        1320 :     { return (m_mode & RT_PARAM_OUT) != 0; }
      66             : 
      67        1320 :     virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException)
      68        1320 :     { return m_position; }
      69             : 
      70           0 :     virtual sal_Bool SAL_CALL isRestParameter()
      71             :         throw (css::uno::RuntimeException)
      72           0 :     { return (m_mode & RT_PARAM_REST) != 0; }
      73             : 
      74             : private:
      75             :     Parameter(Parameter &); // not implemented
      76             :     void operator =(Parameter); // not implemented
      77             : 
      78             :     css::uno::Reference< css::container::XHierarchicalNameAccess > m_manager;
      79             :     rtl::OUString m_name;
      80             :     rtl::OUString m_typeName;
      81             :     RTParamMode m_mode;
      82             :     sal_Int32 m_position;
      83             : };
      84             : 
      85        1320 : css::uno::Reference< css::reflection::XTypeDescription > Parameter::getType()
      86             :     throw (css::uno::RuntimeException)
      87             : {
      88             :     try {
      89             :         return css::uno::Reference< css::reflection::XTypeDescription >(
      90        1320 :             m_manager->getByHierarchicalName(m_typeName),
      91        1320 :             css::uno::UNO_QUERY_THROW);
      92           0 :     } catch (const css::container::NoSuchElementException & e) {
      93             :         throw new css::uno::RuntimeException(
      94             :             (rtl::OUString(
      95             :                 RTL_CONSTASCII_USTRINGPARAM(
      96             :                     "com.sun.star.container.NoSuchElementException: "))
      97           0 :              + e.Message),
      98           0 :             static_cast< cppu::OWeakObject * >(this));
      99             :     }
     100             : }
     101             : 
     102             : }
     103             : 
     104       10166 : MethodDescription::MethodDescription(
     105             :     css::uno::Reference< css::container::XHierarchicalNameAccess > const &
     106             :         manager,
     107             :     rtl::OUString const & name,
     108             :     com::sun::star::uno::Sequence< sal_Int8 > const & bytes,
     109             :     sal_uInt16 index):
     110             :     FunctionDescription(manager, bytes, index), m_name(name),
     111       10166 :     m_parametersInit(false)
     112       10166 : {}
     113             : 
     114       10085 : MethodDescription::~MethodDescription() {}
     115             : 
     116             : css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
     117        1463 : MethodDescription::getParameters() const {
     118        1463 :     osl::MutexGuard guard(m_mutex);
     119        1463 :     if (!m_parametersInit) {
     120        1463 :         typereg::Reader reader(getReader());
     121        1463 :         sal_uInt16 n = reader.getMethodParameterCount(m_index);
     122        1463 :         m_parameters.realloc(n);
     123        2783 :         for (sal_uInt16 i = 0; i < n; ++i) {
     124        1320 :             m_parameters[i] = new Parameter(
     125             :                 m_manager, reader.getMethodParameterName(m_index, i),
     126             :                 reader.getMethodParameterTypeName(m_index, i),
     127        2640 :                 reader.getMethodParameterFlags(m_index, i), i);
     128             :         }
     129        1463 :         m_parametersInit = true;
     130             :     }
     131        1463 :     return m_parameters;
     132             : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10