bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / NameContainer.cxx
blob130d277329f6ea6e4092ced67e8d568cf5de796c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "NameContainer.hxx"
23 #include <com/sun/star/uno/Any.hxx>
25 using namespace ::com::sun::star;
26 using ::com::sun::star::uno::Sequence;
27 using ::com::sun::star::uno::Any;
30 //.............................................................................
31 namespace chart
33 //.............................................................................
35 uno::Reference< container::XNameContainer > createNameContainer(
36 const ::com::sun::star::uno::Type& rType, const OUString& rServicename, const OUString& rImplementationName )
38 return new NameContainer( rType, rServicename, rImplementationName );
41 NameContainer::NameContainer( const ::com::sun::star::uno::Type& rType, const OUString& rServicename, const OUString& rImplementationName )
42 : m_aType( rType )
43 , m_aServicename( rServicename )
44 , m_aImplementationName( rImplementationName )
45 , m_aMap()
49 NameContainer::NameContainer(
50 const NameContainer & rOther )
51 : impl::NameContainer_Base()
52 , m_aType( rOther.m_aType )
53 , m_aServicename( rOther.m_aServicename )
54 , m_aImplementationName( rOther.m_aImplementationName )
55 , m_aMap( rOther.m_aMap )
59 NameContainer::~NameContainer()
63 //XServiceInfo
64 OUString SAL_CALL NameContainer::getImplementationName()
65 throw( ::com::sun::star::uno::RuntimeException )
67 return m_aImplementationName;
70 sal_Bool SAL_CALL NameContainer::supportsService( const OUString& ServiceName )
71 throw( ::com::sun::star::uno::RuntimeException )
73 Sequence< OUString > aSNL = getSupportedServiceNames();
74 const OUString* pArray = aSNL.getArray();
75 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
77 if( pArray[ i ] == ServiceName )
78 return sal_True;
80 return sal_False;
83 Sequence< OUString > SAL_CALL NameContainer::getSupportedServiceNames()
84 throw( ::com::sun::star::uno::RuntimeException )
86 Sequence< OUString > aSNS( 1 );
87 aSNS.getArray()[ 0 ] = m_aServicename;
88 return aSNS;
91 //-----------------------------------------------------------------
92 //-----------------------------------------------------------------
93 //-----------------------------------------------------------------
95 // XNameContainer
96 void SAL_CALL NameContainer::insertByName( const OUString& rName, const Any& rElement )
97 throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
99 if( m_aMap.find( rName ) != m_aMap.end() )
100 throw container::ElementExistException();
101 m_aMap.insert( tContentMap::value_type( rName, rElement ));
106 void SAL_CALL NameContainer::removeByName( const OUString& Name )
107 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
109 tContentMap::iterator aIt( m_aMap.find( Name ));
110 if( aIt == m_aMap.end())
111 throw container::NoSuchElementException();
112 m_aMap.erase( aIt );
115 // XNameReplace
116 void SAL_CALL NameContainer::replaceByName( const OUString& rName, const Any& rElement )
117 throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
119 tContentMap::iterator aIt( m_aMap.find( rName ));
120 if( aIt == m_aMap.end() )
121 throw container::NoSuchElementException();
122 aIt->second = rElement;
125 // XNameAccess
126 Any SAL_CALL NameContainer::getByName( const OUString& rName )
127 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
129 tContentMap::iterator aIter( m_aMap.find( rName ) );
130 if( aIter == m_aMap.end() )
131 throw container::NoSuchElementException();
132 return aIter->second;
135 Sequence< OUString > SAL_CALL NameContainer::getElementNames()
136 throw( uno::RuntimeException )
138 sal_Int32 nCount = m_aMap.size();
139 Sequence< OUString > aSeq(nCount);
140 sal_Int32 nN = 0;
141 for( tContentMap::iterator aIter = m_aMap.begin(); aIter != m_aMap.end() && nN < nCount; ++aIter, ++nN )
142 aSeq[nN]=aIter->first;
143 return aSeq;
146 sal_Bool SAL_CALL NameContainer::hasByName( const OUString& rName )
147 throw( uno::RuntimeException )
149 return ( m_aMap.find( rName ) != m_aMap.end() );
152 // XElementAccess
153 sal_Bool SAL_CALL NameContainer::hasElements()
154 throw( uno::RuntimeException )
156 return ! m_aMap.empty();
159 uno::Type SAL_CALL NameContainer::getElementType()
160 throw( uno::RuntimeException )
162 return m_aType;
165 // XCloneable
166 uno::Reference< util::XCloneable > SAL_CALL NameContainer::createClone()
167 throw ( uno::RuntimeException )
169 return uno::Reference< util::XCloneable >( new NameContainer( *this ));
172 //.............................................................................
173 } //namespace chart
174 //.............................................................................
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */