fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / starcalc / collect.cxx
blobdcc20858b474bd202ec559e1285208675c59c94f
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 "collect.hxx"
22 #include <string.h>
24 #define MAXCOLLECTIONSIZE 16384
25 #define MAXDELTA 1024
27 ScDataObject::~ScDataObject()
31 // Collection
33 static void lcl_DeleteScDataObjects( ScDataObject** p, sal_uInt16 nCount )
35 if ( p )
37 for (sal_uInt16 i = 0; i < nCount; i++) delete p[i];
38 delete[] p;
42 ScCollection::ScCollection(sal_uInt16 nLim, sal_uInt16 nDel) :
43 nCount ( 0 ),
44 nLimit ( nLim ),
45 nDelta ( nDel ),
46 pItems ( NULL )
48 if (nDelta > MAXDELTA)
49 nDelta = MAXDELTA;
50 else if (nDelta == 0)
51 nDelta = 1;
52 if (nLimit > MAXCOLLECTIONSIZE)
53 nLimit = MAXCOLLECTIONSIZE;
54 else if (nLimit < nDelta)
55 nLimit = nDelta;
56 pItems = new ScDataObject*[nLimit];
59 ScCollection::ScCollection(const ScCollection& rCollection)
60 : ScDataObject(),
61 nCount ( 0 ),
62 nLimit ( 0 ),
63 nDelta ( 0 ),
64 pItems ( NULL )
66 *this = rCollection;
69 ScCollection::~ScCollection()
71 lcl_DeleteScDataObjects( pItems, nCount );
74 bool ScCollection::AtInsert(sal_uInt16 nIndex, ScDataObject* pScDataObject)
76 if ((nCount < MAXCOLLECTIONSIZE) && (nIndex <= nCount) && pItems)
78 if (nCount == nLimit)
80 ScDataObject** pNewItems = new ScDataObject*[nLimit + nDelta];
81 if (!pNewItems)
82 return false;
83 nLimit = sal::static_int_cast<sal_uInt16>( nLimit + nDelta );
84 memcpy(pNewItems, pItems, nCount * sizeof(ScDataObject*));
85 delete[] pItems;
86 pItems = pNewItems;
88 if (nCount > nIndex)
89 memmove(&pItems[nIndex + 1], &pItems[nIndex], (nCount - nIndex) * sizeof(ScDataObject*));
90 pItems[nIndex] = pScDataObject;
91 nCount++;
92 return true;
94 return false;
97 bool ScCollection::Insert(ScDataObject* pScDataObject)
99 return AtInsert(nCount, pScDataObject);
102 ScDataObject* ScCollection::At(sal_uInt16 nIndex) const
104 if (nIndex < nCount)
105 return pItems[nIndex];
106 else
107 return NULL;
110 ScCollection& ScCollection::operator=( const ScCollection& r )
112 // Check for self-assignment
113 if (this == &r)
114 return *this;
116 lcl_DeleteScDataObjects( pItems, nCount );
118 nCount = r.nCount;
119 nLimit = r.nLimit;
120 nDelta = r.nDelta;
121 pItems = new ScDataObject*[nLimit];
122 for ( sal_uInt16 i=0; i<nCount; i++ )
123 pItems[i] = r.pItems[i]->Clone();
125 return *this;
128 ScDataObject* ScCollection::Clone() const
130 return new ScCollection(*this);
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */