diff --git a/common/misc.hh b/common/misc.hh index d6126c6a1acf33b09224d66db1448c051cd9ca33..7aa18ed693807fd0e9bc8a2a5a2691185fe385df 100644 --- a/common/misc.hh +++ b/common/misc.hh @@ -4,6 +4,7 @@ #define __MISC_HH__ #include <iostream> +#include <sstream> //! Check condition at compilation time template <bool flag> class CompileTimeChecker; @@ -39,31 +40,15 @@ namespace Dune { // //******************************************************************** - template <typename T> - inline const char *genFilename(T *path, T *fn, int ntime, int precision = 6) + inline std::basic_string<char> genFilename(std::basic_string <char> path, std::basic_string <char> fn, int ntime, int precision = 6) { - static char name[256]; - char *cp; + std::ostringstream name; - if (path == 0 || path[0] == '\0') - { - sprintf(name, "%s", fn); - } - else - { - const char *cp = path; - while (*cp) - cp++; - cp--; - if (*cp == '/') - sprintf(name, "%s%s", path, fn); - else - sprintf(name, "%s/%s", path, fn); - } - cp = name; - while (*cp) - cp++; + name << path; + name << "/"; + name << fn; + char cp[256]; switch(precision) { case 2 : { sprintf(cp, "%02d", ntime); break; } @@ -81,8 +66,10 @@ namespace Dune { abort(); } } + name << cp; - return( (T *) name); + // here implicitly a string is generated + return name.str().c_str(); } /** @} */