move RedirectCout to base/utilities.h
parent
54063934fa
commit
86c47d52d5
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace gtsam {
|
||||||
|
/**
|
||||||
|
* For Python __str__().
|
||||||
|
* Redirect std cout to a string stream so we can return a string representation
|
||||||
|
* of an object when it prints to cout.
|
||||||
|
* https://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
|
||||||
|
*/
|
||||||
|
struct RedirectCout {
|
||||||
|
/// constructor -- redirect stdout buffer to a stringstream buffer
|
||||||
|
RedirectCout() : ssBuffer_(), coutBuffer_(std::cout.rdbuf(ssBuffer_.rdbuf())) {}
|
||||||
|
|
||||||
|
/// return the string
|
||||||
|
std::string str() const {
|
||||||
|
return ssBuffer_.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// destructor -- redirect stdout buffer to its original buffer
|
||||||
|
~RedirectCout() {
|
||||||
|
std::cout.rdbuf(coutBuffer_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::stringstream ssBuffer_;
|
||||||
|
std::streambuf* coutBuffer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -260,30 +260,5 @@ Values localToWorld(const Values& local, const Pose2& base,
|
||||||
|
|
||||||
} // namespace utilities
|
} // namespace utilities
|
||||||
|
|
||||||
/**
|
|
||||||
* For Python __str__().
|
|
||||||
* Redirect std cout to a string stream so we can return a string representation
|
|
||||||
* of an object when it prints to cout.
|
|
||||||
* https://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
|
|
||||||
*/
|
|
||||||
struct RedirectCout {
|
|
||||||
/// constructor -- redirect stdout buffer to a stringstream buffer
|
|
||||||
RedirectCout() : ssBuffer_(), coutBuffer_(std::cout.rdbuf(ssBuffer_.rdbuf())) {}
|
|
||||||
|
|
||||||
/// return the string
|
|
||||||
std::string str() const {
|
|
||||||
return ssBuffer_.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// destructor -- redirect stdout buffer to its original buffer
|
|
||||||
~RedirectCout() {
|
|
||||||
std::cout.rdbuf(coutBuffer_);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::stringstream ssBuffer_;
|
|
||||||
std::streambuf* coutBuffer_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue