31 #pragma once |
31 #pragma once |
32 #include "mystring.h" |
32 #include "mystring.h" |
33 #include "basics.h" |
33 #include "basics.h" |
34 #include "geometry.h" |
34 #include "geometry.h" |
35 |
35 |
36 #define FORMAT_OVERLOAD(...) \ |
36 // ------------------------------------------------------------------------------------------------- |
37 inline String make_format_argument (__VA_ARGS__ a) |
37 // |
38 |
38 inline String make_format_argument (String a) { return a; } |
39 // ------------------------------------------------------------------------------------------------- |
39 inline String make_format_argument (char a) { return String (a); } |
40 // |
40 inline String make_format_argument (short a) { return String::from_number (a); } |
41 FORMAT_OVERLOAD (String) { return a; } |
41 inline String make_format_argument (int a) { return String::from_number (a); } |
42 FORMAT_OVERLOAD (char) { return String (a); } |
42 inline String make_format_argument (long a) { return String::from_number (a); } |
43 FORMAT_OVERLOAD (short int) { return String::from_number (a); } |
43 inline String make_format_argument (double a) { return String::from_number (a); } |
44 FORMAT_OVERLOAD (int) { return String::from_number (a); } |
44 inline String make_format_argument (unsigned short a) { return String::from_number (a); } |
45 FORMAT_OVERLOAD (long int) { return String::from_number (a); } |
45 inline String make_format_argument (unsigned int a) { return String::from_number (a); } |
46 FORMAT_OVERLOAD (double) { return String::from_number (a); } |
46 inline String make_format_argument (unsigned long a) { return String::from_number (a); } |
47 FORMAT_OVERLOAD (unsigned short int) { return String::from_number (a); } |
47 inline String make_format_argument (const char* a) { return a; } |
48 FORMAT_OVERLOAD (unsigned int) { return String::from_number (a); } |
48 inline String make_format_argument (std::nullptr_t) { return "<null pointer>"; } |
49 FORMAT_OVERLOAD (unsigned long int) { return String::from_number (a); } |
49 inline String make_format_argument (bool a) { return a ? "true" : "false"; } |
50 FORMAT_OVERLOAD (const char*) { return a; } |
50 |
51 FORMAT_OVERLOAD (std::nullptr_t) { (void) a; return "<null pointer>"; } |
51 inline String make_format_argument (const void* a) |
52 FORMAT_OVERLOAD (bool) { return a ? "true" : "false"; } |
|
53 |
|
54 FORMAT_OVERLOAD (const void*) |
|
55 { |
52 { |
56 String result; |
53 String result; |
57 result.sprintf ("%p", a); |
54 result.sprintf ("%p", a); |
58 return result; |
55 return result; |
59 } |
56 } |
60 |
57 |
61 template<typename T, typename C> |
58 template<typename T, typename C> |
62 FORMAT_OVERLOAD (const Container<T, C>&) |
59 inline String make_format_argument (const Container<T, C>& a) |
63 { |
60 { |
64 String result; |
61 String result; |
65 |
62 |
66 if (a.is_empty()) |
63 if (a.is_empty()) |
67 return "{}"; |
64 return "{}"; |
78 |
75 |
79 result += "}"; |
76 result += "}"; |
80 return result; |
77 return result; |
81 } |
78 } |
82 |
79 |
83 FORMAT_OVERLOAD (Color) |
80 inline String make_format_argument (Color a) |
84 { |
81 { |
85 static const char* colorstrings[] = |
82 static const char* colorstrings[] = |
86 { |
83 { |
87 "BLACK", "RED", "GREEN", "YELLOW", |
84 "BLACK", "RED", "GREEN", "YELLOW", |
88 "BLUE", "MAGENTA", "CYAN", "WHITE", "DEFAULT" |
85 "BLUE", "MAGENTA", "CYAN", "WHITE", "DEFAULT" |
95 return colorstrings[int (a)]; |
92 return colorstrings[int (a)]; |
96 |
93 |
97 return "???"; |
94 return "???"; |
98 } |
95 } |
99 |
96 |
100 FORMAT_OVERLOAD (Position) |
97 inline String make_format_argument (const Position& a) |
101 { |
98 { |
102 return String ("(") + a.x + ", " + a.y + ")"; |
99 return String ("(") + a.x + ", " + a.y + ")"; |
103 } |
100 } |
104 |
101 |
105 FORMAT_OVERLOAD (Size) |
102 inline String make_format_argument (const Size& a) |
106 { |
103 { |
107 return String ("(") + a.width + "x" + a.height + ")"; |
104 return String ("(") + a.width + "x" + a.height + ")"; |
108 } |
105 } |
109 |
106 |
110 FORMAT_OVERLOAD (Rectangle) |
107 inline String make_format_argument (const Rectangle& a) |
111 { |
108 { |
112 String result; |
109 String result; |
113 result.sprintf ("{(%d, %d), (%dx%d)}", a.x, a.y, a.width, a.height); |
110 result.sprintf ("{(%d, %d), (%dx%d)}", a.x, a.y, a.width, a.height); |
114 return result; |
111 return result; |
115 } |
112 } |
116 |
113 |
117 // ------------------------------------------------------------------------------------------------- |
114 // ------------------------------------------------------------------------------------------------- |
118 // |
115 // |
119 // Formats the given string with the given args. |
116 // Formats the given string with the given args. |
120 // |
117 // |
121 FUNCTION format_args (const String& fmtstr, const Vector<String>& args) -> String; |
118 String format_args (const String& fmtstr, const Vector<String>& args); |
122 |
119 |
123 // ------------------------------------------------------------------------------------------------- |
120 // ------------------------------------------------------------------------------------------------- |
124 // |
121 // |
125 // Expands the given arguments into a vector of strings. |
122 // Expands the given arguments into a vector of strings. |
126 // |
123 // |