xref: /trunk/main/i18npool/inc/collatorImpl.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 #ifndef _I18N_COLLATORIMPL_HXX_
24 #define _I18N_COLLATORIMPL_HXX_
25 
26 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/i18n/XLocaleData.hpp>
30 #include <com/sun/star/i18n/XCollator.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <cppuhelper/weak.hxx>
33 #include <cppuhelper/implbase2.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <sal/alloca.h>
36 #include <vector>
37 
38 namespace com { namespace sun { namespace star { namespace i18n {
39 //      ----------------------------------------------------
40 //      class CollatorImpl
41 //      ----------------------------------------------------
42 class CollatorImpl : public cppu::WeakImplHelper2
43 <
44     XCollator,
45     com::sun::star::lang::XServiceInfo
46 >
47 {
48 public:
49 
50     // Constructors
51     CollatorImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
52     // Destructor
53     ~CollatorImpl();
54 
55     virtual sal_Int32 SAL_CALL compareSubstring(const rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1,
56         const rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2);
57 
58     virtual sal_Int32 SAL_CALL compareString( const rtl::OUString& s1,
59         const rtl::OUString& s2);
60 
61     virtual sal_Int32 SAL_CALL loadDefaultCollator( const lang::Locale& rLocale,  sal_Int32 collatorOptions);
62 
63     virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(  const rtl::OUString& impl, const lang::Locale& rLocale,
64         sal_Int32 collatorOptions);
65 
66     virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const rtl::OUString& impl, const lang::Locale& rLocale,
67         const com::sun::star::uno::Sequence< sal_Int32 >& collatorOptions);
68 
69     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms( const lang::Locale& rLocale );
70 
71     virtual com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const rtl::OUString& collatorAlgorithmName );
72 
73     //XServiceInfo
74     virtual rtl::OUString SAL_CALL getImplementationName();
75     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName);
76     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames();
77 
78 protected:
79     lang::Locale nLocale;
80 private :
81     struct lookupTableItem {
82         lang::Locale aLocale;
83         rtl::OUString algorithm;
84         rtl::OUString service;
85         com::sun::star::uno::Reference < XCollator > xC;
lookupTableItemcom::sun::star::i18n::CollatorImpl::lookupTableItem86         lookupTableItem(const lang::Locale& rLocale, const rtl::OUString& _algorithm, const rtl::OUString& _service,
87         com::sun::star::uno::Reference < XCollator >& _xC) : aLocale(rLocale), algorithm(_algorithm), service(_service), xC(_xC) {}
equalscom::sun::star::i18n::CollatorImpl::lookupTableItem88         sal_Bool SAL_CALL equals(const lang::Locale& rLocale, const rtl::OUString& _algorithm) {
89         return aLocale.Language == rLocale.Language &&
90             aLocale.Country == rLocale.Country &&
91             aLocale.Variant == rLocale.Variant &&
92             algorithm == _algorithm;
93         }
94     };
95     std::vector<lookupTableItem*> lookupTable;
96     lookupTableItem *cachedItem;
97 
98     // Service Factory
99     com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
100     // lang::Locale Data
101     com::sun::star::uno::Reference < XLocaleData > localedata;
102 
103     sal_Bool SAL_CALL createCollator(const lang::Locale& rLocale, const rtl::OUString& serviceName,
104         const rtl::OUString& rSortAlgorithm);
105     void SAL_CALL loadCachedCollator(const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm);
106 };
107 
108 } } } }
109 
110 #endif
111