diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-03-08 10:01:53 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-06-29 15:51:44 +0100 |
commit | 7be964961f0c3c884766f6215eb214c7e7d65a11 (patch) | |
tree | c0de9ead16c13297d2e3146cd7aaf996a29689d1 /comphelper/source/misc/anycompare.cxx | |
parent | SwDoc::CopyPageDesc: sal_Bool -> bool (diff) | |
download | core-7be964961f0c3c884766f6215eb214c7e7d65a11.tar.gz core-7be964961f0c3c884766f6215eb214c7e7d65a11.zip |
gridfixes: #i117265# implement less-predicate for Date/Time structs
Diffstat (limited to 'comphelper/source/misc/anycompare.cxx')
-rw-r--r-- | comphelper/source/misc/anycompare.cxx | 134 |
1 files changed, 131 insertions, 3 deletions
diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx index 66e8a7bd02aa..0d9675d63c1a 100644 --- a/comphelper/source/misc/anycompare.cxx +++ b/comphelper/source/misc/anycompare.cxx @@ -27,11 +27,12 @@ #include "comphelper/anycompare.hxx" -//...................................................................................................................... +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/Time.hpp> +#include <com/sun/star/util/DateTime.hpp> + namespace comphelper { -//...................................................................................................................... - /** === begin UNO using === **/ using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::XInterface; @@ -59,9 +60,128 @@ namespace comphelper using ::com::sun::star::uno::TypeClass_TYPE; using ::com::sun::star::uno::TypeClass_ENUM; using ::com::sun::star::uno::TypeClass_INTERFACE; + using ::com::sun::star::uno::TypeClass_STRUCT; using ::com::sun::star::i18n::XCollator; + using ::com::sun::star::util::Date; + using ::com::sun::star::util::Time; + using ::com::sun::star::util::DateTime; /** === end UNO using === **/ + //================================================================================================================== + //= DatePredicateLess + //================================================================================================================== + class DatePredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + Date lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + + if ( lhs.Year < rhs.Year ) + return true; + if ( lhs.Year > rhs.Year ) + return false; + + if ( lhs.Month < rhs.Month ) + return true; + if ( lhs.Month > rhs.Month ) + return false; + + if ( lhs.Day < rhs.Day ) + return true; + return false; + } + }; + + //================================================================================================================== + //= TimePredicateLess + //================================================================================================================== + class TimePredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + Time lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + + if ( lhs.Hours < rhs.Hours ) + return true; + if ( lhs.Hours > rhs.Hours ) + return false; + + if ( lhs.Minutes < rhs.Minutes ) + return true; + if ( lhs.Minutes > rhs.Minutes ) + return false; + + if ( lhs.Seconds < rhs.Seconds ) + return true; + if ( lhs.Seconds > rhs.Seconds ) + return false; + + if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) + return true; + return false; + } + }; + + //================================================================================================================== + //= DateTimePredicateLess + //================================================================================================================== + class DateTimePredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + DateTime lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + + if ( lhs.Year < rhs.Year ) + return true; + if ( lhs.Year > rhs.Year ) + return false; + + if ( lhs.Month < rhs.Month ) + return true; + if ( lhs.Month > rhs.Month ) + return false; + + if ( lhs.Day < rhs.Day ) + return true; + if ( lhs.Day > rhs.Day ) + return false; + + if ( lhs.Hours < rhs.Hours ) + return true; + if ( lhs.Hours > rhs.Hours ) + return false; + + if ( lhs.Minutes < rhs.Minutes ) + return true; + if ( lhs.Minutes > rhs.Minutes ) + return false; + + if ( lhs.Seconds < rhs.Seconds ) + return true; + if ( lhs.Seconds > rhs.Seconds ) + return false; + + if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) + return true; + return false; + } + }; + //------------------------------------------------------------------------------------------------------------------ ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator ) { @@ -118,6 +238,14 @@ namespace comphelper case TypeClass_INTERFACE: pComparator.reset( new InterfacePredicateLess() ); break; + case TypeClass_STRUCT: + if ( i_type.equals( ::cppu::UnoType< Date >::get() ) ) + pComparator.reset( new DatePredicateLess() ); + else if ( i_type.equals( ::cppu::UnoType< Time >::get() ) ) + pComparator.reset( new TimePredicateLess() ); + else if ( i_type.equals( ::cppu::UnoType< DateTime >::get() ) ) + pComparator.reset( new DateTimePredicateLess() ); + break; default: break; } |