mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 16:46:35 +01:00
fix insane design for Location::next_available_name() so that it has no effective limit (other than UINT32_MAX)
This commit is contained in:
parent
8641dcdb0c
commit
4eac2a76da
1 changed files with 45 additions and 24 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
#include "pbd/convert.h"
|
||||||
#include "pbd/stl_delete.h"
|
#include "pbd/stl_delete.h"
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
#include "pbd/enumwriter.h"
|
#include "pbd/enumwriter.h"
|
||||||
|
|
@ -37,8 +38,6 @@
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
#define SUFFIX_MAX 32
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
using namespace PBD;
|
using namespace PBD;
|
||||||
|
|
@ -783,33 +782,55 @@ int
|
||||||
Locations::next_available_name(string& result,string base)
|
Locations::next_available_name(string& result,string base)
|
||||||
{
|
{
|
||||||
LocationList::iterator i;
|
LocationList::iterator i;
|
||||||
Location* location;
|
|
||||||
string temp;
|
|
||||||
string::size_type l;
|
string::size_type l;
|
||||||
int suffix;
|
int suffix;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
bool available[SUFFIX_MAX+1];
|
std::map<uint32_t,bool> taken;
|
||||||
|
uint32_t n;
|
||||||
|
|
||||||
result = base;
|
result = base;
|
||||||
for (int k=1; k<SUFFIX_MAX; k++) {
|
l = base.length();
|
||||||
available[k] = true;
|
|
||||||
}
|
if (!base.empty()) {
|
||||||
l = base.length();
|
|
||||||
for (i = locations.begin(); i != locations.end(); ++i) {
|
/* find all existing names that match "base", and store
|
||||||
location =* i;
|
the numeric part of them (if any) in the map "taken"
|
||||||
temp = location->name();
|
*/
|
||||||
if (l && !temp.find(base,0)) {
|
|
||||||
suffix = atoi(temp.substr(l,3).c_str());
|
for (i = locations.begin(); i != locations.end(); ++i) {
|
||||||
if (suffix) available[suffix] = false;
|
|
||||||
}
|
const string& temp ((*i)->name());
|
||||||
}
|
|
||||||
for (int k=1; k<=SUFFIX_MAX; k++) {
|
if (!temp.find (base,0)) {
|
||||||
if (available[k]) {
|
|
||||||
snprintf (buf, 31, "%d", k);
|
if ((suffix = atoi (temp.substr(l,3))) != 0) {
|
||||||
result += buf;
|
taken.insert (make_pair (suffix,true));
|
||||||
return 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now search for an un-used suffix to add to "base". This
|
||||||
|
will find "holes" in the numbering sequence when a location
|
||||||
|
was deleted.
|
||||||
|
|
||||||
|
This must start at 1, both for human-numbering reasons
|
||||||
|
and also because the call to atoi() above would return
|
||||||
|
zero if there is no recognizable numeric suffix, causing
|
||||||
|
"base 0" not to be inserted into the "taken" map.
|
||||||
|
*/
|
||||||
|
|
||||||
|
n = 1;
|
||||||
|
|
||||||
|
while (n < UINT32_MAX) {
|
||||||
|
if (taken.find (n) == taken.end()) {
|
||||||
|
snprintf (buf, sizeof(buf), "%d", n);
|
||||||
|
result += buf;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue