LCOV - code coverage report
Current view: top level - comphelper/source/misc - anycompare.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 23 115 20.0 %
Date: 2015-06-13 12:38:46 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           0 :     class DatePredicateLess : public IKeyPredicateLess
      61             :     {
      62             :     public:
      63           0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const SAL_OVERRIDE
      64             :         {
      65           0 :             Date lhs, rhs;
      66           0 :             if  (   !( _lhs >>= lhs )
      67           0 :                 ||  !( _rhs >>= rhs )
      68             :                 )
      69           0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
      70             :             // FIXME Timezone?
      71             : 
      72           0 :             if ( lhs.Year < rhs.Year )
      73           0 :                 return true;
      74           0 :             if ( lhs.Year > rhs.Year )
      75           0 :                 return false;
      76             : 
      77           0 :             if ( lhs.Month < rhs.Month )
      78           0 :                 return true;
      79           0 :             if ( lhs.Month > rhs.Month )
      80           0 :                 return false;
      81             : 
      82           0 :             if ( lhs.Day < rhs.Day )
      83           0 :                 return true;
      84           0 :             return false;
      85             :         }
      86             :     };
      87             : 
      88           0 :     class TimePredicateLess : public IKeyPredicateLess
      89             :     {
      90             :     public:
      91           0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const SAL_OVERRIDE
      92             :         {
      93           0 :             Time lhs, rhs;
      94           0 :             if  (   !( _lhs >>= lhs )
      95           0 :                 ||  !( _rhs >>= rhs )
      96             :                 )
      97           0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
      98             :             // FIXME Timezone?
      99             : 
     100           0 :             if ( lhs.Hours < rhs.Hours )
     101           0 :                 return true;
     102           0 :             if ( lhs.Hours > rhs.Hours )
     103           0 :                 return false;
     104             : 
     105           0 :             if ( lhs.Minutes < rhs.Minutes )
     106           0 :                 return true;
     107           0 :             if ( lhs.Minutes > rhs.Minutes )
     108           0 :                 return false;
     109             : 
     110           0 :             if ( lhs.Seconds < rhs.Seconds )
     111           0 :                 return true;
     112           0 :             if ( lhs.Seconds > rhs.Seconds )
     113           0 :                 return false;
     114             : 
     115           0 :             if ( lhs.NanoSeconds < rhs.NanoSeconds )
     116           0 :                 return true;
     117           0 :             return false;
     118             :         }
     119             :     };
     120             : 
     121           0 :     class DateTimePredicateLess : public IKeyPredicateLess
     122             :     {
     123             :     public:
     124           0 :         virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const SAL_OVERRIDE
     125             :         {
     126           0 :             DateTime lhs, rhs;
     127           0 :             if  (   !( _lhs >>= lhs )
     128           0 :                 ||  !( _rhs >>= rhs )
     129             :                 )
     130           0 :                 throw ::com::sun::star::lang::IllegalArgumentException();
     131             :             // FIXME Timezone?
     132             : 
     133           0 :             if ( lhs.Year < rhs.Year )
     134           0 :                 return true;
     135           0 :             if ( lhs.Year > rhs.Year )
     136           0 :                 return false;
     137             : 
     138           0 :             if ( lhs.Month < rhs.Month )
     139           0 :                 return true;
     140           0 :             if ( lhs.Month > rhs.Month )
     141           0 :                 return false;
     142             : 
     143           0 :             if ( lhs.Day < rhs.Day )
     144           0 :                 return true;
     145           0 :             if ( lhs.Day > rhs.Day )
     146           0 :                 return false;
     147             : 
     148           0 :             if ( lhs.Hours < rhs.Hours )
     149           0 :                 return true;
     150           0 :             if ( lhs.Hours > rhs.Hours )
     151           0 :                 return false;
     152             : 
     153           0 :             if ( lhs.Minutes < rhs.Minutes )
     154           0 :                 return true;
     155           0 :             if ( lhs.Minutes > rhs.Minutes )
     156           0 :                 return false;
     157             : 
     158           0 :             if ( lhs.Seconds < rhs.Seconds )
     159           0 :                 return true;
     160           0 :             if ( lhs.Seconds > rhs.Seconds )
     161           0 :                 return false;
     162             : 
     163           0 :             if ( lhs.NanoSeconds < rhs.NanoSeconds )
     164           0 :                 return true;
     165           0 :             return false;
     166             :         }
     167             :     };
     168             : 
     169             : 
     170          40 :     ::std::unique_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator )
     171             :     {
     172          40 :         ::std::unique_ptr< IKeyPredicateLess > pComparator;
     173          40 :         switch ( i_type.getTypeClass() )
     174             :         {
     175             :         case TypeClass_CHAR:
     176           0 :             pComparator.reset( new ScalarPredicateLess< sal_Unicode >() );
     177           0 :             break;
     178             :         case TypeClass_BOOLEAN:
     179           2 :             pComparator.reset( new ScalarPredicateLess< sal_Bool >() );
     180           2 :             break;
     181             :         case TypeClass_BYTE:
     182           0 :             pComparator.reset( new ScalarPredicateLess< sal_Int8 >() );
     183           0 :             break;
     184             :         case TypeClass_SHORT:
     185           0 :             pComparator.reset( new ScalarPredicateLess< sal_Int16 >() );
     186           0 :             break;
     187             :         case TypeClass_UNSIGNED_SHORT:
     188           0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt16 >() );
     189           0 :             break;
     190             :         case TypeClass_LONG:
     191          22 :             pComparator.reset( new ScalarPredicateLess< sal_Int32 >() );
     192          22 :             break;
     193             :         case TypeClass_UNSIGNED_LONG:
     194           0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt32 >() );
     195           0 :             break;
     196             :         case TypeClass_HYPER:
     197           2 :             pComparator.reset( new ScalarPredicateLess< sal_Int64 >() );
     198           2 :             break;
     199             :         case TypeClass_UNSIGNED_HYPER:
     200           0 :             pComparator.reset( new ScalarPredicateLess< sal_uInt64 >() );
     201           0 :             break;
     202             :         case TypeClass_FLOAT:
     203           2 :             pComparator.reset( new ScalarPredicateLess< float >() );
     204           2 :             break;
     205             :         case TypeClass_DOUBLE:
     206           3 :             pComparator.reset( new ScalarPredicateLess< double >() );
     207           3 :             break;
     208             :         case TypeClass_STRING:
     209           3 :             if ( i_collator.is() )
     210           0 :                 pComparator.reset( new StringCollationPredicateLess( i_collator ) );
     211             :             else
     212           3 :                 pComparator.reset( new StringPredicateLess() );
     213           3 :             break;
     214             :         case TypeClass_TYPE:
     215           2 :             pComparator.reset( new TypePredicateLess() );
     216           2 :             break;
     217             :         case TypeClass_ENUM:
     218           2 :             pComparator.reset( new EnumPredicateLess( i_type ) );
     219           2 :             break;
     220             :         case TypeClass_INTERFACE:
     221           2 :             pComparator.reset( new InterfacePredicateLess() );
     222           2 :             break;
     223             :         case TypeClass_STRUCT:
     224           0 :             if ( i_type.equals( ::cppu::UnoType< Date >::get() ) )
     225           0 :                 pComparator.reset( new DatePredicateLess() );
     226           0 :             else if ( i_type.equals( ::cppu::UnoType< Time >::get() ) )
     227           0 :                 pComparator.reset( new TimePredicateLess() );
     228           0 :             else if ( i_type.equals( ::cppu::UnoType< DateTime >::get() ) )
     229           0 :                 pComparator.reset( new DateTimePredicateLess() );
     230           0 :             break;
     231             :         default:
     232           0 :             break;
     233             :         }
     234          40 :         return pComparator;
     235             :     }
     236             : 
     237             : 
     238             : } // namespace comphelper
     239             : 
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11