Update ooo320-m1
[ooovba.git] / sw / source / core / except / dbgloop.cxx
blob2998d7728ef42933c080c682f5cf69e0fc28b78d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbgloop.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef PRODUCT
35 #error Wer fummelt denn an den makefiles rum?
36 #endif
37 #include <tools/stream.hxx>
38 #include "dbgloop.hxx"
39 #include "errhdl.hxx"
41 DbgLoopStack DbgLoop::aDbgLoopStack;
43 /*************************************************************************
44 * class DbgLoopStack
45 *************************************************************************/
47 DbgLoopStack::DbgLoopStack()
49 Reset();
52 void DbgLoopStack::Reset()
54 nPtr = 0;
55 pDbg = 0;
56 for( USHORT i = 0; i < DBG_MAX_STACK; ++i )
57 aCount[i] = 0;
60 /*************************************************************************
61 * DbgLoopStack::Push()
62 *************************************************************************/
64 void DbgLoopStack::Push( const void *pThis )
66 // Wir muessen irgendwie mitbekommen, wann die erste Stackposition
67 // resettet werden soll, z.B. wenn wir einen Nullpointer uebergeben
68 if( !nPtr && ( pDbg != pThis || !pThis ) )
70 aCount[1] = 0;
71 pDbg = pThis;
74 ++nPtr;
75 if( DBG_MAX_STACK > nPtr )
77 // Wenn eine loop entdeckt wird, wird der counter wieder zurueckgesetzt.
78 ASSERT( DBG_MAX_LOOP > aCount[nPtr], "DbgLoopStack::Push: loop detected" );
79 if( DBG_MAX_LOOP > aCount[nPtr] )
80 ++(aCount[nPtr]);
81 else
82 aCount[nPtr] = 0;
86 /*************************************************************************
87 * DbgLoopStack::Pop()
88 *************************************************************************/
90 void DbgLoopStack::Pop()
92 if( DBG_MAX_STACK > nPtr )
94 ASSERT( nPtr, "DbgLoopStack::Pop: can't pop the stack" );
96 ASSERT( aCount[nPtr], "DbgLoopStack::Pop: can't dec the count" );
97 if( DBG_MAX_STACK > nPtr + 1 )
98 aCount[nPtr + 1] = 0;
100 --nPtr;
103 /*************************************************************************
104 * DbgLoopStack::Print()
105 *************************************************************************/
107 void DbgLoopStack::Print( SvStream &rOS ) const
109 rOS << "POS: " << nPtr << '\n';
110 USHORT i;
111 for( i = 0; i < DBG_MAX_STACK; ++i )
112 rOS << i << " ";
113 rOS << '\n';
114 for( i = 0; i < DBG_MAX_STACK; ++i )
115 rOS << aCount[i] << " ";
116 rOS << '\n';
119 #ifdef STAND_ALONE
120 // compile with: cl /AL /DSTAND_ALONE dbgloop.cxx
122 /*************************************************************************
123 * main()
124 *************************************************************************/
126 #include <stdlib.h>
128 void AssertFail( const char *pErr, const char *pFile, USHORT nLine )
130 cout << pErr << '\n';
131 PrintLoopStack( cout );
132 exit(0);
135 class Test
137 public:
138 void Run() const;
141 void Test::Run() const
143 cout << "---" << '\n';
144 for( USHORT i = 0; i < 10; ++i )
146 cout << "i" << i;
147 DBG_LOOP;
148 PrintLoopStack( cout );
149 for( USHORT j = 0; j < 10; ++j )
151 cout << " j" << j;
152 DBG_LOOP;
153 PrintLoopStack( cout );
155 cout << '\n';
157 PrintLoopStack( cout );
160 int main()
162 // unterschiedliche Instanzen waehlen wg. pDbg != pThis
163 Test aTest1;
164 aTest1.Run();
165 Test aTest2;
166 aTest2.Run();
167 return 0;
169 #endif