+2004-03-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * filename.[Ch] (mangledFilename): make sure that mangled names are
+ unique
+
2004-02-21 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir,
#include <boost/assert.hpp>
+#include <map>
+#include <sstream>
+
+using std::map;
using std::string;
string const FileName::mangledFilename() const
{
+ // We need to make sure that every FileName instance for a given
+ // filename returns the same mangled name.
+ typedef map<string, string> MangledMap;
+ static MangledMap mangledNames;
+ MangledMap::const_iterator const it = mangledNames.find(name_);
+ if (it != mangledNames.end())
+ return (*it).second;
+
+ // Now the real work
string mname = os::slashify_path(name_);
// Remove the extension.
mname = ChangeExtension(name_, string());
// Replace '.' in the file name with '_'
mname = subst(mname, ".", "_");
// Add the extension back on
- return ChangeExtension(mname, GetExtension(name_));
+ mname = ChangeExtension(mname, GetExtension(name_));
+ // Prepend a counter to the filename. This is necessary to make
+ // the mangled name unique.
+ static int counter = 0;
+ std::ostringstream s;
+ s << counter++;
+ mname = s.str() + mname;
+ mangledNames[name_] = mname;
+ return mname;
}
/** \return a mangled version of the absolute file name,
* suitable for use in the temp dir when, for example, converting
* an image file to another format.
+ * It is guaranteed that
+ * - two different filenames have different mangled names
+ * - two FileName instances with the same filename have identical
+ * mangled names
*/
std::string const mangledFilename() const;