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