Skip to content

Commit 2dc8a48

Browse files
committed
ENH: add helper class MuteObjCrystUserInfo
Support temporary override of fpObjCrystInformUser value.
1 parent aebd586 commit 2dc8a48

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/extensions/helpers.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@
3232

3333
namespace bp = boost::python;
3434

35+
namespace {
36+
37+
void black_hole_info(const std::string& s) { }
38+
39+
} // namespace
40+
41+
// class MuteObjCrystUserInfo ------------------------------------------------
42+
43+
MuteObjCrystUserInfo::MuteObjCrystUserInfo() :
44+
msave_info_func(ObjCryst::fpObjCrystInformUser)
45+
{
46+
ObjCryst::fpObjCrystInformUser = black_hole_info;
47+
}
48+
49+
50+
MuteObjCrystUserInfo::~MuteObjCrystUserInfo()
51+
{
52+
this->release();
53+
}
54+
55+
56+
void MuteObjCrystUserInfo::release()
57+
{
58+
using ObjCryst::fpObjCrystInformUser;
59+
if (msave_info_func) fpObjCrystInformUser = msave_info_func;
60+
msave_info_func = NULL;
61+
}
62+
63+
// free functions ------------------------------------------------------------
64+
3565
void swapstdout(std::ostream& buf)
3666
{
3767
// Switch the stream buffer with std::cout, which is used by Print.

src/extensions/helpers.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ namespace bp = boost::python;
3434

3535
typedef std::numeric_limits<double> doublelim;
3636

37+
class MuteObjCrystUserInfo
38+
{
39+
public:
40+
41+
MuteObjCrystUserInfo();
42+
~MuteObjCrystUserInfo();
43+
void release();
44+
45+
private:
46+
47+
// pointer to the previous info function
48+
void (*msave_info_func)(const std::string &);
49+
};
50+
51+
3752
// Switch stdout with another stream. To get things back the right way, just
3853
// switch again with the same stream.
3954
void swapstdout(std::ostream& buf);

0 commit comments

Comments
 (0)