blob: 723bf1edc25d8c2b3194c3cff680cc250cb93d34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef PRINTUTILS_H_
#define PRINTUTILS_H_
#include <functional>
#include <iostream>
#include <list>
#include <string>
#include <boost/format.hpp>
extern std::function<void(std::string)> outputhandler, default_outputhandler;
void set_output_handler(std::function<void(std::string)>);
extern std::list<std::string> print_messages_stack;
void print_messages_push();
void print_messages_pop();
void PRINT(const std::string &msg);
#define PRINTB(_fmt, _arg) do { PRINT(str(boost::format(_fmt) % _arg)); } while (0)
void PRINT_NOCACHE(const std::string &msg);
#define PRINTB_NOCACHE(_fmt, _arg) do { PRINT_NOCACHE(str(boost::format(_fmt) % _arg)); } while (0)
void PRINT_CONTEXT(const class Context *ctx, const class Module *mod, const class ModuleInstantiation *inst);
std::string two_digit_exp_format( std::string doublestr );
std::string two_digit_exp_format( double x );
// extremely simple logging, eventually replace with something like boost.log
// usage: logstream out(5); openscad_loglevel=6; out << "hi";
static int openscad_loglevel = 0;
class logstream
{
public:
std::ostream *out;
int loglevel;
logstream( int level = 0 ) {
loglevel = level;
out = &(std::cout);
}
template <typename T> logstream & operator<<( T const &t ) {
if (out && loglevel <= openscad_loglevel) {
(*out) << t ;
out->flush();
}
return *this;
}
};
#endif
|