Skip to content

Commit 3bded83

Browse files
committed
Merge branch 'mute-objcryst-info'
* add helper class MuteObjCrystUserInfo * mute console info output from SetPowderPatternObs Resolve #17.
2 parents 28a3fd7 + b0848d6 commit 3bded83

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/extensions/helpers.cpp

+30
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

+15
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);

src/extensions/powderpattern_ext.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void setpowderpatternobs (PowderPattern& pp, bp::object x)
101101
{
102102
CrystVector_REAL cvx;
103103
assignCrystVector(cvx, x);
104+
MuteObjCrystUserInfo muzzle;
104105
pp.SetPowderPatternObs(cvx);
105106
}
106107

0 commit comments

Comments
 (0)