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

Generated by: LCOV version 1.10