~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/safetycounter.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/***************************************************************************
3
 
   copyright            : (C) 2006 by David Nolden
4
 
   email                : david.nolden.kdevelop@art-master.de
5
 
***************************************************************************/
6
 
 
7
 
/***************************************************************************
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
15
 
 
16
 
#ifndef __SAFETYCOUNTER_H__
17
 
#define __SAFETYCOUNTER_H__
18
 
 
19
 
#include <kdebug.h>
20
 
 
21
 
struct SafetyCounter {
22
 
  int safetyCounter;
23
 
  const int maxSafetyCounter;
24
 
  
25
 
  SafetyCounter( int max = 40000 ) : safetyCounter(0), maxSafetyCounter(max) {
26
 
  }
27
 
  
28
 
  void init() {
29
 
    safetyCounter = 0;
30
 
  }
31
 
  
32
 
  SafetyCounter& operator ++() {
33
 
    safetyCounter++;
34
 
    return *this;
35
 
  }
36
 
 
37
 
  ///Returns whether the counter is ok, but without increasing it
38
 
  bool ok() const {
39
 
    return safetyCounter < maxSafetyCounter;
40
 
  }
41
 
  
42
 
  operator bool() {
43
 
    safetyCounter++;
44
 
    bool ret = safetyCounter < maxSafetyCounter;
45
 
          if( !ret ) {
46
 
                        if( safetyCounter == maxSafetyCounter ) {
47
 
#ifdef DEPTHBACKTRACE
48
 
        kdDebug( 9007) << "WARNING: Safety-counter reached count > " << maxSafetyCounter << ", operation stopped" << endl;
49
 
#endif
50
 
                        kdDebug( 9007 ) << endl << kdBacktrace() << endl;
51
 
                        }
52
 
          }
53
 
    
54
 
    return ret;
55
 
  }
56
 
  
57
 
};
58
 
 
59
 
#endif