1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <NameContainer.hxx>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 using namespace ::com::sun::star
;
26 using ::com::sun::star::uno::Sequence
;
27 using ::com::sun::star::uno::Any
;
32 uno::Reference
< container::XNameContainer
> createNameContainer(
33 const css::uno::Type
& rType
, const OUString
& rServicename
, const OUString
& rImplementationName
)
35 return new NameContainer( rType
, rServicename
, rImplementationName
);
38 NameContainer::NameContainer( const css::uno::Type
& rType
, const OUString
& rServicename
, const OUString
& rImplementationName
)
40 , m_aServicename( rServicename
)
41 , m_aImplementationName( rImplementationName
)
46 NameContainer::NameContainer(
47 const NameContainer
& rOther
)
48 : impl::NameContainer_Base(rOther
)
49 , m_aType( rOther
.m_aType
)
50 , m_aServicename( rOther
.m_aServicename
)
51 , m_aImplementationName( rOther
.m_aImplementationName
)
52 , m_aMap( rOther
.m_aMap
)
56 NameContainer::~NameContainer()
61 OUString SAL_CALL
NameContainer::getImplementationName()
63 return m_aImplementationName
;
66 sal_Bool SAL_CALL
NameContainer::supportsService( const OUString
& ServiceName
)
68 return cppu::supportsService(this, ServiceName
);
71 Sequence
< OUString
> SAL_CALL
NameContainer::getSupportedServiceNames()
73 return { m_aServicename
};
77 void SAL_CALL
NameContainer::insertByName( const OUString
& rName
, const Any
& rElement
)
79 if( m_aMap
.find( rName
) != m_aMap
.end() )
80 throw container::ElementExistException();
81 m_aMap
.emplace( rName
, rElement
);
84 void SAL_CALL
NameContainer::removeByName( const OUString
& Name
)
86 tContentMap::iterator
aIt( m_aMap
.find( Name
));
87 if( aIt
== m_aMap
.end())
88 throw container::NoSuchElementException();
93 void SAL_CALL
NameContainer::replaceByName( const OUString
& rName
, const Any
& rElement
)
95 tContentMap::iterator
aIt( m_aMap
.find( rName
));
96 if( aIt
== m_aMap
.end() )
97 throw container::NoSuchElementException();
98 aIt
->second
= rElement
;
102 Any SAL_CALL
NameContainer::getByName( const OUString
& rName
)
104 tContentMap::iterator
aIter( m_aMap
.find( rName
) );
105 if( aIter
== m_aMap
.end() )
106 throw container::NoSuchElementException();
107 return aIter
->second
;
110 Sequence
< OUString
> SAL_CALL
NameContainer::getElementNames()
112 sal_Int32 nCount
= m_aMap
.size();
113 Sequence
< OUString
> aSeq(nCount
);
115 for (auto const& elem
: m_aMap
)
117 aSeq
[nN
++]=elem
.first
;
122 sal_Bool SAL_CALL
NameContainer::hasByName( const OUString
& rName
)
124 return ( m_aMap
.find( rName
) != m_aMap
.end() );
128 sal_Bool SAL_CALL
NameContainer::hasElements()
130 return ! m_aMap
.empty();
133 uno::Type SAL_CALL
NameContainer::getElementType()
139 uno::Reference
< util::XCloneable
> SAL_CALL
NameContainer::createClone()
141 return uno::Reference
< util::XCloneable
>( new NameContainer( *this ));
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */