| 13 typedef unsigned int uint; |
13 typedef unsigned int uint; |
| 14 typedef unsigned short ushort; |
14 typedef unsigned short ushort; |
| 15 typedef unsigned long ulong; |
15 typedef unsigned long ulong; |
| 16 template<class T> using initlist = std::initializer_list<T>; |
16 template<class T> using initlist = std::initializer_list<T>; |
| 17 using std::size_t; |
17 using std::size_t; |
| |
18 |
| |
19 typedef qint8 int8; |
| |
20 typedef qint16 int16; |
| |
21 typedef qint32 int32; |
| |
22 typedef qint64 int64; |
| |
23 typedef quint8 uint8; |
| |
24 typedef quint16 uint16; |
| |
25 typedef quint32 uint32; |
| |
26 typedef quint64 uint64; |
| |
27 |
| |
28 #ifdef IN_IDE_PARSER // :| |
| |
29 typedef void FILE; |
| |
30 #endif |
| 18 |
31 |
| 19 // ============================================================================= |
32 // ============================================================================= |
| 20 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 21 // ============================================================================= |
34 // ============================================================================= |
| 22 // StringFormatArg |
35 // StringFormatArg |
| 51 StringFormatArg( const void* v ); |
64 StringFormatArg( const void* v ); |
| 52 |
65 |
| 53 template<class T> StringFormatArg( const list<T>& v ) { |
66 template<class T> StringFormatArg( const list<T>& v ) { |
| 54 m_val = "{ "; |
67 m_val = "{ "; |
| 55 uint i = 0; |
68 uint i = 0; |
| |
69 const bool isString = typeid( T ) == typeid( str ); |
| 56 |
70 |
| 57 for( const T& it : v ) { |
71 for( const T& it : v ) { |
| 58 if( i++ ) |
72 if( i++ ) |
| 59 m_val += ", "; |
73 m_val += ", "; |
| 60 |
74 |
| 61 StringFormatArg arg( it ); |
75 StringFormatArg arg( it ); |
| 62 m_val += arg.value(); |
76 |
| |
77 if( isString ) |
| |
78 m_val += "\"" + arg.value() + "\""; |
| |
79 else |
| |
80 m_val += arg.value(); |
| 63 } |
81 } |
| 64 |
82 |
| 65 if( i ) |
83 if( i ) |
| 66 m_val += " "; |
84 m_val += " "; |
| 67 |
85 |
| 77 |
95 |
| 78 // Formatter function |
96 // Formatter function |
| 79 str doFormat( initlist<StringFormatArg> args ); |
97 str doFormat( initlist<StringFormatArg> args ); |
| 80 |
98 |
| 81 // printf replacement |
99 // printf replacement |
| 82 void doPrint( initlist<StringFormatArg> args ); |
100 void doPrint( FILE* fp, initlist<StringFormatArg> args ); |
| 83 |
101 |
| 84 // Macros to access these functions |
102 // Macros to access these functions |
| 85 #ifndef IN_IDE_PARSER |
103 #ifndef IN_IDE_PARSER |
| 86 # define fmt(...) doFormat({ __VA_ARGS__ }) |
104 # define fmt(...) doFormat({ __VA_ARGS__ }) |
| 87 # define print(...) doPrint({ __VA_ARGS__ }) |
105 # define print(...) doPrint( stdout, { __VA_ARGS__ }) |
| |
106 # define fprint(FP, ...) doPrint( FP, { __VA_ARGS__ }) |
| 88 #else |
107 #else |
| 89 str fmt( const char* fmtstr, ... ); |
108 str fmt( const char* fmtstr, ... ); |
| 90 void print( const char* fmtstr, ... ); |
109 void print( const char* fmtstr, ... ); |
| |
110 void fprint( FILE* fp, const char* fmtstr, ... ); |
| 91 #endif |
111 #endif |
| 92 |
112 |
| 93 #endif // TYPES_H |
113 #endif // TYPES_H |