1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/anycompare.hxx>
22 #include <com/sun/star/util/Date.hpp>
23 #include <com/sun/star/util/Time.hpp>
24 #include <com/sun/star/util/DateTime.hpp>
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
;
60 class DatePredicateLess
: public IKeyPredicateLess
63 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const SAL_OVERRIDE
66 if ( !( _lhs
>>= lhs
)
69 throw ::com::sun::star::lang::IllegalArgumentException();
72 if ( lhs
.Year
< rhs
.Year
)
74 if ( lhs
.Year
> rhs
.Year
)
77 if ( lhs
.Month
< rhs
.Month
)
79 if ( lhs
.Month
> rhs
.Month
)
82 if ( lhs
.Day
< rhs
.Day
)
88 class TimePredicateLess
: public IKeyPredicateLess
91 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const SAL_OVERRIDE
94 if ( !( _lhs
>>= lhs
)
97 throw ::com::sun::star::lang::IllegalArgumentException();
100 if ( lhs
.Hours
< rhs
.Hours
)
102 if ( lhs
.Hours
> rhs
.Hours
)
105 if ( lhs
.Minutes
< rhs
.Minutes
)
107 if ( lhs
.Minutes
> rhs
.Minutes
)
110 if ( lhs
.Seconds
< rhs
.Seconds
)
112 if ( lhs
.Seconds
> rhs
.Seconds
)
115 if ( lhs
.NanoSeconds
< rhs
.NanoSeconds
)
121 class DateTimePredicateLess
: public IKeyPredicateLess
124 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const SAL_OVERRIDE
127 if ( !( _lhs
>>= lhs
)
130 throw ::com::sun::star::lang::IllegalArgumentException();
133 if ( lhs
.Year
< rhs
.Year
)
135 if ( lhs
.Year
> rhs
.Year
)
138 if ( lhs
.Month
< rhs
.Month
)
140 if ( lhs
.Month
> rhs
.Month
)
143 if ( lhs
.Day
< rhs
.Day
)
145 if ( lhs
.Day
> rhs
.Day
)
148 if ( lhs
.Hours
< rhs
.Hours
)
150 if ( lhs
.Hours
> rhs
.Hours
)
153 if ( lhs
.Minutes
< rhs
.Minutes
)
155 if ( lhs
.Minutes
> rhs
.Minutes
)
158 if ( lhs
.Seconds
< rhs
.Seconds
)
160 if ( lhs
.Seconds
> rhs
.Seconds
)
163 if ( lhs
.NanoSeconds
< rhs
.NanoSeconds
)
170 ::std::unique_ptr
< IKeyPredicateLess
> getStandardLessPredicate( Type
const & i_type
, Reference
< XCollator
> const & i_collator
)
172 ::std::unique_ptr
< IKeyPredicateLess
> pComparator
;
173 switch ( i_type
.getTypeClass() )
176 pComparator
.reset( new ScalarPredicateLess
< sal_Unicode
>() );
178 case TypeClass_BOOLEAN
:
179 pComparator
.reset( new ScalarPredicateLess
< sal_Bool
>() );
182 pComparator
.reset( new ScalarPredicateLess
< sal_Int8
>() );
184 case TypeClass_SHORT
:
185 pComparator
.reset( new ScalarPredicateLess
< sal_Int16
>() );
187 case TypeClass_UNSIGNED_SHORT
:
188 pComparator
.reset( new ScalarPredicateLess
< sal_uInt16
>() );
191 pComparator
.reset( new ScalarPredicateLess
< sal_Int32
>() );
193 case TypeClass_UNSIGNED_LONG
:
194 pComparator
.reset( new ScalarPredicateLess
< sal_uInt32
>() );
196 case TypeClass_HYPER
:
197 pComparator
.reset( new ScalarPredicateLess
< sal_Int64
>() );
199 case TypeClass_UNSIGNED_HYPER
:
200 pComparator
.reset( new ScalarPredicateLess
< sal_uInt64
>() );
202 case TypeClass_FLOAT
:
203 pComparator
.reset( new ScalarPredicateLess
< float >() );
205 case TypeClass_DOUBLE
:
206 pComparator
.reset( new ScalarPredicateLess
< double >() );
208 case TypeClass_STRING
:
209 if ( i_collator
.is() )
210 pComparator
.reset( new StringCollationPredicateLess( i_collator
) );
212 pComparator
.reset( new StringPredicateLess() );
215 pComparator
.reset( new TypePredicateLess() );
218 pComparator
.reset( new EnumPredicateLess( i_type
) );
220 case TypeClass_INTERFACE
:
221 pComparator
.reset( new InterfacePredicateLess() );
223 case TypeClass_STRUCT
:
224 if ( i_type
.equals( ::cppu::UnoType
< Date
>::get() ) )
225 pComparator
.reset( new DatePredicateLess() );
226 else if ( i_type
.equals( ::cppu::UnoType
< Time
>::get() ) )
227 pComparator
.reset( new TimePredicateLess() );
228 else if ( i_type
.equals( ::cppu::UnoType
< DateTime
>::get() ) )
229 pComparator
.reset( new DateTimePredicateLess() );
238 } // namespace comphelper
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */