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