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 
39*7f80ef06SHerbert Dürr bool operator<( const TypeDescription& rLeft, const TypeDescription& rRight) {
40*7f80ef06SHerbert Dürr 	OSL_ASSERT( rLeft.is() && rRight.is());
41*7f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rLeft.get();
42*7f80ef06SHerbert Dürr 	const typelib_TypeDescription& rB = *rRight.get();
43*7f80ef06SHerbert Dürr 	if( rA.eTypeClass != rA.eTypeClass)
44*7f80ef06SHerbert Dürr 		return (rA.eTypeClass < rB.eTypeClass);
45*7f80ef06SHerbert Dürr 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
46*7f80ef06SHerbert Dürr 			rA.pTypeName->buffer, rA.pTypeName->length,
47*7f80ef06SHerbert Dürr 			rB.pTypeName->buffer, rB.pTypeName->length);
48*7f80ef06SHerbert Dürr 	return (nCmp < 0);
49*7f80ef06SHerbert Dürr }
50*7f80ef06SHerbert Dürr 
51*7f80ef06SHerbert Dürr bool TypeDescEqual::operator()( const TypeDescription& rLeft, const TypeDescription& rRight) const
52*7f80ef06SHerbert Dürr {
53*7f80ef06SHerbert Dürr 	OSL_ASSERT( rLeft.is() && rRight.is());
54*7f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rLeft.get();
55*7f80ef06SHerbert Dürr 	const typelib_TypeDescription& rB = *rRight.get();
56*7f80ef06SHerbert Dürr 	if( rA.eTypeClass != rB.eTypeClass)
57*7f80ef06SHerbert Dürr 		return false;
58*7f80ef06SHerbert Dürr 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
59*7f80ef06SHerbert Dürr 			rA.pTypeName->buffer, rA.pTypeName->length,
60*7f80ef06SHerbert Dürr 			rB.pTypeName->buffer, rB.pTypeName->length);
61*7f80ef06SHerbert Dürr 	return (nCmp == 0);
62*7f80ef06SHerbert Dürr }
63*7f80ef06SHerbert Dürr 
64*7f80ef06SHerbert Dürr sal_Int32 TypeDescHash::operator()( const TypeDescription& rTD) const
65*7f80ef06SHerbert Dürr {
66*7f80ef06SHerbert Dürr 	OSL_ASSERT( rTD.is());
67*7f80ef06SHerbert Dürr 	const typelib_TypeDescription& rA = *rTD.get();
68*7f80ef06SHerbert Dürr 	sal_Int32 h = rtl_ustr_hashCode_WithLength( rA.pTypeName->buffer, rA.pTypeName->length);
69*7f80ef06SHerbert Dürr 	h ^= static_cast<sal_Int32>(rA.eTypeClass);
70*7f80ef06SHerbert Dürr 	return h;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir } } } }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace rtl {
76cdf0e10cSrcweir 
77cdf0e10cSrcweir bool operator <(ByteSequence const & left, ByteSequence const & right) {
78*7f80ef06SHerbert Dürr     const sal_Int32 nLen = std::min( left.getLength(), right.getLength());
79*7f80ef06SHerbert 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 }
92*7f80ef06SHerbert Dürr 
93