Tempo ramps - audio-locked meters have a bbt of 1|1|0
[ardour.git] / libs / pbd / pbd / compose.h
index 0df9519aaf571638dd670760d92d216663cadb55..231afa583e4ba0a53703ff99b2446f9ab75e97c1 100644 (file)
 #include <list>
 #include <map>                 // for multimap
 
+#include "pbd/libpbd_visibility.h"
+
 namespace StringPrivate
 {
   // the actual composition class - using string::compose is cleaner, so we
   // hide it here
-  class Composition
+  class LIBPBD_API Composition
   {
   public:
     // initialize and prepare format string on the form "text %1 text %2 etc."
@@ -52,6 +54,10 @@ namespace StringPrivate
     template <typename T>
     Composition &arg(const T &obj);
 
+    // specialization to catch strings (C++ and C)
+    Composition &arg(const std::string &str);
+    Composition &arg(char const * const cstr);
+
     // compose and return string
     std::string str() const;
 
@@ -104,7 +110,7 @@ namespace StringPrivate
     case '8':
     case '9':
       return true;
-    
+
     default:
       return false;
     }
@@ -118,29 +124,65 @@ namespace StringPrivate
     os << obj;
 
     std::string rep = os.str();
-  
+
     if (!rep.empty()) {                // manipulators don't produce output
       for (specification_map::const_iterator i = specs.lower_bound(arg_no),
             end = specs.upper_bound(arg_no); i != end; ++i) {
        output_list::iterator pos = i->second;
        ++pos;
-      
+
        output.insert(pos, rep);
       }
-    
+
       os.str(std::string());
       //os.clear();
       ++arg_no;
     }
-  
+
     return *this;
   }
 
+  inline Composition &Composition::arg(const std::string &str)
+  {
+         /* specialization to ensure that empty strings show up
+          * in the output
+          */
+         for (specification_map::const_iterator i = specs.lower_bound(arg_no),
+                      end = specs.upper_bound(arg_no); i != end; ++i) {
+                 output_list::iterator pos = i->second;
+                 ++pos;
+
+                 output.insert(pos, str);
+         }
+
+         ++arg_no;
+
+         return *this;
+  }
+
+  inline Composition &Composition::arg(char const * const cstr)
+  {
+         /* specialization to ensure that empty C strings show up
+          * in the output
+          */
+         for (specification_map::const_iterator i = specs.lower_bound(arg_no),
+                      end = specs.upper_bound(arg_no); i != end; ++i) {
+                 output_list::iterator pos = i->second;
+                 ++pos;
+
+                 output.insert(pos, std::string (cstr));
+         }
+
+         ++arg_no;
+
+         return *this;
+  }
+
   inline Composition::Composition(std::string fmt)
     : arg_no(1)
   {
     std::string::size_type b = 0, i = 0;
-  
+
     // fill in output with the strings between the %1 %2 %3 etc. and
     // fill in specs with the positions
     while (i < fmt.length()) {
@@ -152,7 +194,7 @@ namespace StringPrivate
        else if (is_number(fmt[i + 1])) { // aha! a spec!
          // save string
          output.push_back(fmt.substr(b, i - b));
-       
+
          int n = 1;            // number of digits
          int spec_no = 0;
 
@@ -165,9 +207,9 @@ namespace StringPrivate
          spec_no /= 10;
          output_list::iterator pos = output.end();
          --pos;                // safe since we have just inserted a string>
-       
+
          specs.insert(specification_map::value_type(spec_no, pos));
-       
+
          // jump over spec string
          i += n;
          b = i;
@@ -178,7 +220,7 @@ namespace StringPrivate
       else
        ++i;
     }
-  
+
     if (i - b > 0)             // add the rest of the string
       output.push_back(fmt.substr(b, i - b));
   }
@@ -187,11 +229,11 @@ namespace StringPrivate
   {
     // assemble string
     std::string str;
-  
+
     for (output_list::const_iterator i = output.begin(), end = output.end();
         i != end; ++i)
       str += *i;
-  
+
     return str;
   }
 }
@@ -308,7 +350,7 @@ namespace StringPrivate
       .arg(o10);
     return c.str();
   }
-  
+
   template <typename T1, typename T2, typename T3, typename T4, typename T5,
            typename T6, typename T7, typename T8, typename T9, typename T10,
            typename T11>