LCOV - code coverage report
Current view: top level - configmgr/source - type.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 30 62 48.4 %
Date: 2014-04-11 Functions: 4 4 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 "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include "com/sun/star/uno/Any.hxx"
      25             : #include "com/sun/star/uno/Reference.hxx"
      26             : #include "com/sun/star/uno/RuntimeException.hpp"
      27             : #include "com/sun/star/uno/Sequence.hxx"
      28             : #include "com/sun/star/uno/Type.hxx"
      29             : #include "com/sun/star/uno/TypeClass.hpp"
      30             : #include "com/sun/star/uno/XInterface.hpp"
      31             : #include "cppu/unotype.hxx"
      32             : #include "rtl/string.h"
      33             : #include "rtl/ustring.h"
      34             : #include "rtl/ustring.hxx"
      35             : #include "sal/types.h"
      36             : 
      37             : #include "type.hxx"
      38             : 
      39             : namespace configmgr {
      40             : 
      41       26568 : bool isListType(Type type) {
      42       26568 :     return type >= TYPE_BOOLEAN_LIST;
      43             : }
      44             : 
      45       26568 : Type elementType(Type type) {
      46       26568 :     switch (type) {
      47             :     case TYPE_BOOLEAN_LIST:
      48           0 :         return TYPE_BOOLEAN;
      49             :     case TYPE_SHORT_LIST:
      50           0 :         return TYPE_SHORT;
      51             :     case TYPE_INT_LIST:
      52           0 :         return TYPE_INT;
      53             :     case TYPE_LONG_LIST:
      54           0 :         return TYPE_LONG;
      55             :     case TYPE_DOUBLE_LIST:
      56           0 :         return TYPE_DOUBLE;
      57             :     case TYPE_STRING_LIST:
      58       26568 :         return TYPE_STRING;
      59             :     case TYPE_HEXBINARY_LIST:
      60           0 :         return TYPE_HEXBINARY;
      61             :     default:
      62             :         assert(false);
      63             :         throw css::uno::RuntimeException(
      64             :             "this cannot happen",
      65           0 :             css::uno::Reference< css::uno::XInterface >());
      66             :     }
      67             : }
      68             : 
      69       76787 : css::uno::Type mapType(Type type) {
      70       76787 :     switch (type) {
      71             :     case TYPE_ANY:
      72           0 :         return cppu::UnoType< css::uno::Any >::get();
      73             :     case TYPE_BOOLEAN:
      74       29849 :         return cppu::UnoType< sal_Bool >::get();
      75             :     case TYPE_SHORT:
      76         864 :         return cppu::UnoType< sal_Int16 >::get();
      77             :     case TYPE_INT:
      78        4681 :         return cppu::UnoType< sal_Int32 >::get();
      79             :     case TYPE_LONG:
      80           0 :         return cppu::UnoType< sal_Int64 >::get();
      81             :     case TYPE_DOUBLE:
      82           0 :         return cppu::UnoType< double >::get();
      83             :     case TYPE_STRING:
      84       41146 :         return cppu::UnoType< OUString >::get();
      85             :     case TYPE_HEXBINARY:
      86           0 :         return cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get();
      87             :     case TYPE_BOOLEAN_LIST:
      88           0 :         return cppu::UnoType< css::uno::Sequence< sal_Bool > >::get();
      89             :     case TYPE_SHORT_LIST:
      90           0 :         return cppu::UnoType< css::uno::Sequence< sal_Int16 > >::get();
      91             :     case TYPE_INT_LIST:
      92           1 :         return cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get();
      93             :     case TYPE_LONG_LIST:
      94           0 :         return cppu::UnoType< css::uno::Sequence< sal_Int64 > >::get();
      95             :     case TYPE_DOUBLE_LIST:
      96           0 :         return cppu::UnoType< css::uno::Sequence< double > >::get();
      97             :     case TYPE_STRING_LIST:
      98         246 :         return cppu::UnoType< css::uno::Sequence< OUString > >::get();
      99             :     case TYPE_HEXBINARY_LIST:
     100             :         return cppu::UnoType<
     101           0 :             css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
     102             :     default:
     103             :         assert(false);
     104             :         throw css::uno::RuntimeException(
     105             :             "this cannot happen",
     106           0 :             css::uno::Reference< css::uno::XInterface >());
     107             :     }
     108             : }
     109             : 
     110      159400 : Type getDynamicType(css::uno::Any const & value) {
     111      159400 :     switch (value.getValueType().getTypeClass()) {
     112             :     case css::uno::TypeClass_VOID:
     113       12990 :         return TYPE_NIL;
     114             :     case css::uno::TypeClass_BOOLEAN:
     115       42740 :         return TYPE_BOOLEAN;
     116             :     case css::uno::TypeClass_BYTE:
     117           0 :         return TYPE_SHORT;
     118             :     case css::uno::TypeClass_SHORT:
     119        5481 :         return TYPE_SHORT;
     120             :     case css::uno::TypeClass_UNSIGNED_SHORT:
     121           0 :         return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
     122             :     case css::uno::TypeClass_LONG:
     123        4418 :         return TYPE_INT;
     124             :     case css::uno::TypeClass_UNSIGNED_LONG:
     125           0 :         return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
     126             :     case css::uno::TypeClass_HYPER:
     127           0 :         return TYPE_LONG;
     128             :     case css::uno::TypeClass_UNSIGNED_HYPER:
     129           0 :         return value.has< sal_Int64 >() ? TYPE_LONG : TYPE_ERROR;
     130             :     case css::uno::TypeClass_FLOAT:
     131             :     case css::uno::TypeClass_DOUBLE:
     132           0 :         return TYPE_DOUBLE;
     133             :     case css::uno::TypeClass_STRING:
     134       41011 :         return TYPE_STRING;
     135             :     case css::uno::TypeClass_SEQUENCE: //TODO
     136             :         {
     137       52760 :             OUString name(value.getValueType().getTypeName());
     138       52760 :             if ( name == "[]byte" ) {
     139           0 :                 return TYPE_HEXBINARY;
     140       52760 :             } else if (name == "[]boolean")
     141             :             {
     142           0 :                 return TYPE_BOOLEAN_LIST;
     143       52760 :             } else if ( name == "[]short" )
     144             :             {
     145           0 :                 return TYPE_SHORT_LIST;
     146       52760 :             } else if ( name == "[]long" )
     147             :             {
     148           2 :                 return TYPE_INT_LIST;
     149       52758 :             } else if ( name == "[]hyper" )
     150             :             {
     151           0 :                 return TYPE_LONG_LIST;
     152       52758 :             } else if (name == "[]double")
     153             :             {
     154           0 :                 return TYPE_DOUBLE_LIST;
     155       52758 :             } else if (name == "[]string")
     156             :             {
     157       52758 :                 return TYPE_STRING_LIST;
     158           0 :             } else if (name == "[][]byte")
     159             :             {
     160           0 :                 return TYPE_HEXBINARY_LIST;
     161           0 :             }
     162             :         }
     163             :         // fall through
     164             :     default:
     165           0 :         return TYPE_ERROR;
     166             :     }
     167             : }
     168             : 
     169             : }
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10