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 //==================================================================================================================
62 //==================================================================================================================
63 class DatePredicateLess
: public IKeyPredicateLess
66 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const
69 if ( !( _lhs
>>= lhs
)
72 throw ::com::sun::star::lang::IllegalArgumentException();
75 if ( lhs
.Year
< rhs
.Year
)
77 if ( lhs
.Year
> rhs
.Year
)
80 if ( lhs
.Month
< rhs
.Month
)
82 if ( lhs
.Month
> rhs
.Month
)
85 if ( lhs
.Day
< rhs
.Day
)
91 //==================================================================================================================
93 //==================================================================================================================
94 class TimePredicateLess
: public IKeyPredicateLess
97 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const
100 if ( !( _lhs
>>= lhs
)
103 throw ::com::sun::star::lang::IllegalArgumentException();
106 if ( lhs
.Hours
< rhs
.Hours
)
108 if ( lhs
.Hours
> rhs
.Hours
)
111 if ( lhs
.Minutes
< rhs
.Minutes
)
113 if ( lhs
.Minutes
> rhs
.Minutes
)
116 if ( lhs
.Seconds
< rhs
.Seconds
)
118 if ( lhs
.Seconds
> rhs
.Seconds
)
121 if ( lhs
.NanoSeconds
< rhs
.NanoSeconds
)
127 //==================================================================================================================
128 //= DateTimePredicateLess
129 //==================================================================================================================
130 class DateTimePredicateLess
: public IKeyPredicateLess
133 virtual bool isLess( ::com::sun::star::uno::Any
const & _lhs
, ::com::sun::star::uno::Any
const & _rhs
) const
136 if ( !( _lhs
>>= lhs
)
139 throw ::com::sun::star::lang::IllegalArgumentException();
142 if ( lhs
.Year
< rhs
.Year
)
144 if ( lhs
.Year
> rhs
.Year
)
147 if ( lhs
.Month
< rhs
.Month
)
149 if ( lhs
.Month
> rhs
.Month
)
152 if ( lhs
.Day
< rhs
.Day
)
154 if ( lhs
.Day
> rhs
.Day
)
157 if ( lhs
.Hours
< rhs
.Hours
)
159 if ( lhs
.Hours
> rhs
.Hours
)
162 if ( lhs
.Minutes
< rhs
.Minutes
)
164 if ( lhs
.Minutes
> rhs
.Minutes
)
167 if ( lhs
.Seconds
< rhs
.Seconds
)
169 if ( lhs
.Seconds
> rhs
.Seconds
)
172 if ( lhs
.NanoSeconds
< rhs
.NanoSeconds
)
178 //------------------------------------------------------------------------------------------------------------------
179 ::std::auto_ptr
< IKeyPredicateLess
> getStandardLessPredicate( Type
const & i_type
, Reference
< XCollator
> const & i_collator
)
181 SAL_WNODEPRECATED_DECLARATIONS_PUSH
182 ::std::auto_ptr
< IKeyPredicateLess
> pComparator
;
183 SAL_WNODEPRECATED_DECLARATIONS_POP
184 switch ( i_type
.getTypeClass() )
187 pComparator
.reset( new ScalarPredicateLess
< sal_Unicode
>() );
189 case TypeClass_BOOLEAN
:
190 pComparator
.reset( new ScalarPredicateLess
< sal_Bool
>() );
193 pComparator
.reset( new ScalarPredicateLess
< sal_Int8
>() );
195 case TypeClass_SHORT
:
196 pComparator
.reset( new ScalarPredicateLess
< sal_Int16
>() );
198 case TypeClass_UNSIGNED_SHORT
:
199 pComparator
.reset( new ScalarPredicateLess
< sal_uInt16
>() );
202 pComparator
.reset( new ScalarPredicateLess
< sal_Int32
>() );
204 case TypeClass_UNSIGNED_LONG
:
205 pComparator
.reset( new ScalarPredicateLess
< sal_uInt32
>() );
207 case TypeClass_HYPER
:
208 pComparator
.reset( new ScalarPredicateLess
< sal_Int64
>() );
210 case TypeClass_UNSIGNED_HYPER
:
211 pComparator
.reset( new ScalarPredicateLess
< sal_uInt64
>() );
213 case TypeClass_FLOAT
:
214 pComparator
.reset( new ScalarPredicateLess
< float >() );
216 case TypeClass_DOUBLE
:
217 pComparator
.reset( new ScalarPredicateLess
< double >() );
219 case TypeClass_STRING
:
220 if ( i_collator
.is() )
221 pComparator
.reset( new StringCollationPredicateLess( i_collator
) );
223 pComparator
.reset( new StringPredicateLess() );
226 pComparator
.reset( new TypePredicateLess() );
229 pComparator
.reset( new EnumPredicateLess( i_type
) );
231 case TypeClass_INTERFACE
:
232 pComparator
.reset( new InterfacePredicateLess() );
234 case TypeClass_STRUCT
:
235 if ( i_type
.equals( ::cppu::UnoType
< Date
>::get() ) )
236 pComparator
.reset( new DatePredicateLess() );
237 else if ( i_type
.equals( ::cppu::UnoType
< Time
>::get() ) )
238 pComparator
.reset( new TimePredicateLess() );
239 else if ( i_type
.equals( ::cppu::UnoType
< DateTime
>::get() ) )
240 pComparator
.reset( new DateTimePredicateLess() );
248 //......................................................................................................................
249 } // namespace comphelper
250 //......................................................................................................................
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */