xref: /aoo4110/main/unotools/inc/unotools/atom.hxx (revision b1cdbd2c)
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 _UTL_ATOM_HXX_
24 #define _UTL_ATOM_HXX_
25 
26 #include "unotools/unotoolsdllapi.h"
27 #include <rtl/ustring.hxx>
28 #include <osl/mutex.hxx>
29 #include <cppuhelper/implbase1.hxx>
30 
31 #include <hash_map>
32 #ifndef __SGI_STL_LIST
33 #include <list>
34 #endif
35 #include <com/sun/star/util/XAtomServer.hpp>
36 
37 #define INVALID_ATOM 0
38 
39 namespace utl {
40 
41     struct AtomDescription
42     {
43         int                 atom;
44         ::rtl::OUString     description;
45     };
46 
47     class AtomProvider
48     {
49         int                                     m_nAtoms;
50         ::std::hash_map< int, ::rtl::OUString, ::std::hash< int > > m_aStringMap;
51         ::std::hash_map< ::rtl::OUString, int, ::rtl::OUStringHash >    m_aAtomMap;
52     public:
53         AtomProvider();
54         ~AtomProvider();
55 
56         int getAtom( const ::rtl::OUString&, sal_Bool bCreate = sal_False );
getLastAtom() const57         int getLastAtom() const { return m_nAtoms-1; }
58         const ::rtl::OUString& getString( int ) const;
59 
60         void getAll( ::std::list< AtomDescription >& atoms );
61 
62         void getRecent( int atom, ::std::list< AtomDescription >& atoms );
63 
64         void overrideAtom( int atom, const ::rtl::OUString& description );
65 
66         sal_Bool hasAtom( int atom ) const;
67     };
68 
69 
70     class UNOTOOLS_DLLPUBLIC MultiAtomProvider
71     {
72         ::std::hash_map< int, AtomProvider*, ::std::hash< int > > m_aAtomLists;
73     public:
74         MultiAtomProvider();
75         ~MultiAtomProvider();
76 
77         int getLastAtom( int atomClass ) const;
78 
79         sal_Bool insertAtomClass( int atomClass );
80 
81         int getAtom( int atomClass, const ::rtl::OUString& rString, sal_Bool bCreate = sal_False );
82 
83         void getRecent( int atomClass, int atom, ::std::list< AtomDescription >& atoms );
84 
85         const ::rtl::OUString& getString( int atomClass, int atom ) const;
86         void getClass( int atomClass, ::std::list< AtomDescription >& atoms ) const;
87 
88         void overrideAtom( int atomClass, int atom, const ::rtl::OUString& description );
overrideAtom(int atomClass,const::com::sun::star::util::AtomDescription & newDescription)89         void overrideAtom( int atomClass, const ::com::sun::star::util::AtomDescription& newDescription )
90             { overrideAtom( atomClass, newDescription.atom, newDescription.description ); }
91         sal_Bool hasAtom( int atomClass, int atom ) const;
92     };
93 
94     class AtomServer : public ::cppu::WeakAggImplHelper1< ::com::sun::star::util::XAtomServer >
95     {
96     private:
97         MultiAtomProvider   m_aProvider;
98         ::osl::Mutex        m_aMutex;
99     public:
100         AtomServer();
101         virtual ~AtomServer();
102 
getString(int atomClass,int atom) const103         const ::rtl::OUString& getString( int atomClass, int atom ) const
104             { return m_aProvider.getString( atomClass, atom ); }
105 
106         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getClass( sal_Int32 atomClass ) throw();
107         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();
108         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAtomDescriptions( const ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomClassRequest >& atoms ) throw();
109         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getRecentAtoms( sal_Int32 atomClass, sal_Int32 atom ) throw();
110         virtual sal_Int32 SAL_CALL getAtom( sal_Int32 atomClass, const ::rtl::OUString& description, sal_Bool create ) throw();
111     };
112 
113     class AtomClient
114     {
115     private:
116         ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer >     m_xServer;
117         MultiAtomProvider m_aProvider;
118     public:
119         AtomClient( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer >& );
120         ~AtomClient();
121 
122         void updateAtomClasses( const ::com::sun::star::uno::Sequence< sal_Int32 >& atomClasses );
123         int getAtom( int atomClass, const ::rtl::OUString& description, sal_Bool bCreate );
124         const ::rtl::OUString& getString( int atomClass, int atom );
125     };
126 }
127 
128 #endif
129