scope_timer.hpp

来自「Octane v1.01.20 The Open Compression To」· HPP 代码 · 共 55 行

HPP
55
字号
//
// Simple timer, measuring time from construction to destruction.
//
// Copyright (c) 2003 by Octane Project Group
// All Rights Reserved
//
// http://octane.sourceforge.net/
//

/// @file   scope_timer.hpp
/// @brief  Simple timer, measuring time from construction to destruction.
/// @author Jibz
/// @date   2003.07.30

#ifndef OCTANE_SCOPE_TIMER_HPP_INCLUDED
#define OCTANE_SCOPE_TIMER_HPP_INCLUDED

#include <iostream>
#include <string>

#include "timer.hpp"

/// Simple timer, measuring time from construction to destruction.
///
/// @ingroup Utility
///
class OctaneScopeTimer {

public:
    /// Constructor.
    /// @param _pre  - string to display before time.
    /// @param _post - string to display after time.
    /// @param _to   - stream for output.
    OctaneScopeTimer(const std::string _pre="<scope_timer> ",
                 const std::string _post=" seconds\n",
                 std::ostream &_to=std::cout)
       : pre(_pre), post(_post), to(_to)
    { ; }

    /// Get the elapsed time since construction.
    /// @return elapsed time.
    float get_elapsed() { return t.stop(); }

    /// Destructor. Outputs the elapsed time along with the pre-
    /// and post messages.
    ~OctaneScopeTimer() { to << pre << t.stop() << post; }

private:
    const std::string pre, post;
    std::ostream &to;
    OctaneTimer t;
};

#endif // OCTANE_SCOPE_TIMER_HPP_INCLUDED

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?