Skip to content
Snippets Groups Projects
Commit 0a2f726c authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Fix Stopwatch to avoid unique global symbols

See #549
parent 521e06b7
No related branches found
No related tags found
No related merge requests found
...@@ -165,13 +165,15 @@ This will make sure timers are written also in case of a premature end. ...@@ -165,13 +165,15 @@ This will make sure timers are written also in case of a premature end.
class Log; class Log;
/// Return an empty string.
/// Inline static so that it can store a static variable (for quicker access)
/// without adding a unique global symbol to a library including this header file.
inline static const std::string & StopwatchEmptyString() noexcept {
const static std::string s;
return s;
}
class Stopwatch { class Stopwatch {
/// Simple function returning an empty string.
/// Used to simplify Stopwatch interface.
static const std::string & emptyString() {
static std::string s;
return s;
}
public: public:
/// Forward declaration /// Forward declaration
...@@ -263,23 +265,23 @@ public: ...@@ -263,23 +265,23 @@ public:
// Destructor. // Destructor.
~Stopwatch(); ~Stopwatch();
/// Start timer named "name" /// Start timer named "name"
Stopwatch& start(const std::string&name=emptyString()); Stopwatch& start(const std::string&name=StopwatchEmptyString());
/// Stop timer named "name" /// Stop timer named "name"
Stopwatch& stop(const std::string&name=emptyString()); Stopwatch& stop(const std::string&name=StopwatchEmptyString());
/// Pause timer named "name" /// Pause timer named "name"
Stopwatch& pause(const std::string&name=emptyString()); Stopwatch& pause(const std::string&name=StopwatchEmptyString());
/// Dump all timers on an ostream /// Dump all timers on an ostream
friend std::ostream& operator<<(std::ostream&,const Stopwatch&); friend std::ostream& operator<<(std::ostream&,const Stopwatch&);
/// Start with exception safety, then stop. /// Start with exception safety, then stop.
/// Starts the Stopwatch and returns an object that, when goes out of scope, /// Starts the Stopwatch and returns an object that, when goes out of scope,
/// stops the watch. This allows Stopwatch to be started and stopped in /// stops the watch. This allows Stopwatch to be started and stopped in
/// an exception safe manner. /// an exception safe manner.
Handler startStop(const std::string&name=emptyString()); Handler startStop(const std::string&name=StopwatchEmptyString());
/// Start with exception safety, then pause. /// Start with exception safety, then pause.
/// Starts the Stopwatch and returns an object that, when goes out of scope, /// Starts the Stopwatch and returns an object that, when goes out of scope,
/// pauses the watch. This allows Stopwatch to be started and paused in /// pauses the watch. This allows Stopwatch to be started and paused in
/// an exception safe manner. /// an exception safe manner.
Handler startPause(const std::string&name=emptyString()); Handler startPause(const std::string&name=StopwatchEmptyString());
}; };
inline inline
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment