137adc4f0SAndrew Rist /**************************************************************
237adc4f0SAndrew Rist  *
337adc4f0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
437adc4f0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
537adc4f0SAndrew Rist  * distributed with this work for additional information
637adc4f0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
737adc4f0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
837adc4f0SAndrew Rist  * "License"); you may not use this file except in compliance
937adc4f0SAndrew Rist  * with the License.  You may obtain a copy of the License at
1037adc4f0SAndrew Rist  *
1137adc4f0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1237adc4f0SAndrew Rist  *
1337adc4f0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1437adc4f0SAndrew Rist  * software distributed under the License is distributed on an
1537adc4f0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1637adc4f0SAndrew Rist  * KIND, either express or implied.  See the License for the
1737adc4f0SAndrew Rist  * specific language governing permissions and limitations
1837adc4f0SAndrew Rist  * under the License.
1937adc4f0SAndrew Rist  *
2037adc4f0SAndrew Rist  *************************************************************/
2137adc4f0SAndrew Rist 
2237adc4f0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <algorithm>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "osl/diagnose.h"
29cdf0e10cSrcweir #include "rtl/byteseq.hxx"
30cdf0e10cSrcweir #include "rtl/ustring.hxx"
31cdf0e10cSrcweir #include "sal/types.h"
32cdf0e10cSrcweir #include "typelib/typeclass.h"
33cdf0e10cSrcweir #include "typelib/typedescription.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "lessoperators.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace uno {
38cdf0e10cSrcweir 
operator <(const TypeDescription & rLeft,const TypeDescription & rRight)397f80ef06SHerbert Dürr bool operator<( const TypeDescription& rLeft, const TypeDescription& rRight) {
407f80ef06SHerbert Dürr 	OSL_ASSERT( rLeft.is() && rRight.is());
417f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rLeft.get();
427f80ef06SHerbert Dürr 	const typelib_TypeDescription& rB = *rRight.get();
43*f1d3244eSDamjan Jovanovic 	if( rA.eTypeClass != rB.eTypeClass)
447f80ef06SHerbert Dürr 		return (rA.eTypeClass < rB.eTypeClass);
457f80ef06SHerbert Dürr 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
467f80ef06SHerbert Dürr 			rA.pTypeName->buffer, rA.pTypeName->length,
477f80ef06SHerbert Dürr 			rB.pTypeName->buffer, rB.pTypeName->length);
487f80ef06SHerbert Dürr 	return (nCmp < 0);
497f80ef06SHerbert Dürr }
507f80ef06SHerbert Dürr 
operator ()(const TypeDescription & rLeft,const TypeDescription & rRight) const517f80ef06SHerbert Dürr bool TypeDescEqual::operator()( const TypeDescription& rLeft, const TypeDescription& rRight) const
527f80ef06SHerbert Dürr {
537f80ef06SHerbert Dürr 	OSL_ASSERT( rLeft.is() && rRight.is());
547f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rLeft.get();
557f80ef06SHerbert Dürr 	const typelib_TypeDescription& rB = *rRight.get();
567f80ef06SHerbert Dürr 	if( rA.eTypeClass != rB.eTypeClass)
577f80ef06SHerbert Dürr 		return false;
587f80ef06SHerbert Dürr 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
597f80ef06SHerbert Dürr 			rA.pTypeName->buffer, rA.pTypeName->length,
607f80ef06SHerbert Dürr 			rB.pTypeName->buffer, rB.pTypeName->length);
617f80ef06SHerbert Dürr 	return (nCmp == 0);
627f80ef06SHerbert Dürr }
637f80ef06SHerbert Dürr 
operator ()(const TypeDescription & rTD) const647f80ef06SHerbert Dürr sal_Int32 TypeDescHash::operator()( const TypeDescription& rTD) const
657f80ef06SHerbert Dürr {
667f80ef06SHerbert Dürr 	OSL_ASSERT( rTD.is());
677f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rTD.get();
687f80ef06SHerbert Dürr 	sal_Int32 h = rtl_ustr_hashCode_WithLength( rA.pTypeName->buffer, rA.pTypeName->length);
697f80ef06SHerbert Dürr 	h ^= static_cast<sal_Int32>(rA.eTypeClass);
707f80ef06SHerbert Dürr 	return h;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir } } } }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace rtl {
76cdf0e10cSrcweir 
operator <(ByteSequence const & left,ByteSequence const & right)77cdf0e10cSrcweir bool operator <(ByteSequence const & left, ByteSequence const & right) {
787f80ef06SHerbert Dürr     const sal_Int32 nLen = std::min( left.getLength(), right.getLength());
797f80ef06SHerbert Dürr     for( sal_Int32 i = 0; i < nLen; ++i )
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         if (left[i] < right[i]) {
82cdf0e10cSrcweir             return true;
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir         if (right[i] < left[i]) {
85cdf0e10cSrcweir             return false;
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir     return left.getLength() < right.getLength();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir }
927f80ef06SHerbert Dürr 
93