src/format.h

changeset 86
43fe4be38a58
parent 85
264a61e9eba0
equal deleted inserted replaced
85:264a61e9eba0 86:43fe4be38a58
33 #include "containers.h" 33 #include "containers.h"
34 34
35 class format_arg 35 class format_arg
36 { 36 {
37 public: 37 public:
38 format_arg (const string& a) : m_string (a) {} 38 format_arg (const string& a) :
39 format_arg (char a) : m_string (a) {} 39 m_string (a) {}
40 format_arg (int a) : m_string (string::from_number (a)) {} 40
41 format_arg (long a) : m_string (string::from_number (a)) {} 41 format_arg (char a) :
42 format_arg (const char* a) : m_string (a) {} 42 m_string (a) {}
43
44 format_arg (int a) :
45 m_string (string::from_number (a)) {}
46
47 format_arg (long a) :
48 m_string (string::from_number (a)) {}
49
50 format_arg (const char* a) :
51 m_string (a) {}
43 52
44 format_arg (void* a) 53 format_arg (void* a)
45 { 54 {
46 m_string.sprintf ("%p", a); 55 m_string.sprintf ("%p", a);
47 } 56 }
86 string out; 95 string out;
87 out.sprintf (fmtstr, a); 96 out.sprintf (fmtstr, a);
88 return out; 97 return out;
89 } 98 }
90 99
91 inline string hex (ulong a)
92 {
93 return custom_format (a, "0x%X");
94 }
95
96 inline string charnum (char a)
97 {
98 return custom_format (a, "%d");
99 }
100
101 class script_error : public std::exception
102 {
103 public:
104 script_error (const string& msg) : m_msg (msg) {}
105
106 inline const char* what() const throw()
107 {
108 return m_msg.c_str();
109 }
110
111 private:
112 string m_msg;
113 };
114
115 string format_args (const list<format_arg>& args); 100 string format_args (const list<format_arg>& args);
116 void print_args (FILE* fp, const list<format_arg>& args); 101 void print_args (FILE* fp, const list<format_arg>& args);
117 void do_fatal (const list<format_arg>& args); 102 void do_fatal (const list<format_arg>& args);
118 void do_error (string msg); 103 void do_error (string msg);
119 104

mercurial