LCOV - code coverage report
Current view: top level - comphelper/source/misc - anycompare.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 115 20.0 %
Date: 2012-08-25 Functions: 1 13 7.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 157 12.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 "comphelper/anycompare.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/util/Date.hpp>
      23                 :            : #include <com/sun/star/util/Time.hpp>
      24                 :            : #include <com/sun/star/util/DateTime.hpp>
      25                 :            : 
      26                 :            : namespace comphelper
      27                 :            : {
      28                 :            :     /** === begin UNO using === **/
      29                 :            :     using ::com::sun::star::uno::Reference;
      30                 :            :     using ::com::sun::star::uno::XInterface;
      31                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      32                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      33                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      34                 :            :     using ::com::sun::star::uno::Exception;
      35                 :            :     using ::com::sun::star::uno::RuntimeException;
      36                 :            :     using ::com::sun::star::uno::Any;
      37                 :            :     using ::com::sun::star::uno::makeAny;
      38                 :            :     using ::com::sun::star::uno::Sequence;
      39                 :            :     using ::com::sun::star::uno::Type;
      40                 :            :     using ::com::sun::star::uno::TypeClass_CHAR;
      41                 :            :     using ::com::sun::star::uno::TypeClass_BOOLEAN;
      42                 :            :     using ::com::sun::star::uno::TypeClass_BYTE;
      43                 :            :     using ::com::sun::star::uno::TypeClass_SHORT;
      44                 :            :     using ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT;
      45                 :            :     using ::com::sun::star::uno::TypeClass_LONG;
      46                 :            :     using ::com::sun::star::uno::TypeClass_UNSIGNED_LONG;
      47                 :            :     using ::com::sun::star::uno::TypeClass_HYPER;
      48                 :            :     using ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER;
      49                 :            :     using ::com::sun::star::uno::TypeClass_FLOAT;
      50                 :            :     using ::com::sun::star::uno::TypeClass_DOUBLE;
      51                 :            :     using ::com::sun::star::uno::TypeClass_STRING;
      52                 :            :     using ::com::sun::star::uno::TypeClass_TYPE;
      53                 :            :     using ::com::sun::star::uno::TypeClass_ENUM;
      54                 :            :     using ::com::sun::star::uno::TypeClass_INTERFACE;
      55                 :            :     using ::com::sun::star::uno::TypeClass_STRUCT;
      56                 :            :     using ::com::sun::star::i18n::XCollator;
      57                 :            :     using ::com::sun::star::util::Date;
      58                 :            :     using ::com::sun::star::util::Time;
      59                 :            :     using ::com::sun::star::util::DateTime;
      60                 :            :     /** === end UNO using === **/
      61                 :            : 
      62                 :            :     //==================================================================================================================
      63                 :            :     //= DatePredicateLess
      64                 :            :     //==================================================================================================================
      65         [ #  # ]:          0 :     class DatePredicateLess : public IKeyPredicateLess
      66                 :            :     {
      67                 :            :     public:
      68                 :          0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
      69                 :            :         {
      70                 :          0 :             Date lhs, rhs;
      71 [ #  # ][ #  # ]:          0 :             if  (   !( _lhs >>= lhs )
         [ #  # ][ #  # ]
      72         [ #  # ]:          0 :                 ||  !( _rhs >>= rhs )
      73                 :            :                 )
      74         [ #  # ]:          0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
      75                 :            : 
      76         [ #  # ]:          0 :             if ( lhs.Year < rhs.Year )
      77                 :          0 :                 return true;
      78         [ #  # ]:          0 :             if ( lhs.Year > rhs.Year )
      79                 :          0 :                 return false;
      80                 :            : 
      81         [ #  # ]:          0 :             if ( lhs.Month < rhs.Month )
      82                 :          0 :                 return true;
      83         [ #  # ]:          0 :             if ( lhs.Month > rhs.Month )
      84                 :          0 :                 return false;
      85                 :            : 
      86         [ #  # ]:          0 :             if ( lhs.Day < rhs.Day )
      87                 :          0 :                 return true;
      88                 :          0 :             return false;
      89                 :            :         }
      90                 :            :     };
      91                 :            : 
      92                 :            :     //==================================================================================================================
      93                 :            :     //= TimePredicateLess
      94                 :            :     //==================================================================================================================
      95         [ #  # ]:          0 :     class TimePredicateLess : public IKeyPredicateLess
      96                 :            :     {
      97                 :            :     public:
      98                 :          0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
      99                 :            :         {
     100                 :          0 :             Time lhs, rhs;
     101 [ #  # ][ #  # ]:          0 :             if  (   !( _lhs >>= lhs )
         [ #  # ][ #  # ]
     102         [ #  # ]:          0 :                 ||  !( _rhs >>= rhs )
     103                 :            :                 )
     104         [ #  # ]:          0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
     105                 :            : 
     106         [ #  # ]:          0 :             if ( lhs.Hours < rhs.Hours )
     107                 :          0 :                 return true;
     108         [ #  # ]:          0 :             if ( lhs.Hours > rhs.Hours )
     109                 :          0 :                 return false;
     110                 :            : 
     111         [ #  # ]:          0 :             if ( lhs.Minutes < rhs.Minutes )
     112                 :          0 :                 return true;
     113         [ #  # ]:          0 :             if ( lhs.Minutes > rhs.Minutes )
     114                 :          0 :                 return false;
     115                 :            : 
     116         [ #  # ]:          0 :             if ( lhs.Seconds < rhs.Seconds )
     117                 :          0 :                 return true;
     118         [ #  # ]:          0 :             if ( lhs.Seconds > rhs.Seconds )
     119                 :          0 :                 return false;
     120                 :            : 
     121         [ #  # ]:          0 :             if ( lhs.HundredthSeconds < rhs.HundredthSeconds )
     122                 :          0 :                 return true;
     123                 :          0 :             return false;
     124                 :            :         }
     125                 :            :     };
     126                 :            : 
     127                 :            :     //==================================================================================================================
     128                 :            :     //= DateTimePredicateLess
     129                 :            :     //==================================================================================================================
     130         [ #  # ]:          0 :     class DateTimePredicateLess : public IKeyPredicateLess
     131                 :            :     {
     132                 :            :     public:
     133                 :          0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
     134                 :            :         {
     135                 :          0 :             DateTime lhs, rhs;
     136 [ #  # ][ #  # ]:          0 :             if  (   !( _lhs >>= lhs )
         [ #  # ][ #  # ]
     137         [ #  # ]:          0 :                 ||  !( _rhs >>= rhs )
     138                 :            :                 )
     139         [ #  # ]:          0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
     140                 :            : 
     141         [ #  # ]:          0 :             if ( lhs.Year < rhs.Year )
     142                 :          0 :                 return true;
     143         [ #  # ]:          0 :             if ( lhs.Year > rhs.Year )
     144                 :          0 :                 return false;
     145                 :            : 
     146         [ #  # ]:          0 :             if ( lhs.Month < rhs.Month )
     147                 :          0 :                 return true;
     148         [ #  # ]:          0 :             if ( lhs.Month > rhs.Month )
     149                 :          0 :                 return false;
     150                 :            : 
     151         [ #  # ]:          0 :             if ( lhs.Day < rhs.Day )
     152                 :          0 :                 return true;
     153         [ #  # ]:          0 :             if ( lhs.Day > rhs.Day )
     154                 :          0 :                 return false;
     155                 :            : 
     156         [ #  # ]:          0 :             if ( lhs.Hours < rhs.Hours )
     157                 :          0 :                 return true;
     158         [ #  # ]:          0 :             if ( lhs.Hours > rhs.Hours )
     159                 :          0 :                 return false;
     160                 :            : 
     161         [ #  # ]:          0 :             if ( lhs.Minutes < rhs.Minutes )
     162                 :          0 :                 return true;
     163         [ #  # ]:          0 :             if ( lhs.Minutes > rhs.Minutes )
     164                 :          0 :                 return false;
     165                 :            : 
     166         [ #  # ]:          0 :             if ( lhs.Seconds < rhs.Seconds )
     167                 :          0 :                 return true;
     168         [ #  # ]:          0 :             if ( lhs.Seconds > rhs.Seconds )
     169                 :          0 :                 return false;
     170                 :            : 
     171         [ #  # ]:          0 :             if ( lhs.HundredthSeconds < rhs.HundredthSeconds )
     172                 :          0 :                 return true;
     173                 :          0 :             return false;
     174                 :            :         }
     175                 :            :     };
     176                 :            : 
     177                 :            :     //------------------------------------------------------------------------------------------------------------------
     178                 :         68 :     ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator )
     179                 :            :     {
     180                 :            :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     181                 :         68 :         ::std::auto_ptr< IKeyPredicateLess > pComparator;
     182                 :            :         SAL_WNODEPRECATED_DECLARATIONS_POP
     183   [ -  +  -  -  :         68 :         switch ( i_type.getTypeClass() )
          -  +  -  +  -  
          +  +  +  +  +  
                +  -  - ]
     184                 :            :         {
     185                 :            :         case TypeClass_CHAR:
     186         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_Unicode >() );
     187                 :          0 :             break;
     188                 :            :         case TypeClass_BOOLEAN:
     189         [ +  - ]:          4 :             pComparator.reset( new ScalarPredicateLess< sal_Bool >() );
     190                 :          4 :             break;
     191                 :            :         case TypeClass_BYTE:
     192         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_Int8 >() );
     193                 :          0 :             break;
     194                 :            :         case TypeClass_SHORT:
     195         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_Int16 >() );
     196                 :          0 :             break;
     197                 :            :         case TypeClass_UNSIGNED_SHORT:
     198         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt16 >() );
     199                 :          0 :             break;
     200                 :            :         case TypeClass_LONG:
     201         [ +  - ]:         32 :             pComparator.reset( new ScalarPredicateLess< sal_Int32 >() );
     202                 :         32 :             break;
     203                 :            :         case TypeClass_UNSIGNED_LONG:
     204         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt32 >() );
     205                 :          0 :             break;
     206                 :            :         case TypeClass_HYPER:
     207         [ +  - ]:          4 :             pComparator.reset( new ScalarPredicateLess< sal_Int64 >() );
     208                 :          4 :             break;
     209                 :            :         case TypeClass_UNSIGNED_HYPER:
     210         [ #  # ]:          0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt64 >() );
     211                 :          0 :             break;
     212                 :            :         case TypeClass_FLOAT:
     213         [ +  - ]:          4 :             pComparator.reset( new ScalarPredicateLess< float >() );
     214                 :          4 :             break;
     215                 :            :         case TypeClass_DOUBLE:
     216         [ +  - ]:          6 :             pComparator.reset( new ScalarPredicateLess< double >() );
     217                 :          6 :             break;
     218                 :            :         case TypeClass_STRING:
     219         [ -  + ]:          6 :             if ( i_collator.is() )
     220 [ #  # ][ #  # ]:          0 :                 pComparator.reset( new StringCollationPredicateLess( i_collator ) );
     221                 :            :             else
     222         [ +  - ]:          6 :                 pComparator.reset( new StringPredicateLess() );
     223                 :          6 :             break;
     224                 :            :         case TypeClass_TYPE:
     225         [ +  - ]:          4 :             pComparator.reset( new TypePredicateLess() );
     226                 :          4 :             break;
     227                 :            :         case TypeClass_ENUM:
     228         [ +  - ]:          4 :             pComparator.reset( new EnumPredicateLess( i_type ) );
     229                 :          4 :             break;
     230                 :            :         case TypeClass_INTERFACE:
     231         [ +  - ]:          4 :             pComparator.reset( new InterfacePredicateLess() );
     232                 :          4 :             break;
     233                 :            :         case TypeClass_STRUCT:
     234         [ #  # ]:          0 :             if ( i_type.equals( ::cppu::UnoType< Date >::get() ) )
     235         [ #  # ]:          0 :                 pComparator.reset( new DatePredicateLess() );
     236         [ #  # ]:          0 :             else if ( i_type.equals( ::cppu::UnoType< Time >::get() ) )
     237         [ #  # ]:          0 :                 pComparator.reset( new TimePredicateLess() );
     238         [ #  # ]:          0 :             else if ( i_type.equals( ::cppu::UnoType< DateTime >::get() ) )
     239         [ #  # ]:          0 :                 pComparator.reset( new DateTimePredicateLess() );
     240                 :          0 :             break;
     241                 :            :         default:
     242                 :          0 :             break;
     243                 :            :         }
     244                 :         68 :         return pComparator;
     245                 :            :     }
     246                 :            : 
     247                 :            : //......................................................................................................................
     248                 :            : } // namespace comphelper
     249                 :            : //......................................................................................................................
     250                 :            : 
     251                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10