1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/config.h"
25 
26 #include <algorithm>
27 
28 #include "osl/diagnose.h"
29 #include "rtl/byteseq.hxx"
30 #include "rtl/ustring.hxx"
31 #include "sal/types.h"
32 #include "typelib/typeclass.h"
33 #include "typelib/typedescription.hxx"
34 
35 #include "lessoperators.hxx"
36 
37 namespace com { namespace sun { namespace star { namespace uno {
38 
39 bool operator<( const TypeDescription& rLeft, const TypeDescription& rRight) {
40 	OSL_ASSERT( rLeft.is() && rRight.is());
41 	const typelib_TypeDescription& rA = *rLeft.get();
42 	const typelib_TypeDescription& rB = *rRight.get();
43 	if( rA.eTypeClass != rA.eTypeClass)
44 		return (rA.eTypeClass < rB.eTypeClass);
45 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
46 			rA.pTypeName->buffer, rA.pTypeName->length,
47 			rB.pTypeName->buffer, rB.pTypeName->length);
48 	return (nCmp < 0);
49 }
50 
51 bool TypeDescEqual::operator()( const TypeDescription& rLeft, const TypeDescription& rRight) const
52 {
53 	OSL_ASSERT( rLeft.is() && rRight.is());
54 	const typelib_TypeDescription& rA = *rLeft.get();
55 	const typelib_TypeDescription& rB = *rRight.get();
56 	if( rA.eTypeClass != rB.eTypeClass)
57 		return false;
58 	const sal_Int32 nCmp = rtl_ustr_compare_WithLength(
59 			rA.pTypeName->buffer, rA.pTypeName->length,
60 			rB.pTypeName->buffer, rB.pTypeName->length);
61 	return (nCmp == 0);
62 }
63 
64 sal_Int32 TypeDescHash::operator()( const TypeDescription& rTD) const
65 {
66 	OSL_ASSERT( rTD.is());
67 	const typelib_TypeDescription& rA = *rTD.get();
68 	sal_Int32 h = rtl_ustr_hashCode_WithLength( rA.pTypeName->buffer, rA.pTypeName->length);
69 	h ^= static_cast<sal_Int32>(rA.eTypeClass);
70 	return h;
71 }
72 
73 } } } }
74 
75 namespace rtl {
76 
77 bool operator <(ByteSequence const & left, ByteSequence const & right) {
78     const sal_Int32 nLen = std::min( left.getLength(), right.getLength());
79     for( sal_Int32 i = 0; i < nLen; ++i )
80     {
81         if (left[i] < right[i]) {
82             return true;
83         }
84         if (right[i] < left[i]) {
85             return false;
86         }
87     }
88     return left.getLength() < right.getLength();
89 }
90 
91 }
92 
93