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