Replaced all std::cout with kDebug.
[tagua/yd.git] / src / common.cpp
blob65a8f8db668a4b050c76b6a9fda6b40a2469117f
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 // throw exception: used by boost
13 #include <string.h>
14 #include <stdlib.h>
15 #include <stdarg.h>
16 #include <iostream>
17 #include <QString>
18 #include <KDebug>
19 #include "common.h"
21 namespace boost {
23 void throw_exception(std::exception const &) {
24 kError() << "[bug] boost exception";
29 std::ostream &operator <<(std::ostream &os, const QString& s) {
30 os << s.toAscii().constData();
31 return os;
34 #ifdef Q_CC_GNU
35 void __attribute__ ((used))
36 #else
37 void
38 #endif
39 pstr(const QString& s) {
40 kDebug() << "\"" << s << "\"";
43 QString qPrintf(const char* fmt, ...) {
44 va_list ap;
46 va_start(ap, fmt);
47 int l = vsnprintf(NULL, 0, fmt, ap)+1;
48 va_end(ap);
50 char *str = (char*)alloca(l);
51 //char *str = (char*)malloc(l);
52 va_start(ap, fmt);
53 vsnprintf(str, l, fmt, ap);
54 va_end(ap);
56 QString retv(str);
58 //free(str);
59 return retv;
62 #ifdef Q_CC_GNU
63 #include <typeinfo>
64 #include <cxxabi.h>
65 #endif //Q_CC_GNU
67 QString prettyTypeName(const char* name) {
68 #ifdef Q_CC_GNU
69 int s;
70 const char* res = abi::__cxa_demangle(name, NULL, NULL, &s);
71 if(res) {
72 QString retv(res);
73 free((void*)res);
74 return retv;
76 #endif //Q_CC_GNU
77 return QString(name);