/* $Id: progresslog.hpp,v 1.2 2005/06/28 13:55:21 chfreund Exp $ */ #ifndef _PROGRESSLOG_HPP_ #define _PROGRESSLOG_HPP_ /**********************************************************/ #include "string.hpp" #include "global.hpp" /**********************************************************/ //! class for reporting the progress of one action class Progress { public: Progress( const int TitleLockLength = -1 ); ~Progress(); //! \name access //@{ //! returns the title string (if you need a char*, simply cast it) const String& getTitle() const { return m_Title; } //! sets the title string void setTitle( const char* const title ); //! sets the title string void setTitle( const String& title ) { setTitle((char*)title); } //! returns the progress value double getProgress() const { return m_Progress; } //! sets the progress void setProgress( const double progress ) { m_Progress = progress; } //! adds the passed value to the progress void addToProgress( const double increment ) { m_Progress += increment; } //! true, if the title string is valid bool TitleIsValid() const { return m_TitleIsValid; } //! sets the title string to "non valid" void setTitleUnvalid() { m_TitleIsValid = false; } //@} //! \name operators //@{ double operator = ( const double p ) { return m_Progress = p; } double operator += ( const double p ) { return m_Progress += p; } //@} //! lock length of the title string (also see class String) bool lockTitleLength( const int length ) { return length == m_Title.lockLength( length ); } protected: String m_Title; //!< the title of the double m_Progress; //!< the progress [0,1] bool m_TitleIsValid; //!< true, if the title string is valid }; /**********************************************************/ #define LEVEL_CHECK(fn) \ DBG(2) {\ ASSERT( 0 <= level && level < m_nLevels, \ "%s: level %d out of range [0,%d]\n", \ fn, m_nLevels ); \ } /**********************************************************/ //! class for logging the whole progress of an algorithm class ProgressLog { public: ProgressLog(); ProgressLog( const int TitleLockLength, const int nLevels ); ~ProgressLog(); //! \name access //@{ //! returns number of levels int getNumLevels() const { return m_nLevels; } //! returns the title string of level "level" const String& getTitle( const int level = 0 ) const { LEVEL_CHECK( "ProgressLog::getTitle" ) return m_Progress[level].getTitle(); } //! returns the progress of level "level" double getProgress( const int level = 0 ) const { LEVEL_CHECK( "ProgessLog::getProgress" ) return m_Progress[level].getProgress(); } //! returns the progress object at level "level" const Progress& getProgressObject( const int level = 0 ) const { LEVEL_CHECK( "ProgessLog::getProgressObject" ) return m_Progress[level]; } //! returns the progress object at level "level" Progress& getProgressObject( const int level = 0 ) { LEVEL_CHECK( "ProgessLog::getProgressObject" ) return m_Progress[level]; } //@} //! create a new logging bool create( const int TitleLockLength = -1, const int nLevels = 1 ); //! reset the class to the state after creation with standard constructor void reset(); protected: Progress* m_Progress; //!< array with progress levels [m_nLevels] int m_nLevels; //!< number of progress levels }; /**********************************************************/ #undef LEVEL_CHECK /**********************************************************/ #endif // _PROGRESSLOG_HPP_