Line data Source code
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 : #include "grouptable.hxx"
21 :
22 : using ::com::sun::star::uno::Reference;
23 : using ::com::sun::star::container::XIndexAccess;
24 :
25 29 : GroupTable::GroupTable()
26 : : mnIndex(0)
27 : , mnCurrentGroupEntry(0)
28 : , mnMaxGroupEntry(0)
29 : , mnGroupsClosed(0)
30 29 : , mpGroupEntry(NULL)
31 : {
32 29 : ImplResizeGroupTable( 32 );
33 29 : }
34 :
35 29 : GroupTable::~GroupTable()
36 : {
37 29 : for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; delete mpGroupEntry[ i++ ] ) ;
38 29 : delete[] mpGroupEntry;
39 29 : }
40 :
41 29 : void GroupTable::ImplResizeGroupTable( sal_uInt32 nEntrys )
42 : {
43 29 : if ( nEntrys > mnMaxGroupEntry )
44 : {
45 29 : mnMaxGroupEntry = nEntrys;
46 29 : GroupEntry** pTemp = new GroupEntry*[ nEntrys ];
47 29 : for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; i++ )
48 0 : pTemp[ i ] = mpGroupEntry[ i ];
49 29 : if ( mpGroupEntry )
50 0 : delete[] mpGroupEntry;
51 29 : mpGroupEntry = pTemp;
52 : }
53 29 : }
54 :
55 10 : bool GroupTable::EnterGroup( ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rXIndexAccessRef )
56 : {
57 10 : bool bRet = false;
58 10 : if ( rXIndexAccessRef.is() )
59 : {
60 10 : GroupEntry* pNewGroup = new GroupEntry( rXIndexAccessRef );
61 10 : if ( pNewGroup->mnCount )
62 : {
63 5 : if ( mnMaxGroupEntry == mnCurrentGroupEntry )
64 0 : ImplResizeGroupTable( mnMaxGroupEntry + 8 );
65 5 : mpGroupEntry[ mnCurrentGroupEntry++ ] = pNewGroup;
66 5 : bRet = true;
67 : }
68 : else
69 5 : delete pNewGroup;
70 : }
71 10 : return bRet;
72 : }
73 :
74 1143 : sal_uInt32 GroupTable::GetGroupsClosed()
75 : {
76 1143 : sal_uInt32 nRet = mnGroupsClosed;
77 1143 : mnGroupsClosed = 0;
78 1143 : return nRet;
79 : }
80 :
81 402 : void GroupTable::ClearGroupTable()
82 : {
83 402 : for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; i++, delete mpGroupEntry[ i ] ) ;
84 402 : mnCurrentGroupEntry = 0;
85 402 : }
86 :
87 386 : void GroupTable::ResetGroupTable( sal_uInt32 nCount )
88 : {
89 386 : ClearGroupTable();
90 386 : mpGroupEntry[ mnCurrentGroupEntry++ ] = new GroupEntry( nCount );
91 386 : }
92 :
93 1513 : bool GroupTable::GetNextGroupEntry()
94 : {
95 3417 : while ( mnCurrentGroupEntry )
96 : {
97 1518 : mnIndex = mpGroupEntry[ mnCurrentGroupEntry - 1 ]->mnCurrentPos++;
98 :
99 1518 : if ( mpGroupEntry[ mnCurrentGroupEntry - 1 ]->mnCount > mnIndex )
100 1127 : return true;
101 :
102 391 : delete ( mpGroupEntry[ --mnCurrentGroupEntry ] );
103 :
104 391 : if ( mnCurrentGroupEntry )
105 5 : mnGroupsClosed++;
106 : }
107 386 : return false;
108 : }
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|