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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 
27 #include "comphelper/serviceinfohelper.hxx"
28 #include <stdarg.h>
29 
30 // #####################################################################
31 
32 namespace comphelper
33 {
34 
35 /** returns an empty UString(). most times sufficient */
getImplementationName()36 ::rtl::OUString SAL_CALL ServiceInfoHelper::getImplementationName() throw( ::com::sun::star::uno::RuntimeException )
37 {
38 	return ::rtl::OUString();
39 }
40 
41 /** the base implementation iterates over the service names from <code>getSupportedServiceNames</code> */
supportsService(const::rtl::OUString & ServiceName)42 sal_Bool SAL_CALL ServiceInfoHelper::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
43 {
44 	return supportsService( ServiceName, getSupportedServiceNames() );
45 }
46 
supportsService(const::rtl::OUString & ServiceName,const::com::sun::star::uno::Sequence<::rtl::OUString> & SupportedServices)47 sal_Bool SAL_CALL ServiceInfoHelper::supportsService( const ::rtl::OUString& ServiceName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& SupportedServices ) throw()
48 {
49 	const ::rtl::OUString * pArray = SupportedServices.getConstArray();
50 	for( sal_Int32 i = 0; i < SupportedServices.getLength(); i++ )
51 		if( pArray[i] == ServiceName )
52 			return sal_True;
53 	return sal_False;
54 }
55 
56 /** the base implementation has no supported services */
getSupportedServiceNames(void)57 ::com::sun::star::uno::Sequence< ::rtl::OUString > ServiceInfoHelper::getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException )
58 {
59 	::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq(0);
60 	return aSeq;
61 }
62 
63 /** this method concatenates the given sequences and returns the result
64  */
concatSequences(const::com::sun::star::uno::Sequence<::rtl::OUString> & rSeq1,const::com::sun::star::uno::Sequence<::rtl::OUString> & rSeq2)65 ::com::sun::star::uno::Sequence< ::rtl::OUString > ServiceInfoHelper::concatSequences( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq1,
66 		const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq2 ) throw()
67 {
68 	const sal_Int32 nLen1 = rSeq1.getLength();
69 	const sal_Int32 nLen2 = rSeq2.getLength();
70 
71 	::com::sun::star::uno::Sequence< ::rtl::OUString > aSeq( nLen1 + nLen2 );
72 
73 	::rtl::OUString* pStrings = aSeq.getArray();
74 
75 	sal_Int32 nIdx;
76 	const ::rtl::OUString* pStringSrc = rSeq1.getConstArray();
77 	for( nIdx = 0; nIdx < nLen1; nIdx++ )
78 		*pStrings++ = *pStringSrc++;
79 
80 	pStringSrc = rSeq2.getConstArray();
81 	for( nIdx = 0; nIdx < nLen2; nIdx++ )
82 		*pStrings++ = *pStringSrc++;
83 
84 	return aSeq;
85 }
86 
87 /** this method adds a variable number of char pointer to a given Sequence
88  */
addToSequence(::com::sun::star::uno::Sequence<::rtl::OUString> & rSeq,sal_uInt16 nServices,...)89 void ServiceInfoHelper::addToSequence( ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq, sal_uInt16 nServices, /* char * */ ... ) throw()
90 {
91 	sal_uInt32 nCount = rSeq.getLength();
92 
93 	rSeq.realloc( nCount + nServices );
94 	rtl::OUString* pStrings = rSeq.getArray();
95 
96 	va_list marker;
97 	va_start( marker, nServices );
98 	for( sal_uInt16 i = 0 ; i < nServices; i++ )
99 		pStrings[nCount++] = rtl::OUString::createFromAscii(va_arg( marker, char*));
100 	va_end( marker );
101 }
102 
103 }
104 
105 
106