Added throw specification.
[libsex.git] / include / libsex / utility.hxx
blob54f98ae1f91e8f329f1233e236d0015318e41508
1 #ifndef UTILITY_HXX
2 #define UTILITY_HXX
4 #include <cstdarg> // variadic argument fun
5 #include <cstdio> // (v)snprintf() and size_t
7 namespace libsex {
9 /**
10 * @brief Formats a message and writes it into @a buffer.
12 * It is guaranteed that not more than @a length characters
13 * are written to @a buffer.
15 * @TODO what to do when buffer too small?
17 * @param buffer String to be filled.
18 * @param length Size of buffer.
19 * @param file Filename in which the error occured.
20 * @param line Line number in which the error occured.
21 * @param message printf formatstring template
22 * @param ap variadic argument list, holds parameters
23 * to be used when formatting (vsnprintf()).
25 bool vformat(
26 char* const buffer,
27 size_t length,
28 const char* const file,
29 unsigned short line,
30 const char* const message,
31 va_list ap) throw();
33 /**
34 * @brief Same as the vformat() but uses "real" variadic
35 * arguments instead of va_list parameter.
37 bool format(
38 char* const buffer,
39 size_t length,
40 const char* const file,
41 unsigned short line,
42 const char* const message,
43 ...) throw();
45 /**
46 * @brief Instanciates T with properly formatted message.
48 * T is supposed to have a static const char*
49 * MessageTemplate field, which will be used as
50 * formatstring for makeMessage().
52 * @param file To be passed on to format().
53 * @param line To be passed on to format().
54 * @param ... Passed to format() (sprintf() like).
56 * @return Instance of T.
58 template <typename T>
59 T formatted(const char* const file, unsigned short line, ...) throw();
61 }; // namespace
63 #include "utility.ixx"
65 #endif