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 
24 
25 #include <osl/diagnose.h>
26 #ifndef _COM_SUN_STAR_XNAMECONTAINER_HPP_
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #endif
29 #ifndef _COM_SUN_STAR_XCONTAINER_HPP_
30 #include <com/sun/star/container/XContainer.hpp>
31 #endif
32 
33 #include <toolkit/helper/listenermultiplexer.hxx>
34 
35 #include <hash_map>
36 #include <cppuhelper/implbase2.hxx>
37 typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer,
38 								 ::com::sun::star::container::XContainer > NameContainerHelper;
39 
40 
41 namespace toolkit
42 {
43 
44 // Hashtable to optimize
45 struct hashName_Impl
46 {
operator ()toolkit::hashName_Impl47 	size_t operator()(const ::rtl::OUString Str) const
48 	{
49 		return (size_t)Str.hashCode();
50 	}
51 };
52 
53 struct eqName_Impl
54 {
operator ()toolkit::eqName_Impl55 	sal_Bool operator()(const ::rtl::OUString Str1, const ::rtl::OUString Str2) const
56 	{
57 		return ( Str1 == Str2 );
58 	}
59 };
60 
61 typedef std::hash_map
62 <
63 	::rtl::OUString,
64 	sal_Int32,
65 	hashName_Impl,
66 	eqName_Impl
67 >
68 NameContainerNameMap;
69 
70 
71 class NameContainer_Impl : public NameContainerHelper
72 {
73 	NameContainerNameMap mHashMap;
74 	::com::sun::star::uno::Sequence< ::rtl::OUString > mNames;
75 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > mValues;
76 	sal_Int32 mnElementCount;
77 	::com::sun::star::uno::Type mType;
78 
79 	ContainerListenerMultiplexer maContainerListeners;
80 
81 public:
NameContainer_Impl(::com::sun::star::uno::Type const & aType)82 	NameContainer_Impl( ::com::sun::star::uno::Type const & aType )
83 		: mnElementCount( 0 ),
84 		  mType( aType ),
85 		  maContainerListeners( *this )
86 	{
87 	}
88 
89     // Methods XElementAccess
90     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
91 		throw(::com::sun::star::uno::RuntimeException);
92     virtual sal_Bool SAL_CALL hasElements(  )
93 		throw(::com::sun::star::uno::RuntimeException);
94 
95     // Methods XNameAccess
96     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
97 		throw(::com::sun::star::container::NoSuchElementException,
98 			  ::com::sun::star::lang::WrappedTargetException,
99 			  ::com::sun::star::uno::RuntimeException);
100     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  )
101 		throw(::com::sun::star::uno::RuntimeException);
102     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
103 		throw(::com::sun::star::uno::RuntimeException);
104 
105     // Methods XNameReplace
106     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
107 		throw(::com::sun::star::lang::IllegalArgumentException,
108 			  ::com::sun::star::container::NoSuchElementException,
109 			  ::com::sun::star::lang::WrappedTargetException,
110 			  ::com::sun::star::uno::RuntimeException);
111 
112     // Methods XNameContainer
113     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
114 		throw(::com::sun::star::lang::IllegalArgumentException,
115 			  ::com::sun::star::container::ElementExistException,
116 			  ::com::sun::star::lang::WrappedTargetException,
117 			  ::com::sun::star::uno::RuntimeException);
118     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
119 		throw(::com::sun::star::container::NoSuchElementException,
120 			  ::com::sun::star::lang::WrappedTargetException,
121 			  ::com::sun::star::uno::RuntimeException);
122 
123 	// Methods XContainer
124     void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
125 		throw(::com::sun::star::uno::RuntimeException);
126     void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
127 		throw(::com::sun::star::uno::RuntimeException);
128 };
129 
130 class ScriptEventContainer : public NameContainer_Impl
131 {
132 public:
133 	ScriptEventContainer( void );
134 };
135 
136 
137 }	// namespace toolkit_namecontainer
138 
139