Remove unnecessary (and wrong) check for movement, as the parent does it (fixes ...
[ardour2.git] / libs / pbd / debug.cc
blobe7ec767f873c2b41c3b9c3f5ab815fa1f6f72ddd
1 /*
2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <cstring>
21 #include <cstdlib>
22 #include <iostream>
23 #include <map>
25 #include "pbd/debug.h"
27 #include "i18n.h"
29 using namespace std;
30 static uint64_t _debug_bit = 1;
31 static std::map<const char*,uint64_t> _debug_bit_map;
33 uint64_t PBD::DEBUG::Stateful = PBD::new_debug_bit ("stateful");
34 uint64_t PBD::DEBUG::Properties = PBD::new_debug_bit ("properties");
35 uint64_t PBD::DEBUG::FileManager = PBD::new_debug_bit ("filemanager");
36 uint64_t PBD::DEBUG::Pool = PBD::new_debug_bit ("pool");
38 uint64_t PBD::debug_bits = 0x0;
40 uint64_t
41 PBD::new_debug_bit (const char* name)
43 uint64_t ret;
44 _debug_bit_map.insert (make_pair (name, _debug_bit));
45 ret = _debug_bit;
46 _debug_bit <<= 1;
47 return ret;
50 void
51 PBD::debug_print (const char* prefix, string str)
53 cerr << prefix << ": " << str;
56 void
57 PBD::set_debug_bits (uint64_t bits)
59 debug_bits = bits;
62 int
63 PBD::parse_debug_options (const char* str)
65 char* p;
66 char* sp;
67 uint64_t bits = 0;
68 char* copy = strdup (str);
70 p = strtok_r (copy, ",", &sp);
72 while (p) {
73 if (strcasecmp (p, "list") == 0) {
74 list_debug_options ();
75 free (copy);
76 return 1;
79 if (strcasecmp (p, "all") == 0) {
80 PBD::set_debug_bits (~0ULL);
81 free (copy);
82 return 0;
85 for (map<const char*,uint64_t>::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) {
86 if (strncasecmp (p, i->first, strlen (p)) == 0) {
87 bits |= i->second;
91 p = strtok_r (0, ",", &sp);
94 free (copy);
95 PBD::set_debug_bits (bits);
96 return 0;
99 void
100 PBD::list_debug_options ()
102 cout << _("The following debug options are available. Separate multipe options with commas.\nNames are case-insensitive and can be abbreviated.") << endl << endl;
103 cout << "\tAll" << endl;
105 for (map<const char*,uint64_t>::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) {
106 cout << "\t" << i->first << endl;