From: tho Date: Thu, 1 Apr 2010 15:10:36 +0000 (+0000) Subject: Utils: added documentation for format::IndentHelper X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=3ccce76c61833d1cac9e1a2e34dcc670b93c6b3f;p=senf.git Utils: added documentation for format::IndentHelper git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1590 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/ActiveFeeder.test.cc b/senf/PPI/ActiveFeeder.test.cc index 4418d55..54d0472 100644 --- a/senf/PPI/ActiveFeeder.test.cc +++ b/senf/PPI/ActiveFeeder.test.cc @@ -32,7 +32,6 @@ #include "Setup.hh" #include "CloneSource.hh" #include -#include #include #include @@ -44,14 +43,10 @@ namespace ppi = senf::ppi; namespace module = senf::ppi::module; namespace scheduler = senf::scheduler; -namespace { - void timeout() { - scheduler::terminate(); - } - +namespace { void run(senf::ClockService::clock_type t) { - scheduler::TimerEvent timeoutTimer ("timeoutTimer", &timeout, - senf::ClockService::now() + t); + scheduler::TimerEvent timeout( + "test-timeout", &scheduler::terminate, scheduler::now() + t); ppi::run(); } } diff --git a/senf/Utils/Format.cci b/senf/Utils/Format.cci index ff8f87b..c74c184 100644 --- a/senf/Utils/Format.cci +++ b/senf/Utils/Format.cci @@ -30,6 +30,9 @@ #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// senf::format::eng + prefix_ senf::format::eng::eng(float v, float d) : v_ (v), d_ (d), haveWidth_ (false), width_ (0), havePrecision_ (false), precision_ (0), haveFill_ (false), fill_ (' '), mask_ (), flags_ () @@ -150,13 +153,44 @@ prefix_ senf::format::eng const & senf::format::eng::right() return *this; } +/////////////////////////////////////////////////////////////////////////// +// senf::format::IndentHelper + +prefix_ senf::format::IndentHelper::IndentHelper() + : instance_level(1) +{ + ++static_level; +} + +prefix_ senf::format::IndentHelper::~IndentHelper() +{ + static_level -= instance_level; +} + +prefix_ void senf::format::IndentHelper::increase() +{ + ++static_level; + ++instance_level; +} + +prefix_ unsigned int senf::format::IndentHelper::level() + const +{ + return static_level; +} + prefix_ std::ostream & senf::format::operator<<(std::ostream & os, senf::format::IndentHelper const & indent) { - for (unsigned int i = 0; i < indent.static_level; ++i) + for (unsigned int i=0, j=indent.level(); i + f2 begin + f1 + f2 end + + Here f1() and f2() 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); }} diff --git a/senf/Utils/Format.test.cc b/senf/Utils/Format.test.cc index ece8647..8dd4bae 100644 --- a/senf/Utils/Format.test.cc +++ b/senf/Utils/Format.test.cc @@ -149,6 +149,31 @@ SENF_AUTO_UNIT_TEST(dumpint) # undef CheckFormat } +namespace { + void f1(std::ostream & os) { + senf::format::IndentHelper indent; + os << indent << "f1\n"; + } + void f2(std::ostream & os) { + senf::format::IndentHelper indent; + os << indent << "f2_1\n"; + f1( os); + os << indent << "f2_2\n"; + indent.increase(); + os << indent << "f2_3\n"; + } +} +SENF_AUTO_UNIT_TEST(indent) +{ + std::stringstream ss; + f2(ss); + BOOST_CHECK_EQUAL( ss.str(), + " f2_1\n" + " f1\n" + " f2_2\n" + " f2_3\n"); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_