1*bae3752eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bae3752eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bae3752eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bae3752eSAndrew Rist * distributed with this work for additional information 6*bae3752eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bae3752eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bae3752eSAndrew Rist * "License"); you may not use this file except in compliance 9*bae3752eSAndrew Rist * with the License. You may obtain a copy of the License at 10*bae3752eSAndrew Rist * 11*bae3752eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*bae3752eSAndrew Rist * 13*bae3752eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bae3752eSAndrew Rist * software distributed under the License is distributed on an 15*bae3752eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bae3752eSAndrew Rist * KIND, either express or implied. See the License for the 17*bae3752eSAndrew Rist * specific language governing permissions and limitations 18*bae3752eSAndrew Rist * under the License. 19*bae3752eSAndrew Rist * 20*bae3752eSAndrew Rist *************************************************************/ 21*bae3752eSAndrew Rist 22*bae3752eSAndrew Rist 23cdf0e10cSrcweir #ifndef _UTL_ATOM_HXX_ 24cdf0e10cSrcweir #define _UTL_ATOM_HXX_ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "unotools/unotoolsdllapi.h" 27cdf0e10cSrcweir #include <rtl/ustring.hxx> 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <hash_map> 32cdf0e10cSrcweir #ifndef __SGI_STL_LIST 33cdf0e10cSrcweir #include <list> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <com/sun/star/util/XAtomServer.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #define INVALID_ATOM 0 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace utl { 40cdf0e10cSrcweir 41cdf0e10cSrcweir struct AtomDescription 42cdf0e10cSrcweir { 43cdf0e10cSrcweir int atom; 44cdf0e10cSrcweir ::rtl::OUString description; 45cdf0e10cSrcweir }; 46cdf0e10cSrcweir 47cdf0e10cSrcweir class AtomProvider 48cdf0e10cSrcweir { 49cdf0e10cSrcweir int m_nAtoms; 50cdf0e10cSrcweir ::std::hash_map< int, ::rtl::OUString, ::std::hash< int > > m_aStringMap; 51cdf0e10cSrcweir ::std::hash_map< ::rtl::OUString, int, ::rtl::OUStringHash > m_aAtomMap; 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir AtomProvider(); 54cdf0e10cSrcweir ~AtomProvider(); 55cdf0e10cSrcweir 56cdf0e10cSrcweir int getAtom( const ::rtl::OUString&, sal_Bool bCreate = sal_False ); getLastAtom() const57cdf0e10cSrcweir int getLastAtom() const { return m_nAtoms-1; } 58cdf0e10cSrcweir const ::rtl::OUString& getString( int ) const; 59cdf0e10cSrcweir 60cdf0e10cSrcweir void getAll( ::std::list< AtomDescription >& atoms ); 61cdf0e10cSrcweir 62cdf0e10cSrcweir void getRecent( int atom, ::std::list< AtomDescription >& atoms ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir void overrideAtom( int atom, const ::rtl::OUString& description ); 65cdf0e10cSrcweir 66cdf0e10cSrcweir sal_Bool hasAtom( int atom ) const; 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir 70cdf0e10cSrcweir class UNOTOOLS_DLLPUBLIC MultiAtomProvider 71cdf0e10cSrcweir { 72cdf0e10cSrcweir ::std::hash_map< int, AtomProvider*, ::std::hash< int > > m_aAtomLists; 73cdf0e10cSrcweir public: 74cdf0e10cSrcweir MultiAtomProvider(); 75cdf0e10cSrcweir ~MultiAtomProvider(); 76cdf0e10cSrcweir 77cdf0e10cSrcweir int getLastAtom( int atomClass ) const; 78cdf0e10cSrcweir 79cdf0e10cSrcweir sal_Bool insertAtomClass( int atomClass ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir int getAtom( int atomClass, const ::rtl::OUString& rString, sal_Bool bCreate = sal_False ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir void getRecent( int atomClass, int atom, ::std::list< AtomDescription >& atoms ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir const ::rtl::OUString& getString( int atomClass, int atom ) const; 86cdf0e10cSrcweir void getClass( int atomClass, ::std::list< AtomDescription >& atoms ) const; 87cdf0e10cSrcweir 88cdf0e10cSrcweir void overrideAtom( int atomClass, int atom, const ::rtl::OUString& description ); overrideAtom(int atomClass,const::com::sun::star::util::AtomDescription & newDescription)89cdf0e10cSrcweir void overrideAtom( int atomClass, const ::com::sun::star::util::AtomDescription& newDescription ) 90cdf0e10cSrcweir { overrideAtom( atomClass, newDescription.atom, newDescription.description ); } 91cdf0e10cSrcweir sal_Bool hasAtom( int atomClass, int atom ) const; 92cdf0e10cSrcweir }; 93cdf0e10cSrcweir 94cdf0e10cSrcweir class AtomServer : public ::cppu::WeakAggImplHelper1< ::com::sun::star::util::XAtomServer > 95cdf0e10cSrcweir { 96cdf0e10cSrcweir private: 97cdf0e10cSrcweir MultiAtomProvider m_aProvider; 98cdf0e10cSrcweir ::osl::Mutex m_aMutex; 99cdf0e10cSrcweir public: 100cdf0e10cSrcweir AtomServer(); 101cdf0e10cSrcweir virtual ~AtomServer(); 102cdf0e10cSrcweir getString(int atomClass,int atom) const103cdf0e10cSrcweir const ::rtl::OUString& getString( int atomClass, int atom ) const 104cdf0e10cSrcweir { return m_aProvider.getString( atomClass, atom ); } 105cdf0e10cSrcweir 106cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getClass( sal_Int32 atomClass ) throw(); 107cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > > SAL_CALL getClasses( const ::com::sun::star::uno::Sequence< sal_Int32 >& atomClasses ) throw(); 108cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAtomDescriptions( const ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomClassRequest >& atoms ) throw(); 109cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getRecentAtoms( sal_Int32 atomClass, sal_Int32 atom ) throw(); 110cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getAtom( sal_Int32 atomClass, const ::rtl::OUString& description, sal_Bool create ) throw(); 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir class AtomClient 114cdf0e10cSrcweir { 115cdf0e10cSrcweir private: 116cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer > m_xServer; 117cdf0e10cSrcweir MultiAtomProvider m_aProvider; 118cdf0e10cSrcweir public: 119cdf0e10cSrcweir AtomClient( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer >& ); 120cdf0e10cSrcweir ~AtomClient(); 121cdf0e10cSrcweir 122cdf0e10cSrcweir void updateAtomClasses( const ::com::sun::star::uno::Sequence< sal_Int32 >& atomClasses ); 123cdf0e10cSrcweir int getAtom( int atomClass, const ::rtl::OUString& description, sal_Bool bCreate ); 124cdf0e10cSrcweir const ::rtl::OUString& getString( int atomClass, int atom ); 125cdf0e10cSrcweir }; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir #endif 129