Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / i18npool / inc / collatorImpl.hxx
blob34ddfc70c565b6b204fa3e45666acd61875ec826
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_I18NPOOL_INC_COLLATORIMPL_HXX
20 #define INCLUDED_I18NPOOL_INC_COLLATORIMPL_HXX
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/uno/Reference.h>
24 #include <com/sun/star/i18n/XLocaleData4.hpp>
25 #include <com/sun/star/i18n/XCollator.hpp>
26 #include <com/sun/star/lang/Locale.hpp>
27 #include <cppuhelper/weak.hxx>
28 #include <cppuhelper/implbase.hxx>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <vector>
33 namespace com { namespace sun { namespace star { namespace i18n {
34 // ----------------------------------------------------
35 // class CollatorImpl
36 // ----------------------------------------------------
37 class CollatorImpl : public cppu::WeakImplHelper
39 XCollator,
40 css::lang::XServiceInfo
43 public:
45 // Constructors
46 CollatorImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
47 // Destructor
48 virtual ~CollatorImpl() override;
50 virtual sal_Int32 SAL_CALL compareSubstring(const OUString& s1, sal_Int32 off1, sal_Int32 len1,
51 const OUString& s2, sal_Int32 off2, sal_Int32 len2) override;
53 virtual sal_Int32 SAL_CALL compareString( const OUString& s1,
54 const OUString& s2) override;
56 virtual sal_Int32 SAL_CALL loadDefaultCollator( const lang::Locale& rLocale, sal_Int32 collatorOptions) override;
58 virtual sal_Int32 SAL_CALL loadCollatorAlgorithm( const OUString& impl, const lang::Locale& rLocale,
59 sal_Int32 collatorOptions) override;
61 virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const OUString& impl, const lang::Locale& rLocale,
62 const css::uno::Sequence< sal_Int32 >& collatorOptions) override;
64 virtual css::uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms( const lang::Locale& rLocale ) override;
66 virtual css::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const OUString& collatorAlgorithmName ) override;
68 //XServiceInfo
69 virtual OUString SAL_CALL getImplementationName() override;
70 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
71 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
73 protected:
74 lang::Locale nLocale;
75 private:
76 struct lookupTableItem {
77 lang::Locale aLocale;
78 OUString algorithm;
79 OUString service;
80 css::uno::Reference < XCollator > xC;
81 lookupTableItem(const lang::Locale& rLocale, const OUString& _algorithm, const OUString& _service,
82 css::uno::Reference < XCollator >& _xC) : aLocale(rLocale), algorithm(_algorithm), service(_service), xC(_xC) {}
83 bool SAL_CALL equals(const lang::Locale& rLocale, const OUString& _algorithm) {
84 return aLocale.Language == rLocale.Language &&
85 aLocale.Country == rLocale.Country &&
86 aLocale.Variant == rLocale.Variant &&
87 algorithm == _algorithm;
90 std::vector<lookupTableItem*> lookupTable;
91 lookupTableItem * cachedItem;
93 // Service Factory
94 css::uno::Reference < css::uno::XComponentContext > m_xContext;
95 // lang::Locale Data
96 css::uno::Reference < XLocaleData4 > mxLocaleData;
98 /// @throws css::uno::RuntimeException
99 bool SAL_CALL createCollator(const lang::Locale& rLocale, const OUString& serviceName,
100 const OUString& rSortAlgorithm);
101 /// @throws css::uno::RuntimeException
102 void SAL_CALL loadCachedCollator(const lang::Locale& rLocale, const OUString& rSortAlgorithm);
105 } } } }
107 #endif
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */