Rough PGN save support.
[tagua/yd.git] / src / common.cpp
blob85425e2c7ac41926db8267b9436e3b8e8e1d0598
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 "common.h"
20 namespace boost {
22 void throw_exception(std::exception const &) {
23 std::cout << "[bug] boost exception" << std::endl;
28 std::ostream &operator <<(std::ostream &os, const QString& s) {
29 os << s.toAscii().constData();
30 return os;
33 #ifdef Q_CC_GNU
34 void __attribute__ ((used))
35 #else
36 void
37 #endif
38 pstr(const QString& s) {
39 std::cout << "\"" << s << "\"" << std::endl;
42 QString qPrintf(const char* fmt, ...) {
43 va_list ap;
45 va_start(ap, fmt);
46 int l = vsnprintf(NULL, 0, fmt, ap)+1;
47 va_end(ap);
49 char *str = (char*)alloca(l);
50 //char *str = (char*)malloc(l);
51 va_start(ap, fmt);
52 vsnprintf(str, l, fmt, ap);
53 va_end(ap);
55 QString retv(str);
57 //free(str);
58 return retv;
61 #ifdef Q_CC_GNU
62 #include <typeinfo>
63 #include <cxxabi.h>
64 #endif //Q_CC_GNU
66 QString prettyTypeName(const char* name) {
67 #ifdef Q_CC_GNU
68 int s;
69 const char* res = abi::__cxa_demangle(name, NULL, NULL, &s);
70 if(res) {
71 QString retv(res);
72 free((void*)res);
73 return retv;
75 #endif //Q_CC_GNU
76 return QString(name);