Improved doc and syntax.
[libsex.git] / include / libsex / utility.hxx
blob59b8c967740043f1c82a07da03458f62deaecfa1
1 #ifndef LIBSEX_UTILITY_HXX
2 #define LIBSEX_UTILITY_HXX
4 #include <cstdarg> // variadic argument fun
5 #include <cstdio> // size_t
7 namespace libsex {
9 /**
10 * 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 * @param buffer String to be filled.
16 * @param length Size of buffer.
17 * @param file Filename in which the error occured.
18 * @param line Line number in which the error occured.
19 * @param message printf formatstring template
20 * @param ap variadic argument list, holds parameters
21 * to be used when formatting (vsnprintf()).
22 * @return true if buffer was large enough, false otherwise
24 bool vformat(
25 char* const buffer,
26 size_t length,
27 const char* const file,
28 unsigned short line,
29 const char* const message,
30 va_list ap) throw();
32 /// @see vformat()
33 bool format(
34 char* const buffer,
35 size_t length,
36 const char* const file,
37 unsigned short line,
38 const char* const message,
39 ...) throw();
41 /**
42 * Instanciates T with properly formatted message.
44 * T is supposed to have a static const char* TEMPLATE
45 * field, which will be used as formatstring for vformat().
47 * @param file To be passed on to format().
48 * @param line To be passed on to format().
49 * @param ... Passed to vformat() (sprintf() like).
50 * @return Instance of T.
52 template <typename T>
53 T formatted(
54 const char* const file,
55 unsigned short line,
56 ...) throw();
58 }; // End of namespace.
60 #include "utility.ixx"
62 #endif