switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Format.hh
index 180c39e..aebcf23 100644 (file)
@@ -1,24 +1,29 @@
 // $Id$
 //
-// Copyright (C) 2009 
+// Copyright (C) 2009
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Stefan Bund <g0dil@berlios.de>
 //
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// This program 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Stefan Bund <g0dil@berlios.de>
 
 /** \file
     \brief Format public header */
@@ -34,7 +39,7 @@
 #include <boost/type_traits/is_unsigned.hpp>
 
 //#include "Format.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace senf {
 namespace format {
@@ -80,7 +85,7 @@ namespace format {
         \par \c std::\c showpoint, \c std::\c noshowpoint
             If the \c showpoint flag is set, the exponent will be output even if it is 0. Otherwise,
             if \c width is set, the exponent will be replaced with 4 blanks.
-        
+
         \par \c std::\c uppercase, \c std::\c nouppercase
             If the \c uppercase flag is set, the exponent letter will be an uppercase 'E' instead of
             'e'. SI prefixes are \e not uppercased, since some SI prefixes differ only in case.
@@ -104,7 +109,7 @@ namespace format {
         os << std::setw(1) << senf::format::eng(1.23);
           -> "   1.230    "
 
-        os << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase 
+        os << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase
            << std::internal << senf::format::eng(12345,67);
           -> "+       12.35+-000.07E+03"
 
@@ -114,7 +119,7 @@ namespace format {
         senf::str(senf::format::eng(12.345,67).setw().setprecision(5).showpoint().uppercase())
           -> "  12.35+-67.00E+00"
         \endcode
-        
+
         \param[in] v value
         \param[in] d optional delta
 
@@ -148,7 +153,7 @@ namespace format {
     private:
         float v_;
         float d_;
-        
+
         mutable bool haveWidth_;
         mutable unsigned width_;
         mutable bool havePrecision_;
@@ -184,43 +189,80 @@ namespace format {
     template <class T>
     streamable_type dumpint(T const & v);
 
-#else 
+#else
 
-    template <class T> 
-    std::string dumpint(T const & v, 
+    template <class T>
+    std::string dumpint(T const & v,
                         typename boost::enable_if<boost::is_signed<T> >::type * = 0);
 
-    template <class T> 
-    std::string dumpint(T const & v, 
+    template <class T>
+    std::string dumpint(T const & v,
                         typename boost::enable_if<boost::is_unsigned<T> >::type * = 0);
-    
-    template <class T> 
-    std::string dumpint(T const & v, 
+
+    template <class T>
+    std::string dumpint(T const & v,
                         typename boost::enable_if<boost::is_signed<typename T::value_type> >::type * = 0);
 
-    template <class T> 
-    std::string dumpint(T const & v, 
+    template <class T>
+    std::string dumpint(T const & v,
                         typename boost::enable_if<boost::is_unsigned<typename T::value_type> >::type * = 0);
 
 #endif
-    
+
+    /** \brief Helper class to easily achieve indent levels
+
+        This class helps to achieve indent levels across function calls. Every instance
+        increases the static indent level. On destruction the level is decreased to the level
+        before the instance.
+        The following example illustrates the use of this class:
+        \code
+            void f1() {
+                senf::format::IndentHelper indent;
+                std::cout << indent << "f1\n";
+            }
+            void f2() {
+                senf::format::IndentHelper indent;
+                std::cout << indent << "f2 begin\n";
+                f1();
+                std::cout << indent << "f2 end\n";
+            }
+            f2()
+        \endcode
+        Output:
+        <pre>
+            f2 begin
+              f1
+            f2 end
+        </pre>
+        Here <tt>f1()</tt> and <tt>f2()</tt> don't need to know to current indent level,
+        they just increase the level by instantiating IndentHelper.
+
+        \ingroup senf_utils_format
+     */
     class IndentHelper
     {
         static unsigned int static_level;
-
         unsigned int instance_level;
     public:
-        IndentHelper () : instance_level(1) { ++static_level; }
-        ~IndentHelper () { static_level -= instance_level; }
-        void increase() { ++static_level; ++instance_level; }
 
-        friend std::ostream & operator<<(std::ostream & os, IndentHelper const & indent);
+        IndentHelper();                 ///< Construct new IndentHelper instance
+                                        /**< The static indent level is increased by one. */
+        ~IndentHelper();                ///< Destruct IndentHelper instance
+                                        /**< The static indent level will be decreased to the
+                                             level before the instance. */
+        void increase();                ///< Increase the indent level
+                                        /**< The indent level of the instance is increases by one. */
+        unsigned int level() const;     ///< return the current indent level
     };
+
+    /** \brief Output indent to given ostream
+        \related IndentHelper
+     */
     std::ostream & operator<<(std::ostream & os, IndentHelper const & indent);
 
 }}
 
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #include "Format.cci"
 //#include "Format.ct"
 #include "Format.cti"