3675: Add a routine to generate formatted debug filenames.

* mln/debug/filename.hh: new routine. --- milena/ChangeLog | 6 ++ milena/mln/debug/filename.hh | 107 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 0 deletions(-) create mode 100644 milena/mln/debug/filename.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index ef8857b..06dba5b 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,11 @@ 2009-04-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add a routine to generate formatted debug filenames. + + * mln/debug/filename.hh: new routine. + +2009-04-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add graph::compute and few related functors. * mln/canvas/browsing/depth_first_search.hh: update and add more doc. diff --git a/milena/mln/debug/filename.hh b/milena/mln/debug/filename.hh new file mode 100644 index 0000000..fe64adb --- /dev/null +++ b/milena/mln/debug/filename.hh @@ -0,0 +1,107 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_DEBUG_FILENAME_HH +# define MLN_DEBUG_FILENAME_HH + +/// \file mln/debug/filename.hh +/// +/// Constructs and returns a formatted output file name. + + +# include <string> +# include <sstream> + + +namespace mln +{ + + namespace debug + { + + /// Constructs and returns a formatted output file name. + /*! + ** The file name is formatted as follow: + ** + ** `filename_prefix`_`id`_`filename`_`postfix_id` + ** + ** Where: + ** - `filename_prefix` can be set through the global variable + ** debug::internal::filename_prefix. + ** - `id` is auto-incremented and cannot be controlled. + ** - `filename` is the given filename + ** - `postfix_id` is an optional counter which can be controlled contrary + ** to `id`. + */ + std::string + filename(const std::string& filename, int postfix_id); + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + std::string filename_prefix = ""; + + } // end of namespace scribo::make::internal + + + std::string + filename(const std::string& filename, int postfix_id = -1) + { + static int file_id = 1; + + std::ostringstream os; + + if (! internal::filename_prefix.empty()) + os << internal::filename_prefix << "_"; + + if (file_id < 10) + os << "0"; + if (file_id < 100) + os << "0"; + + os << file_id++ + << "_" + << filename; + + if (postfix_id >= 0) + os << "_" << postfix_id; + + return os.str(); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::debug + +} // end of namespace mln + +#endif // ! MLN_DEBUG_FILENAME_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara