GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / rngitem.cxx
blobefc4d8134075afac803ba58bae4d53ecd1db862d
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 .
20 #include <tools/stream.hxx>
21 #include <svl/rngitem.hxx>
23 static inline sal_uInt16 Count_Impl(const sal_uInt16 * pRanges)
25 sal_uInt16 nCount = 0;
26 for (; *pRanges; pRanges += 2) nCount += 2;
27 return nCount;
30 // -----------------------------------------------------------------------
32 TYPEINIT1_AUTOFACTORY(SfxRangeItem, SfxPoolItem);
33 TYPEINIT1_AUTOFACTORY(SfxUShortRangesItem, SfxPoolItem);
35 sal_uInt16 Count_Impl( const sal_uInt16 *pRanges );
37 // -----------------------------------------------------------------------
39 SfxRangeItem::SfxRangeItem()
41 nFrom = 0;
42 nTo = 0;
45 // -----------------------------------------------------------------------
47 SfxRangeItem::SfxRangeItem( sal_uInt16 which, sal_uInt16 from, sal_uInt16 to ):
48 SfxPoolItem( which ),
49 nFrom( from ),
50 nTo( to )
54 // -----------------------------------------------------------------------
56 SfxRangeItem::SfxRangeItem( const SfxRangeItem& rItem ) :
57 SfxPoolItem( rItem )
59 nFrom = rItem.nFrom;
60 nTo = rItem.nTo;
63 // -----------------------------------------------------------------------
65 SfxItemPresentation SfxRangeItem::GetPresentation
67 SfxItemPresentation /*ePresentation*/,
68 SfxMapUnit /*eCoreMetric*/,
69 SfxMapUnit /*ePresentationMetric*/,
70 OUString& rText,
71 const IntlWrapper *
72 ) const
74 rText = OUString::number(nFrom) + ":" + OUString::number(nTo);
75 return SFX_ITEM_PRESENTATION_NAMELESS;
78 // -----------------------------------------------------------------------
80 int SfxRangeItem::operator==( const SfxPoolItem& rItem ) const
82 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
83 SfxRangeItem* pT = (SfxRangeItem*)&rItem;
84 if( nFrom==pT->nFrom && nTo==pT->nTo )
85 return 1;
86 return 0;
89 // -----------------------------------------------------------------------
91 SfxPoolItem* SfxRangeItem::Clone(SfxItemPool *) const
93 return new SfxRangeItem( Which(), nFrom, nTo );
96 // -----------------------------------------------------------------------
98 SfxPoolItem* SfxRangeItem::Create(SvStream &rStream, sal_uInt16) const
100 sal_uInt16 nVon(0), nBis(0);
101 rStream >> nVon;
102 rStream >> nBis;
103 return new SfxRangeItem( Which(), nVon, nBis );
106 // -----------------------------------------------------------------------
108 SvStream& SfxRangeItem::Store(SvStream &rStream, sal_uInt16) const
110 rStream << nFrom;
111 rStream << nTo;
112 return rStream;
116 SfxUShortRangesItem::SfxUShortRangesItem()
117 : _pRanges(0)
122 SfxUShortRangesItem::SfxUShortRangesItem( sal_uInt16 nWID, SvStream &rStream )
123 : SfxPoolItem( nWID )
125 sal_uInt16 nCount(0);
126 rStream >> nCount;
127 _pRanges = new sal_uInt16[nCount + 1];
128 for ( sal_uInt16 n = 0; n < nCount; ++n )
129 rStream >> _pRanges[n];
130 _pRanges[nCount] = 0;
134 SfxUShortRangesItem::SfxUShortRangesItem( const SfxUShortRangesItem& rItem )
135 : SfxPoolItem( rItem )
137 sal_uInt16 nCount = Count_Impl(rItem._pRanges) + 1;
138 _pRanges = new sal_uInt16[nCount];
139 memcpy( _pRanges, rItem._pRanges, sizeof(sal_uInt16) * nCount );
143 SfxUShortRangesItem::~SfxUShortRangesItem()
145 delete _pRanges;
149 int SfxUShortRangesItem::operator==( const SfxPoolItem &rItem ) const
151 const SfxUShortRangesItem &rOther = (const SfxUShortRangesItem&) rItem;
152 if ( !_pRanges && !rOther._pRanges )
153 return sal_True;
154 if ( _pRanges || rOther._pRanges )
155 return sal_False;
157 sal_uInt16 n;
158 for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n )
159 if ( *_pRanges != rOther._pRanges[n] )
160 return 0;
162 return !_pRanges[n] && !rOther._pRanges[n];
166 SfxItemPresentation SfxUShortRangesItem::GetPresentation( SfxItemPresentation /*ePres*/,
167 SfxMapUnit /*eCoreMetric*/,
168 SfxMapUnit /*ePresMetric*/,
169 OUString & /*rText*/,
170 const IntlWrapper * ) const
172 // not implemented
173 return SFX_ITEM_PRESENTATION_NONE;
177 SfxPoolItem* SfxUShortRangesItem::Clone( SfxItemPool * ) const
179 return new SfxUShortRangesItem( *this );
183 SfxPoolItem* SfxUShortRangesItem::Create( SvStream &rStream, sal_uInt16 ) const
185 return new SfxUShortRangesItem( Which(), rStream );
189 SvStream& SfxUShortRangesItem::Store( SvStream &rStream, sal_uInt16 ) const
191 sal_uInt16 nCount = Count_Impl( _pRanges );
192 rStream >> nCount;
193 for ( sal_uInt16 n = 0; _pRanges[n]; ++n )
194 rStream >> _pRanges[n];
195 return rStream;
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */