File: DebugItem.cc

package info (click to toggle)
thepeg 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 9,312 kB
  • ctags: 11,509
  • sloc: cpp: 57,129; sh: 11,315; java: 3,212; lisp: 1,402; makefile: 830; ansic: 58; perl: 3
file content (80 lines) | stat: -rw-r--r-- 2,545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// -*- C++ -*-
//
// This is the implementation of the non-inlined, non-templated member
// functions of the DebugItem class.
//

#include "DebugItem.h"
#include "ThePEG/Utilities/Debug.h"

using namespace ThePEG;

DebugItem::DebugItem(string itemname, int level): debug(false) {
  if ( level <= Debug::level ) debug = true;
  items().insert(make_pair(itemname, this));
  map<string,long>::iterator it = nametics().find(itemname);
  if ( it != nametics().end() ) {
    if ( ticker() >= it->second ) debug = true;
    else itemtics().insert(make_pair(it->second, this));
  } else {
    while ( itemname.rfind("::") != string::npos ) {
      itemname = itemname.substr(0, itemname.rfind("::")) + "::all";
      it = nametics().find(itemname);
      if ( it != nametics().end() ) {
	if ( ticker() >= it->second ) debug = true;
	else itemtics().insert(make_pair(it->second, this));
      }
      itemname = itemname.substr(0, itemname.rfind("::"));
    }
  }
}

void DebugItem::tic() {
  ticker()++;
  multimap<long,DebugItem*>::iterator it = itemtics().begin();
  while ( it != itemtics().end() &&
	  ticker() >= it->first ) (it++)->second->debug = true;
  itemtics().erase(itemtics().begin(), it);
}

void DebugItem::setDebugItem(string itemname, long after) {
  typedef multimap<string,DebugItem*>::iterator ItemIt;
  if ( itemname.rfind('=') != string::npos ) {
    after =  atoi(itemname.substr(itemname.rfind('=') + 1).c_str());
    itemname = itemname.substr(0, itemname.rfind('='));
  }
  nametics()[itemname] = after;
  pair<ItemIt,ItemIt> range = items().equal_range(itemname);
  while ( range.first != range.second ) {
    if ( ticker() >= after ) (range.first++)->second->debug = true;
    else itemtics().insert(make_pair(after, (range.first++)->second));
  }
  if ( itemname.substr(itemname.length() - 5) == "::all" ) {
    itemname = itemname.substr(itemname.length() - 3);
    for ( ItemIt it = items().begin(); it != items().end(); ++it )
      if ( it->first.substr(0, itemname.length()) == itemname ) {
	if ( ticker() >= after ) it->second->debug = true;
	else itemtics().insert(make_pair(after, it->second));
      }	
  }
}

long & DebugItem::ticker() {
  static long tics = 0;
  return tics;
}

multimap<string,DebugItem*> & DebugItem::items() {
  static multimap<string,DebugItem*> itemmap;
  return itemmap;
}

multimap<long,DebugItem*> & DebugItem::itemtics() {
  static multimap<long,DebugItem*> itemmap;
  return itemmap;
}

map<string,long> & DebugItem::nametics() {
  static map<string,long> namemap;
  return namemap;
}