src/types.h

Wed, 17 Jul 2013 01:53:57 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 17 Jul 2013 01:53:57 +0300
changeset 3
d0b278fd29d5
parent 1
c9b22c06307c
child 6
67b6ef6917ba
permissions
-rw-r--r--

Implemented wad path list

0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #ifndef TYPES_H
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 #define TYPES_H
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 #include "main.h"
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 #include <QString>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 #include <QList>
3
d0b278fd29d5 Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
7 #include <QVariant>
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 typedef QString str;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 typedef QChar qchar;
3
d0b278fd29d5 Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
11 typedef QVariant var;
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 template<class T> using list = QList<T>;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 typedef unsigned int uint;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 typedef unsigned short ushort;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 typedef unsigned long ulong;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 template<class T> using initlist = std::initializer_list<T>;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 using std::size_t;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 // StringFormatArg
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 //
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 // Converts a given value into a string that can be retrieved with ::value ().
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 // Used as the argument type to the formatting functions, hence its name.
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 class StringFormatArg {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 public:
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 StringFormatArg( const str& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 StringFormatArg( const char& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 StringFormatArg( const uchar& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 StringFormatArg( const qchar& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #define NUMERIC_FORMAT_ARG(T,C) \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 StringFormatArg (const T& v) { \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 char valstr[32]; \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 sprintf (valstr, "%" #C, v); \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 m_val = valstr; \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 NUMERIC_FORMAT_ARG( int, d )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 NUMERIC_FORMAT_ARG( short, d )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 NUMERIC_FORMAT_ARG( long, ld )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 NUMERIC_FORMAT_ARG( uint, u )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 NUMERIC_FORMAT_ARG( ushort, u )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 NUMERIC_FORMAT_ARG( ulong, lu )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 StringFormatArg( const float& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 StringFormatArg( const double& v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 StringFormatArg( const char* v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 StringFormatArg( const void* v );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 template<class T> StringFormatArg( const list<T>& v ) {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 m_val = "{ ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 uint i = 0;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 for( const T& it : v ) {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 if( i++ )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 m_val += ", ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 StringFormatArg arg( it );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 m_val += arg.value();
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 if( i )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 m_val += " ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 m_val += "}";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 str value() const {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 return m_val;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 private:
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 str m_val;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 };
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // Formatter function
1
c9b22c06307c Done config box base
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
79 str doFormat( initlist<StringFormatArg> args );
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 // printf replacement
1
c9b22c06307c Done config box base
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
82 void doPrint( initlist<StringFormatArg> args );
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 // Macros to access these functions
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 #ifndef IN_IDE_PARSER
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 # define fmt(...) doFormat({ __VA_ARGS__ })
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 # define print(...) doPrint({ __VA_ARGS__ })
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 #else
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 str fmt( const char* fmtstr, ... );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 void print( const char* fmtstr, ... );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 #endif
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 #endif // TYPES_H

mercurial