pbp_addons.cpp
Go to the documentation of this file.
1// my headers
2#include "corefaudes.h"
3#include "pbp_addons.h"
4
5// python header
6#include "Python.h"
7
8namespace faudes {
9
10
11// write to Python's sys.stdout
12void faudes_pprint(const char* msg) {
13 PySys_FormatStdout(msg);
14}
15
16
17// redirect libFAUDES console
19public:
20 // singleton access
21 static PythonConsole* G(void);
22 // singelton destructor
23 static void Destruct(void);
24private:
25 // construct/destruct
27 virtual ~PythonConsole();
28protected:
29 // reimplement faudes dowrite
30 void DoWrite(const std::string& message, long int cntnow, long int cntdone, int verb=0);
31 // single instance
33};
34
35
36// static singleton incl construction
38
39// explcit activation
40void faudes_redirect(bool on) {
41 static PythonConsole* gSinglRythonConsole=NULL;
42 if(on) {
43 gSinglRythonConsole=PythonConsole::G();
44 } else {
46 }
47}
48
49// private construct
51 FD_WARN("faudes::ConsoleOut(): redirect to sys.stdout")
53};
54// private destruct
56 FD_WARN("faudes::ConsoleOut(): redirect off");
58 mpVInstance=NULL;
59};
60// access/construct singleton
65// destruct singleton
67 if(!mpVInstance) return;
68 delete mpVInstance;
70}
71// faudes hook ...
72// ... is rather fragile due to interference between logging and loop call back
73// ... dont use debugging macros FD_xxx here, they will mess up logging
74void PythonConsole::DoWrite(const std::string& message,long int cntnow, long int cntdone, int verb) {
75 (void) cntnow; (void) cntdone;
76 // we're on mute
77 if(Verb()<verb) {
78 return;
79 }
80 // its a file
81 if(IsFile()) {
82 ConsoleOut::DoWrite(message,cntnow,cntdone,verb);
83 return;
84 }
85 // its the console we want to grab
86 faudes_pprint(message.c_str());
87}
88
89
90
91
92}//namespace
#define FD_WARN(message)
static ConsoleOut * G(void)
virtual void DoWrite(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=1)
void Redirect(ConsoleOut *out)
static PythonConsole * mpVInstance
void DoWrite(const std::string &message, long int cntnow, long int cntdone, int verb=0)
static void Destruct(void)
static PythonConsole * G(void)
void faudes_pprint(const char *msg)
void faudes_redirect(bool on)

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen