2009-12-09 17:22:50 +03:00
|
|
|
#ifndef PRINTUTILS_H_
|
|
|
|
#define PRINTUTILS_H_
|
|
|
|
|
2011-11-01 02:56:35 +04:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2011-04-29 19:06:46 +04:00
|
|
|
#include <iostream>
|
2012-01-25 06:11:12 +04:00
|
|
|
#include <boost/format.hpp>
|
2010-01-06 13:48:51 +03:00
|
|
|
|
2011-11-01 02:56:35 +04:00
|
|
|
typedef void (OutputHandlerFunc)(const std::string &msg, void *userdata);
|
2010-02-28 23:54:55 +03:00
|
|
|
extern OutputHandlerFunc *outputhandler;
|
|
|
|
extern void *outputhandler_data;
|
|
|
|
|
|
|
|
void set_output_handler(OutputHandlerFunc *newhandler, void *userdata);
|
|
|
|
|
2011-11-01 02:56:35 +04:00
|
|
|
extern std::list<std::string> print_messages_stack;
|
2010-01-06 13:48:51 +03:00
|
|
|
void print_messages_push();
|
|
|
|
void print_messages_pop();
|
2014-03-03 07:09:10 +04:00
|
|
|
void printDeprecation(const std::string &str);
|
|
|
|
void resetPrintedDeprecations();
|
|
|
|
|
|
|
|
#define PRINT_DEPRECATION(_fmt, _arg) do { printDeprecation(str(boost::format(_fmt) % _arg)); } while (0)
|
2009-12-09 17:22:50 +03:00
|
|
|
|
2011-11-01 02:56:35 +04:00
|
|
|
void PRINT(const std::string &msg);
|
2012-01-25 06:11:12 +04:00
|
|
|
#define PRINTB(_fmt, _arg) do { PRINT(str(boost::format(_fmt) % _arg)); } while (0)
|
2009-12-09 17:22:50 +03:00
|
|
|
|
2011-11-01 02:56:35 +04:00
|
|
|
void PRINT_NOCACHE(const std::string &msg);
|
2012-01-25 06:11:12 +04:00
|
|
|
#define PRINTB_NOCACHE(_fmt, _arg) do { PRINT_NOCACHE(str(boost::format(_fmt) % _arg)); } while (0)
|
2011-04-29 19:06:46 +04:00
|
|
|
|
2013-04-09 08:28:16 +04:00
|
|
|
|
|
|
|
void PRINT_CONTEXT(const class Context *ctx, const class Module *mod, const class ModuleInstantiation *inst);
|
|
|
|
|
2013-02-14 08:55:19 +04:00
|
|
|
std::string two_digit_exp_format( std::string doublestr );
|
|
|
|
std::string two_digit_exp_format( double x );
|
|
|
|
|
2012-10-28 17:56:23 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-12-09 17:22:50 +03:00
|
|
|
#endif
|