GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / slstitm.cxx
blob5b8ec5a16ac35aa4a6611602b8675aec1c80a7ec
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 <svl/slstitm.hxx>
22 #include <svl/poolitem.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <tools/stream.hxx>
27 // STATIC DATA -----------------------------------------------------------
29 DBG_NAME(SfxStringListItem)
31 // -----------------------------------------------------------------------
33 TYPEINIT1_AUTOFACTORY(SfxStringListItem, SfxPoolItem);
35 class SfxImpStringList
37 public:
38 sal_uInt16 nRefCount;
39 std::vector<OUString> aList;
41 SfxImpStringList() { nRefCount = 1; }
42 ~SfxImpStringList();
46 SfxImpStringList::~SfxImpStringList()
48 DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted");
49 nRefCount = 0xffff;
52 // class SfxStringListItem -----------------------------------------------
54 SfxStringListItem::SfxStringListItem() :
55 pImp(NULL)
60 SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<OUString>* pList ) :
61 SfxPoolItem( which ),
62 pImp(NULL)
64 // PB: das Putten einer leeren Liste funktionierte nicht,
65 // deshalb habe ich hier die Abfrage nach dem Count auskommentiert
66 if( pList /*!!! && pList->Count() */ )
68 pImp = new SfxImpStringList;
70 if (pImp)
71 pImp->aList = *pList;
76 SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) :
77 SfxPoolItem( which ),
78 pImp(NULL)
80 //fdo#39428 SvStream no longer supports operator>>(long&)
81 sal_Int32 nEntryCount;
82 rStream >> nEntryCount;
84 if( nEntryCount )
85 pImp = new SfxImpStringList;
87 if (pImp)
89 for( sal_Int32 i=0; i < nEntryCount; i++ )
91 pImp->aList.push_back( readByteString(rStream) );
97 SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) :
98 SfxPoolItem( rItem ),
99 pImp(rItem.pImp)
101 if( pImp )
103 DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
104 pImp->nRefCount++;
109 SfxStringListItem::~SfxStringListItem()
111 if( pImp )
113 DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
114 if( pImp->nRefCount > 1 )
115 pImp->nRefCount--;
116 else
117 delete pImp;
122 std::vector<OUString>& SfxStringListItem::GetList()
124 if( !pImp )
125 pImp = new SfxImpStringList;
126 DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
127 return pImp->aList;
130 const std::vector<OUString>& SfxStringListItem::GetList () const
132 return (const_cast< SfxStringListItem * >(this))->GetList();
136 int SfxStringListItem::operator==( const SfxPoolItem& rItem ) const
138 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
140 SfxStringListItem* pItem = (SfxStringListItem*)&rItem;
142 return pImp == pItem->pImp;
146 SfxItemPresentation SfxStringListItem::GetPresentation
148 SfxItemPresentation /*ePresentation*/,
149 SfxMapUnit /*eCoreMetric*/,
150 SfxMapUnit /*ePresentationMetric*/,
151 OUString& rText,
152 const IntlWrapper *
153 ) const
155 rText = "(List)";
156 return SFX_ITEM_PRESENTATION_NONE;
160 SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const
162 return new SfxStringListItem( *this );
164 if( pImp )
165 return new SfxStringListItem( Which(), &(pImp->aList) );
166 else
167 return new SfxStringListItem( Which(), NULL );
173 SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, sal_uInt16 ) const
175 return new SfxStringListItem( Which(), rStream );
179 SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const
181 if( !pImp )
183 //fdo#39428 SvStream no longer supports operator<<(long)
184 rStream << (sal_Int32) 0;
185 return rStream;
188 DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
190 sal_uInt32 nCount = pImp->aList.size();
191 rStream << nCount;
193 for( sal_uInt32 i=0; i < nCount; i++ )
194 writeByteString(rStream, pImp->aList[i]);
196 return rStream;
200 void SfxStringListItem::SetString( const OUString& rStr )
202 DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
204 if ( pImp && (pImp->nRefCount == 1) )
205 delete pImp;
206 else if( pImp )
207 pImp->nRefCount--;
208 pImp = new SfxImpStringList;
210 sal_Int32 nStart = 0;
211 OUString aStr(convertLineEnd(rStr, LINEEND_CR));
212 for (;;)
214 const sal_Int32 nDelimPos = aStr.indexOf( '\r', nStart );
215 if ( nDelimPos < 0 )
217 if (nStart<aStr.getLength())
219 // put last string only if not empty
220 pImp->aList.push_back(aStr.copy(nStart));
222 break;
225 pImp->aList.push_back(aStr.copy(nStart, nDelimPos-nStart));
227 // skip both inserted string and delimiter
228 nStart = nDelimPos + 1 ;
233 OUString SfxStringListItem::GetString()
235 OUString aStr;
236 if ( pImp )
238 DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
240 std::vector<OUString>::iterator iter = pImp->aList.begin();
241 for (;;)
243 aStr += *iter;
244 ++iter;
246 if (iter == pImp->aList.end())
247 break;
249 aStr += "\r";
252 return convertLineEnd(aStr, GetSystemLineEnd());
256 void SfxStringListItem::SetStringList( const com::sun::star::uno::Sequence< OUString >& rList )
258 DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
260 if ( pImp && (pImp->nRefCount == 1) )
261 delete pImp;
262 else if( pImp )
263 pImp->nRefCount--;
264 pImp = new SfxImpStringList;
266 if (pImp)
268 // String gehoert der Liste
269 for ( sal_Int32 n = 0; n < rList.getLength(); n++ )
270 pImp->aList.push_back(rList[n]);
274 void SfxStringListItem::GetStringList( com::sun::star::uno::Sequence< OUString >& rList ) const
276 long nCount = pImp->aList.size();
278 rList.realloc( nCount );
279 for( long i=0; i < nCount; i++ )
280 rList[i] = pImp->aList[i];
283 // virtual
284 bool SfxStringListItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
286 com::sun::star::uno::Sequence< OUString > aValue;
287 if ( rVal >>= aValue )
289 SetStringList( aValue );
290 return true;
293 OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
294 return false;
297 // virtual
298 bool SfxStringListItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
300 // GetString() is not const!!!
301 SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this );
303 com::sun::star::uno::Sequence< OUString > aStringList;
304 pThis->GetStringList( aStringList );
305 rVal = ::com::sun::star::uno::makeAny( aStringList );
306 return true;
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */