rework MIDI [processor|plugin] chain
[ardour.git] / libs / pbd / debug.cc
index e7ec767f873c2b41c3b9c3f5ab815fa1f6f72ddd..c86afbe87e723b74205f1cef1483d3c060b9b7b7 100644 (file)
@@ -21,6 +21,8 @@
 #include <cstdlib>
 #include <iostream>
 #include <map>
+#include <vector>
+#include <algorithm>
 
 #include "pbd/debug.h"
 
 
 using namespace std;
 static uint64_t _debug_bit = 1;
-static std::map<const char*,uint64_t> _debug_bit_map;
+
+typedef std::map<const char*,uint64_t> DebugMap;
+
+namespace PBD {
+       DebugMap & _debug_bit_map()
+       {
+               static DebugMap map;
+               return map;
+       }
+}
 
 uint64_t PBD::DEBUG::Stateful = PBD::new_debug_bit ("stateful");
 uint64_t PBD::DEBUG::Properties = PBD::new_debug_bit ("properties");
 uint64_t PBD::DEBUG::FileManager = PBD::new_debug_bit ("filemanager");
 uint64_t PBD::DEBUG::Pool = PBD::new_debug_bit ("pool");
+uint64_t PBD::DEBUG::EventLoop = PBD::new_debug_bit ("eventloop");
+uint64_t PBD::DEBUG::AbstractUI = PBD::new_debug_bit ("abstractui");
 
 uint64_t PBD::debug_bits = 0x0;
 
@@ -41,7 +54,7 @@ uint64_t
 PBD::new_debug_bit (const char* name)
 {
         uint64_t ret;
-        _debug_bit_map.insert (make_pair (name, _debug_bit));
+        _debug_bit_map().insert (make_pair (name, _debug_bit));
         ret = _debug_bit;
         _debug_bit <<= 1;
         return ret;
@@ -82,7 +95,7 @@ PBD::parse_debug_options (const char* str)
                        return 0;
                }
 
-                for (map<const char*,uint64_t>::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) {
+               for (map<const char*,uint64_t>::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) {
                         if (strncasecmp (p, i->first, strlen (p)) == 0) {
                                 bits |= i->second;
                         }
@@ -99,10 +112,18 @@ PBD::parse_debug_options (const char* str)
 void
 PBD::list_debug_options ()
 {
-       cout << _("The following debug options are available. Separate multipe options with commas.\nNames are case-insensitive and can be abbreviated.") << endl << endl;
-       cout << "\tAll" << endl;
+       cout << _("The following debug options are available. Separate multiple options with commas.\nNames are case-insensitive and can be abbreviated.") << endl << endl;
+       cout << '\t' << X_("all") << endl; 
 
-        for (map<const char*,uint64_t>::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) {
-                cout << "\t" << i->first << endl;
+       vector<string> options;
+
+       for (map<const char*,uint64_t>::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) {
+               options.push_back (i->first);
         }
+
+       sort (options.begin(), options.end());
+
+       for (vector<string>::iterator i = options.begin(); i != options.end(); ++i) {
+                cout << "\t" << (*i) << endl;
+       }
 }