1 #ifndef __COMPHELPER_UNOINTERFACETOUNIQUEIDENTIFIERMAPPER__
2 #define __COMPHELPER_UNOINTERFACETOUNIQUEIDENTIFIERMAPPER__
3 
4 #include <map>
5 #include <rtl/ustring.hxx>
6 #include <com/sun/star/uno/XInterface.hpp>
7 
8 namespace comphelper
9 {
10 
11 typedef ::std::map< rtl::OUString, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > IdMap_t;
12 
13 class UnoInterfaceToUniqueIdentifierMapper
14 {
15 public:
16 	UnoInterfaceToUniqueIdentifierMapper();
17 
18 	/** returns a unique identifier for the given uno object. IF a uno object is
19 		registered more than once, the returned identifier is always the same.
20 	*/
21 	const rtl::OUString& registerReference( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface );
22 
23 	/** registers the given uno object with the given identifier.
24 
25 		@returns
26 			false, if the given identifier already exists and is not associated with the given interface
27 	*/
28 	bool registerReference( const rtl::OUString& rIdentifier, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface );
29 
30 	/** @returns
31 			the identifier for the given uno object. If this uno object is not already
32 			registered, an empty string is returned
33 	*/
34 	const rtl::OUString& getIdentifier( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface ) const;
35 
36 	/** @returns
37 		the uno object that is registered with the given identifier. If no uno object
38 		is registered with the given identifier, an empty reference is returned.
39 	*/
40 	const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& getReference( const rtl::OUString& rIdentifier ) const;
41 
42 private:
43 	bool findReference( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface, IdMap_t::const_iterator& rIter ) const;
44 	bool findIdentifier( const rtl::OUString& rIdentifier, IdMap_t::const_iterator& rIter ) const;
45 
46 	IdMap_t	maEntries;
47 	sal_Int32 mnNextId;
48 };
49 
50 }
51 
52 #endif
53