Changeset 93abe8


Ignore:
Timestamp:
Apr 2, 2011, 12:11:44 AM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
8e24ef
Parents:
6b898c
git-author:
Frederik Heber <heber@…> (03/14/11 17:54:03)
git-committer:
Frederik Heber <heber@…> (04/02/11 00:11:44)
Message:

Added static and private object counter Info::NumberInfos.

Location:
src
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/Info.cpp

    r6b898c r93abe8  
    2020#include "MemDebug.hpp"
    2121
     22#include "Chronos.hpp"
    2223#include "Info.hpp"
    2324#include "Log.hpp"
     
    2526
    2627int Info::verbosity = 0;
     28Chronos * Info::timekeeper = NULL;
     29bool Info::ChronosBlocker = false;
     30size_t Info::NumberInfos = 0;
    2731
    2832/**
     
    3640  verbosity++;
    3741  DoLog(0) && (Log() << Verbose(0) << "Begin of " << FunctionName << endl);
    38 };
     42
     43  // one more info object
     44  ++NumberInfos;
     45
     46  // have pointer ready
     47  if (timekeeper == NULL) {
     48    timekeeper = Chronos::getPointer();
     49  }
     50
     51  // start time keeping
     52  timekeeper->startTiming(FunctionName);
     53}
    3954
    4055/**
    4156 * Destructor. Better use purgeInstance().
    4257 */
    43 Info::~Info() {
     58Info::~Info()
     59{
     60  // end time keeping
     61  timekeeper->endTiming(FunctionName);
     62
     63  // verbosity stuff
    4464  DoLog(0) && (Log() << Verbose(0) << "End of " << FunctionName << endl);
    4565  verbosity--;
     66
     67  // one info object less
     68  --NumberInfos;
     69
     70  // we are last one?
     71  if (!NumberInfos) {
     72    timekeeper = NULL;
     73  }
    4674}
    4775
     
    5179 * \param verbosityLevel verbosity
    5280 */
    53 void Info::setVerbosity(int verbosityLevel) {
     81void Info::setVerbosity(int verbosityLevel)
     82{
    5483  verbosity = verbosityLevel;
    5584}
  • src/Helpers/Info.hpp

    r6b898c r93abe8  
    1414#endif
    1515
     16#include <string>
     17
     18class ChronosTest;
     19
    1620/*********************************************** includes ***********************************/
    1721
     
    2125
    2226class Info {
     27  //!> unit tests needs access to some internals
     28  friend class ChronosTest;
    2329public :
    2430  static int verbosity;
    25   const char *FunctionName;
     31  const std::string FunctionName;
    2632
    2733  Info(const char *msg);
     
    2935  static void setVerbosity(int verbosityLevel);
    3036
     37private:
     38  static class Chronos * timekeeper;
     39  static bool ChronosBlocker;
     40  static size_t NumberInfos;
    3141};
    3242
  • src/Makefile.am

    r6b898c r93abe8  
    6161        Patterns/Observer.cpp \
    6262        Helpers/Assert.cpp \
     63        Helpers/Chronos.cpp \
    6364        Helpers/errorlogger.cpp \
    6465        Helpers/Info.cpp \
     
    7172HELPERSHEADER =  \
    7273        Helpers/Assert.hpp \
     74        Helpers/Chronos.hpp \
    7375        Helpers/enumeration.hpp \
    7476        Helpers/errorlogger.hpp \
  • src/unittests/InfoUnitTest.cpp

    r6b898c r93abe8  
    5959  class Info test(msg);
    6060
    61   CPPUNIT_ASSERT_EQUAL( msg , test.FunctionName );
     61  CPPUNIT_ASSERT_EQUAL( std::string(msg) , test.FunctionName );
    6262  CPPUNIT_ASSERT_EQUAL( 1, test.verbosity );
    6363};
  • src/unittests/Makefile.am

    r6b898c r93abe8  
    1313TESTS = \
    1414        AssertUnitTest \
     15        ChronosUnitTest \
    1516  InfoUnitTest \
    1617  IteratorAdaptorsUnitTest \
     
    4748  $(top_srcdir)/src/Patterns/unittests/stubs/RegistryStub.cpp \
    4849  AssertUnitTest.cpp \
     50        ChronosUnitTest.cpp \
    4951  InfoUnitTest.cpp \
    5052  LogUnitTest.cpp \
     
    8082  $(top_srcdir)/src/Patterns/unittests/stubs/RegistryStub.hpp \
    8183  AssertUnitTest.hpp \
     84        ChronosUnitTest.hpp \
    8285  InfoUnitTest.hpp \
    8386  LogUnitTest.hpp \
     
    8992        AssertUnitTest.hpp
    9093AssertUnitTest_LDADD = ${TESTLIBS}
     94
     95ChronosUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
     96        ChronosUnitTest.cpp \
     97        ChronosUnitTest.hpp
     98ChronosUnitTest_LDADD = ${TESTLIBS}
    9199
    92100InfoUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
Note: See TracChangeset for help on using the changeset viewer.