1*dde7d3faSAndrew Rist /************************************************************** 2*dde7d3faSAndrew Rist * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10*dde7d3faSAndrew Rist * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*dde7d3faSAndrew Rist * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19*dde7d3faSAndrew Rist * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "comphelper/anycompare.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** === begin UNO includes === **/ 29cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp> 30cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp> 31cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 32cdf0e10cSrcweir /** === end UNO includes === **/ 33cdf0e10cSrcweir 34cdf0e10cSrcweir //...................................................................................................................... 35cdf0e10cSrcweir namespace comphelper 36cdf0e10cSrcweir { 37cdf0e10cSrcweir //...................................................................................................................... 38cdf0e10cSrcweir 39cdf0e10cSrcweir /** === begin UNO using === **/ 40cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 42cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 43cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 44cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 45cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 46cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 47cdf0e10cSrcweir using ::com::sun::star::uno::Any; 48cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 49cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 50cdf0e10cSrcweir using ::com::sun::star::uno::Type; 51cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_CHAR; 52cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_BOOLEAN; 53cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_BYTE; 54cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_SHORT; 55cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT; 56cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_LONG; 57cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_UNSIGNED_LONG; 58cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_HYPER; 59cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER; 60cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_FLOAT; 61cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_DOUBLE; 62cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_STRING; 63cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_TYPE; 64cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_ENUM; 65cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_INTERFACE; 66cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_STRUCT; 67cdf0e10cSrcweir using ::com::sun::star::i18n::XCollator; 68cdf0e10cSrcweir using ::com::sun::star::util::Date; 69cdf0e10cSrcweir using ::com::sun::star::util::Time; 70cdf0e10cSrcweir using ::com::sun::star::util::DateTime; 71cdf0e10cSrcweir /** === end UNO using === **/ 72cdf0e10cSrcweir 73cdf0e10cSrcweir //================================================================================================================== 74cdf0e10cSrcweir //= DatePredicateLess 75cdf0e10cSrcweir //================================================================================================================== 76cdf0e10cSrcweir class DatePredicateLess : public IKeyPredicateLess 77cdf0e10cSrcweir { 78cdf0e10cSrcweir public: isLess(::com::sun::star::uno::Any const & _lhs,::com::sun::star::uno::Any const & _rhs) const79cdf0e10cSrcweir virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const 80cdf0e10cSrcweir { 81cdf0e10cSrcweir Date lhs, rhs; 82cdf0e10cSrcweir if ( !( _lhs >>= lhs ) 83cdf0e10cSrcweir || !( _rhs >>= rhs ) 84cdf0e10cSrcweir ) 85cdf0e10cSrcweir throw ::com::sun::star::lang::IllegalArgumentException(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir if ( lhs.Year < rhs.Year ) 88cdf0e10cSrcweir return true; 89cdf0e10cSrcweir if ( lhs.Year > rhs.Year ) 90cdf0e10cSrcweir return false; 91cdf0e10cSrcweir 92cdf0e10cSrcweir if ( lhs.Month < rhs.Month ) 93cdf0e10cSrcweir return true; 94cdf0e10cSrcweir if ( lhs.Month > rhs.Month ) 95cdf0e10cSrcweir return false; 96cdf0e10cSrcweir 97cdf0e10cSrcweir if ( lhs.Day < rhs.Day ) 98cdf0e10cSrcweir return true; 99cdf0e10cSrcweir return false; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir }; 102cdf0e10cSrcweir 103cdf0e10cSrcweir //================================================================================================================== 104cdf0e10cSrcweir //= TimePredicateLess 105cdf0e10cSrcweir //================================================================================================================== 106cdf0e10cSrcweir class TimePredicateLess : public IKeyPredicateLess 107cdf0e10cSrcweir { 108cdf0e10cSrcweir public: isLess(::com::sun::star::uno::Any const & _lhs,::com::sun::star::uno::Any const & _rhs) const109cdf0e10cSrcweir virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const 110cdf0e10cSrcweir { 111cdf0e10cSrcweir Time lhs, rhs; 112cdf0e10cSrcweir if ( !( _lhs >>= lhs ) 113cdf0e10cSrcweir || !( _rhs >>= rhs ) 114cdf0e10cSrcweir ) 115cdf0e10cSrcweir throw ::com::sun::star::lang::IllegalArgumentException(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if ( lhs.Hours < rhs.Hours ) 118cdf0e10cSrcweir return true; 119cdf0e10cSrcweir if ( lhs.Hours > rhs.Hours ) 120cdf0e10cSrcweir return false; 121cdf0e10cSrcweir 122cdf0e10cSrcweir if ( lhs.Minutes < rhs.Minutes ) 123cdf0e10cSrcweir return true; 124cdf0e10cSrcweir if ( lhs.Minutes > rhs.Minutes ) 125cdf0e10cSrcweir return false; 126cdf0e10cSrcweir 127cdf0e10cSrcweir if ( lhs.Seconds < rhs.Seconds ) 128cdf0e10cSrcweir return true; 129cdf0e10cSrcweir if ( lhs.Seconds > rhs.Seconds ) 130cdf0e10cSrcweir return false; 131cdf0e10cSrcweir 132cdf0e10cSrcweir if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) 133cdf0e10cSrcweir return true; 134cdf0e10cSrcweir return false; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir }; 137cdf0e10cSrcweir 138cdf0e10cSrcweir //================================================================================================================== 139cdf0e10cSrcweir //= DateTimePredicateLess 140cdf0e10cSrcweir //================================================================================================================== 141cdf0e10cSrcweir class DateTimePredicateLess : public IKeyPredicateLess 142cdf0e10cSrcweir { 143cdf0e10cSrcweir public: isLess(::com::sun::star::uno::Any const & _lhs,::com::sun::star::uno::Any const & _rhs) const144cdf0e10cSrcweir virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const 145cdf0e10cSrcweir { 146cdf0e10cSrcweir DateTime lhs, rhs; 147cdf0e10cSrcweir if ( !( _lhs >>= lhs ) 148cdf0e10cSrcweir || !( _rhs >>= rhs ) 149cdf0e10cSrcweir ) 150cdf0e10cSrcweir throw ::com::sun::star::lang::IllegalArgumentException(); 151cdf0e10cSrcweir 152cdf0e10cSrcweir if ( lhs.Year < rhs.Year ) 153cdf0e10cSrcweir return true; 154cdf0e10cSrcweir if ( lhs.Year > rhs.Year ) 155cdf0e10cSrcweir return false; 156cdf0e10cSrcweir 157cdf0e10cSrcweir if ( lhs.Month < rhs.Month ) 158cdf0e10cSrcweir return true; 159cdf0e10cSrcweir if ( lhs.Month > rhs.Month ) 160cdf0e10cSrcweir return false; 161cdf0e10cSrcweir 162cdf0e10cSrcweir if ( lhs.Day < rhs.Day ) 163cdf0e10cSrcweir return true; 164cdf0e10cSrcweir if ( lhs.Day > rhs.Day ) 165cdf0e10cSrcweir return false; 166cdf0e10cSrcweir 167cdf0e10cSrcweir if ( lhs.Hours < rhs.Hours ) 168cdf0e10cSrcweir return true; 169cdf0e10cSrcweir if ( lhs.Hours > rhs.Hours ) 170cdf0e10cSrcweir return false; 171cdf0e10cSrcweir 172cdf0e10cSrcweir if ( lhs.Minutes < rhs.Minutes ) 173cdf0e10cSrcweir return true; 174cdf0e10cSrcweir if ( lhs.Minutes > rhs.Minutes ) 175cdf0e10cSrcweir return false; 176cdf0e10cSrcweir 177cdf0e10cSrcweir if ( lhs.Seconds < rhs.Seconds ) 178cdf0e10cSrcweir return true; 179cdf0e10cSrcweir if ( lhs.Seconds > rhs.Seconds ) 180cdf0e10cSrcweir return false; 181cdf0e10cSrcweir 182cdf0e10cSrcweir if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) 183cdf0e10cSrcweir return true; 184cdf0e10cSrcweir return false; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir }; 187cdf0e10cSrcweir 188cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getStandardLessPredicate(Type const & i_type,Reference<XCollator> const & i_collator)189cdf0e10cSrcweir ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir ::std::auto_ptr< IKeyPredicateLess > pComparator; 192cdf0e10cSrcweir switch ( i_type.getTypeClass() ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir case TypeClass_CHAR: 195cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Unicode >() ); 196cdf0e10cSrcweir break; 197cdf0e10cSrcweir case TypeClass_BOOLEAN: 198cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Bool >() ); 199cdf0e10cSrcweir break; 200cdf0e10cSrcweir case TypeClass_BYTE: 201cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Int8 >() ); 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir case TypeClass_SHORT: 204cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Int16 >() ); 205cdf0e10cSrcweir break; 206cdf0e10cSrcweir case TypeClass_UNSIGNED_SHORT: 207cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_uInt16 >() ); 208cdf0e10cSrcweir break; 209cdf0e10cSrcweir case TypeClass_LONG: 210cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Int32 >() ); 211cdf0e10cSrcweir break; 212cdf0e10cSrcweir case TypeClass_UNSIGNED_LONG: 213cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_uInt32 >() ); 214cdf0e10cSrcweir break; 215cdf0e10cSrcweir case TypeClass_HYPER: 216cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_Int64 >() ); 217cdf0e10cSrcweir break; 218cdf0e10cSrcweir case TypeClass_UNSIGNED_HYPER: 219cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< sal_uInt64 >() ); 220cdf0e10cSrcweir break; 221cdf0e10cSrcweir case TypeClass_FLOAT: 222cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< float >() ); 223cdf0e10cSrcweir break; 224cdf0e10cSrcweir case TypeClass_DOUBLE: 225cdf0e10cSrcweir pComparator.reset( new ScalarPredicateLess< double >() ); 226cdf0e10cSrcweir break; 227cdf0e10cSrcweir case TypeClass_STRING: 228cdf0e10cSrcweir if ( i_collator.is() ) 229cdf0e10cSrcweir pComparator.reset( new StringCollationPredicateLess( i_collator ) ); 230cdf0e10cSrcweir else 231cdf0e10cSrcweir pComparator.reset( new StringPredicateLess() ); 232cdf0e10cSrcweir break; 233cdf0e10cSrcweir case TypeClass_TYPE: 234cdf0e10cSrcweir pComparator.reset( new TypePredicateLess() ); 235cdf0e10cSrcweir break; 236cdf0e10cSrcweir case TypeClass_ENUM: 237cdf0e10cSrcweir pComparator.reset( new EnumPredicateLess( i_type ) ); 238cdf0e10cSrcweir break; 239cdf0e10cSrcweir case TypeClass_INTERFACE: 240cdf0e10cSrcweir pComparator.reset( new InterfacePredicateLess() ); 241cdf0e10cSrcweir break; 242cdf0e10cSrcweir case TypeClass_STRUCT: 243cdf0e10cSrcweir if ( i_type.equals( ::cppu::UnoType< Date >::get() ) ) 244cdf0e10cSrcweir pComparator.reset( new DatePredicateLess() ); 245cdf0e10cSrcweir else if ( i_type.equals( ::cppu::UnoType< Time >::get() ) ) 246cdf0e10cSrcweir pComparator.reset( new TimePredicateLess() ); 247cdf0e10cSrcweir else if ( i_type.equals( ::cppu::UnoType< DateTime >::get() ) ) 248cdf0e10cSrcweir pComparator.reset( new DateTimePredicateLess() ); 249cdf0e10cSrcweir break; 250cdf0e10cSrcweir default: 251cdf0e10cSrcweir break; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir return pComparator; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir //...................................................................................................................... 257cdf0e10cSrcweir } // namespace comphelper 258cdf0e10cSrcweir //...................................................................................................................... 259