debug.hh (10685:a24286e33318) | debug.hh (11153:20bbfe5b2b86) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * Copyright (c) 2010 The Hewlett-Packard Development Company 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright --- 31 unchanged lines hidden (view full) --- 40 41void breakpoint(); 42 43class Flag 44{ 45 protected: 46 const char *_name; 47 const char *_desc; | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * Copyright (c) 2010 The Hewlett-Packard Development Company 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright --- 31 unchanged lines hidden (view full) --- 40 41void breakpoint(); 42 43class Flag 44{ 45 protected: 46 const char *_name; 47 const char *_desc; |
48 std::vector<Flag *> _kids; | |
49 50 public: 51 Flag(const char *name, const char *desc); 52 virtual ~Flag(); 53 54 std::string name() const { return _name; } 55 std::string desc() const { return _desc; } | 48 49 public: 50 Flag(const char *name, const char *desc); 51 virtual ~Flag(); 52 53 std::string name() const { return _name; } 54 std::string desc() const { return _desc; } |
56 std::vector<Flag *> kids() { return _kids; } | 55 virtual std::vector<Flag *> kids() { return std::vector<Flag*>(); } |
57 58 virtual void enable() = 0; 59 virtual void disable() = 0; | 56 57 virtual void enable() = 0; 58 virtual void disable() = 0; |
59 virtual void sync() {} |
|
60}; 61 62class SimpleFlag : public Flag 63{ | 60}; 61 62class SimpleFlag : public Flag 63{ |
64 static bool _active; // whether debug tracings are enabled |
|
64 protected: | 65 protected: |
65 bool _status; | 66 bool _tracing; // tracing is enabled and flag is on 67 bool _status; // flag status |
66 67 public: 68 SimpleFlag(const char *name, const char *desc) 69 : Flag(name, desc), _status(false) 70 { } 71 | 68 69 public: 70 SimpleFlag(const char *name, const char *desc) 71 : Flag(name, desc), _status(false) 72 { } 73 |
72 bool status() const { return _status; } 73 operator bool() const { return _status; } 74 bool operator!() const { return !_status; } | 74 bool status() const { return _tracing; } 75 operator bool() const { return _tracing; } 76 bool operator!() const { return !_tracing; } |
75 | 77 |
76 void enable() { _status = true; } 77 void disable() { _status = false; } | 78 void enable() { _status = true; sync(); } 79 void disable() { _status = false; sync(); } 80 81 void sync() { _tracing = _active && _status; } 82 83 static void enableAll(); 84 static void disableAll(); |
78}; 79 | 85}; 86 |
80class CompoundFlag : public SimpleFlag | 87class CompoundFlag : public Flag |
81{ 82 protected: | 88{ 89 protected: |
90 std::vector<Flag *> _kids; 91 |
|
83 void 84 addFlag(Flag *f) 85 { 86 if (f != nullptr) 87 _kids.push_back(f); 88 } 89 90 public: 91 CompoundFlag(const char *name, const char *desc, 92 Flag *f00 = nullptr, Flag *f01 = nullptr, 93 Flag *f02 = nullptr, Flag *f03 = nullptr, 94 Flag *f04 = nullptr, Flag *f05 = nullptr, 95 Flag *f06 = nullptr, Flag *f07 = nullptr, 96 Flag *f08 = nullptr, Flag *f09 = nullptr, 97 Flag *f10 = nullptr, Flag *f11 = nullptr, 98 Flag *f12 = nullptr, Flag *f13 = nullptr, 99 Flag *f14 = nullptr, Flag *f15 = nullptr, 100 Flag *f16 = nullptr, Flag *f17 = nullptr, 101 Flag *f18 = nullptr, Flag *f19 = nullptr) | 92 void 93 addFlag(Flag *f) 94 { 95 if (f != nullptr) 96 _kids.push_back(f); 97 } 98 99 public: 100 CompoundFlag(const char *name, const char *desc, 101 Flag *f00 = nullptr, Flag *f01 = nullptr, 102 Flag *f02 = nullptr, Flag *f03 = nullptr, 103 Flag *f04 = nullptr, Flag *f05 = nullptr, 104 Flag *f06 = nullptr, Flag *f07 = nullptr, 105 Flag *f08 = nullptr, Flag *f09 = nullptr, 106 Flag *f10 = nullptr, Flag *f11 = nullptr, 107 Flag *f12 = nullptr, Flag *f13 = nullptr, 108 Flag *f14 = nullptr, Flag *f15 = nullptr, 109 Flag *f16 = nullptr, Flag *f17 = nullptr, 110 Flag *f18 = nullptr, Flag *f19 = nullptr) |
102 : SimpleFlag(name, desc) | 111 : Flag(name, desc) |
103 { 104 addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); 105 addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); 106 addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14); 107 addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19); 108 } 109 | 112 { 113 addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); 114 addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); 115 addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14); 116 addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19); 117 } 118 |
119 std::vector<Flag *> kids() { return _kids; } 120 |
|
110 void enable(); 111 void disable(); 112}; 113 114typedef std::map<std::string, Flag *> FlagsMap; 115FlagsMap &allFlags(); 116 117Flag *findFlag(const std::string &name); --- 14 unchanged lines hidden --- | 121 void enable(); 122 void disable(); 123}; 124 125typedef std::map<std::string, Flag *> FlagsMap; 126FlagsMap &allFlags(); 127 128Flag *findFlag(const std::string &name); --- 14 unchanged lines hidden --- |