X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fport_set.cc;h=44a5f436a98742e0ea92bff03f096173a3486f3b;hb=00ddd099ed5cd6e0d77448670381d13d88b96218;hp=7648db00cb413dff0d94f5f26695cf65b58480fd;hpb=6ef5d85ae1f2c500c4163cd1df580b3f26991c1e;p=ardour.git diff --git a/libs/ardour/port_set.cc b/libs/ardour/port_set.cc index 7648db00cb..44a5f436a9 100644 --- a/libs/ardour/port_set.cc +++ b/libs/ardour/port_set.cc @@ -16,12 +16,14 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include +#include #include "ardour/port_set.h" #include "ardour/midi_port.h" #include "ardour/audio_port.h" +using std::string; + namespace ARDOUR { PortSet::PortSet() @@ -32,41 +34,41 @@ PortSet::PortSet() static bool sort_ports_by_name (Port* a, Port* b) { - Glib::ustring aname (a->name()); - Glib::ustring bname (b->name()); - - Glib::ustring::size_type last_digit_position_a = aname.size(); - Glib::ustring::const_reverse_iterator r_iterator = aname.rbegin(); - - while (r_iterator!= aname.rend() && Glib::Unicode::isdigit(*r_iterator)) { - r_iterator++; - last_digit_position_a--; - } - - Glib::ustring::size_type last_digit_position_b = bname.size(); - r_iterator = bname.rbegin(); - - while (r_iterator != bname.rend() && Glib::Unicode::isdigit(*r_iterator)) { - r_iterator++; - last_digit_position_b--; - } - - // if some of the names don't have a number as posfix, compare as strings - - if (last_digit_position_a == aname.size() or last_digit_position_b == bname.size()) { - return aname < bname; - } - - const std::string prefix_a = aname.substr(0, last_digit_position_a - 1); - const unsigned int posfix_a = std::atoi(aname.substr(last_digit_position_a, aname.size() - last_digit_position_a).c_str()); - const std::string prefix_b = bname.substr(0, last_digit_position_b - 1); - const unsigned int posfix_b = std::atoi(bname.substr(last_digit_position_b, bname.size() - last_digit_position_b).c_str()); - - if (prefix_a != prefix_b) { - return aname < bname; - } else { - return posfix_a < posfix_b; - } + string aname (a->name()); + string bname (b->name()); + + string::size_type last_digit_position_a = aname.size(); + string::reverse_iterator r_iterator = aname.rbegin(); + + while (r_iterator!= aname.rend() && Glib::Unicode::isdigit(*r_iterator)) { + r_iterator++; + last_digit_position_a--; + } + + string::size_type last_digit_position_b = bname.size(); + r_iterator = bname.rbegin(); + + while (r_iterator != bname.rend() && Glib::Unicode::isdigit(*r_iterator)) { + r_iterator++; + last_digit_position_b--; + } + + // if some of the names don't have a number as posfix, compare as strings + + if (last_digit_position_a == aname.size() or last_digit_position_b == bname.size()) { + return aname < bname; + } + + const std::string prefix_a = aname.substr(0, last_digit_position_a - 1); + const unsigned int posfix_a = std::atoi(aname.substr(last_digit_position_a, aname.size() - last_digit_position_a).c_str()); + const std::string prefix_b = bname.substr(0, last_digit_position_b - 1); + const unsigned int posfix_b = std::atoi(bname.substr(last_digit_position_b, bname.size() - last_digit_position_b).c_str()); + + if (prefix_a != prefix_b) { + return aname < bname; + } else { + return posfix_a < posfix_b; + } } void @@ -75,10 +77,9 @@ PortSet::add(Port* port) PortVec& v = _ports[port->type()]; v.push_back(port); - sort(v.begin(), v.end(), sort_ports_by_name); + sort(v.begin(), v.end(), sort_ports_by_name); _count.set(port->type(), _count.get(port->type()) + 1); - assert(_count.get(port->type()) == _ports[port->type()].size()); }