Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / linguistic / source / convdic.hxx
bloba0501e2ddf1be214d83eb617212fcfd0c544219b
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 #pragma once
21 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
22 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
23 #include <com/sun/star/util/XFlushable.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <comphelper/interfacecontainer3.hxx>
27 #include <i18nlangtag/lang.h>
29 #include <memory>
30 #include <unordered_map>
32 // text conversion dictionary extension
33 inline constexpr OUStringLiteral CONV_DIC_EXT = u"tcd";
34 #define CONV_DIC_DOT_EXT ".tcd"
36 inline constexpr OUStringLiteral SN_CONV_DICTIONARY = u"com.sun.star.linguistic2.ConversionDictionary";
39 bool IsConvDic( const OUString &rFileURL, LanguageType &nLang, sal_Int16 &nConvType );
41 typedef std::unordered_multimap<OUString, OUString> ConvMap;
42 typedef std::unordered_multimap<OUString, sal_Int16> PropTypeMap;
44 class ConvDic :
45 public ::cppu::WeakImplHelper
47 css::linguistic2::XConversionDictionary,
48 css::linguistic2::XConversionPropertyType,
49 css::util::XFlushable,
50 css::lang::XServiceInfo
53 friend class ConvDicXMLExport;
55 protected:
57 ::comphelper::OInterfaceContainerHelper3<css::util::XFlushListener> aFlushListeners;
59 ConvMap aFromLeft;
60 std::unique_ptr< ConvMap > pFromRight; // only available for bidirectional conversion dictionaries
62 std::unique_ptr< PropTypeMap > pConvPropType;
64 OUString aMainURL; // URL to file
65 OUString aName;
66 LanguageType nLanguage;
67 sal_Int16 nConversionType;
68 sal_Int16 nMaxLeftCharCount;
69 sal_Int16 nMaxRightCharCount;
70 bool bMaxCharCountIsValid;
71 bool bNeedEntries;
72 bool bIsModified;
73 bool bIsActive;
75 // disallow copy-constructor and assignment-operator for now
76 ConvDic(const ConvDic &);
77 ConvDic & operator = (const ConvDic &);
79 static ConvMap::iterator GetEntry( ConvMap &rMap, const OUString &rFirstText, std::u16string_view rSecondText );
80 void Load();
81 void Save();
83 public:
84 ConvDic( OUString aName,
85 LanguageType nLanguage,
86 sal_Int16 nConversionType,
87 bool bBiDirectional,
88 const OUString &rMainURL);
89 virtual ~ConvDic() override;
91 // XConversionDictionary
92 virtual OUString SAL_CALL getName( ) override;
93 virtual css::lang::Locale SAL_CALL getLocale( ) override;
94 virtual sal_Int16 SAL_CALL getConversionType( ) override;
95 virtual void SAL_CALL setActive( sal_Bool bActivate ) override;
96 virtual sal_Bool SAL_CALL isActive( ) override;
97 virtual void SAL_CALL clear( ) override;
98 virtual css::uno::Sequence< OUString > SAL_CALL getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, css::linguistic2::ConversionDirection eDirection, sal_Int32 nTextConversionOptions ) override;
99 virtual css::uno::Sequence< OUString > SAL_CALL getConversionEntries( css::linguistic2::ConversionDirection eDirection ) override;
100 virtual void SAL_CALL addEntry( const OUString& aLeftText, const OUString& aRightText ) override;
101 virtual void SAL_CALL removeEntry( const OUString& aLeftText, const OUString& aRightText ) override;
102 virtual sal_Int16 SAL_CALL getMaxCharCount( css::linguistic2::ConversionDirection eDirection ) override;
104 // XConversionPropertyType
105 virtual void SAL_CALL setPropertyType( const OUString& aLeftText, const OUString& aRightText, ::sal_Int16 nPropertyType ) override;
106 virtual ::sal_Int16 SAL_CALL getPropertyType( const OUString& aLeftText, const OUString& aRightText ) override;
108 // XFlushable
109 virtual void SAL_CALL flush( ) override;
110 virtual void SAL_CALL addFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override;
111 virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override;
113 // XServiceInfo
114 virtual OUString SAL_CALL getImplementationName( ) override;
115 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
116 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
118 bool HasEntry( const OUString &rLeftText, std::u16string_view rRightText );
119 void AddEntry( const OUString &rLeftText, const OUString &rRightText );
120 void RemoveEntry( const OUString &rLeftText, const OUString &rRightText );
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */