LibreOffice Module comphelper (master)  1
propertysetinfo.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
22 #include <comphelper/sequence.hxx>
23 #include <vector>
24 
25 
26 using namespace ::comphelper;
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::beans;
30 using namespace ::com::sun::star::lang;
31 
32 void PropertySetInfo::addImpl(PropertyMapEntry const * pMap) noexcept
33 {
34  while (!pMap->maName.isEmpty())
35  {
36  // check for duplicates
37  assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end());
38 
39  maPropertyMap[pMap->maName] = pMap;
40 
41  maProperties.clear();
42 
43  ++pMap;
44  }
45 }
46 
47 PropertySetInfo::PropertySetInfo() noexcept
48 {
49 }
50 
51 PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) noexcept
52 {
53  while (!pMap->maName.isEmpty())
54  {
55  // check for duplicates
56  assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end());
57 
58  maPropertyMap[pMap->maName] = pMap;
59 
60  ++pMap;
61  }
62 }
63 
64 PropertySetInfo::PropertySetInfo(uno::Sequence<beans::Property> const& rProps) noexcept
65 {
66  PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength() + 1]);
67  PropertyMapEntry * pEntry(&pEntries[0]);
68  for (auto const& it : rProps)
69  {
70  pEntry->maName = it.Name;
71  pEntry->mnHandle = it.Handle;
72  pEntry->maType = it.Type;
73  pEntry->mnAttributes = it.Attributes;
74  pEntry->mnMemberId = 0;
75  ++pEntry;
76  }
77  pEntry->maName = OUString();
78 
79  addImpl(pEntries);
80 }
81 
82 PropertySetInfo::~PropertySetInfo() noexcept
83 {
84 }
85 
86 void PropertySetInfo::add( PropertyMapEntry const * pMap ) noexcept
87 {
88  addImpl( pMap );
89 }
90 
91 void PropertySetInfo::remove( const OUString& aName ) noexcept
92 {
93  maPropertyMap.erase( aName );
94  maProperties.clear();
95 }
96 
97 Sequence< css::beans::Property > SAL_CALL PropertySetInfo::getProperties()
98 {
99  // maybe we have to generate the properties after
100  // a change in the property map or at first call
101  // to getProperties
102  if( maProperties.size() != maPropertyMap.size() )
103  {
104  maProperties.resize( maPropertyMap.size() );
105  auto propIter = maProperties.begin();
106 
107  for( const auto& rProperty : maPropertyMap )
108  {
109  PropertyMapEntry const * pEntry = rProperty.second;
110 
111  propIter->Name = pEntry->maName;
112  propIter->Handle = pEntry->mnHandle;
113  propIter->Type = pEntry->maType;
114  propIter->Attributes = pEntry->mnAttributes;
115 
116  ++propIter;
117  }
118  }
120 }
121 
122 Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName )
123 {
124  PropertyMap::iterator aIter = maPropertyMap.find( aName );
125 
126  if( maPropertyMap.end() == aIter )
127  throw UnknownPropertyException( aName );
128 
129  PropertyMapEntry const * pEntry = (*aIter).second;
130 
131  return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
132 }
133 
134 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& aName )
135 {
136  return maPropertyMap.find( aName ) != maPropertyMap.end();
137 }
138 
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int16 mnAttributes
flag bitmap,
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
Removes all occurrences of a character from within the source string.
Definition: string.hxx:50
SvGenericNameContainerMapImpl maProperties
unsigned char sal_Bool
std::pair< OUString const, DataAccessDescriptorProperty > PropertyMapEntry
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Copy from a container into a Sequence.
Definition: sequence.hxx:190
OUString aName