Fix: Headers are now installed.
[libsex.git] / include / libsex / utility.hxx
blob8a120a6632f9769d726228abd15c67abae5faaf8
1 #ifndef LIBSEX_UTILITY_HXX
2 #define LIBSEX_UTILITY_HXX
4 #include <libsex/Exception.hxx>
6 #include <cstdarg> // variadic argument fun
7 #include <cstdio> // size_t
9 namespace libsex {
11 /**
12 * Formats a message and writes it into @a buffer.
14 * It is guaranteed that not more than @a length characters
15 * are written to @a buffer.
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()).
24 * @return true if buffer was large enough, false otherwise
26 bool vformat(
27 char* const buffer,
28 size_t length,
29 const char* const file,
30 unsigned short line,
31 const char* const message,
32 va_list ap) throw();
34 /// @see vformat()
35 bool format(
36 char* const buffer,
37 size_t length,
38 const char* const file,
39 unsigned short line,
40 const char* const message,
41 ...) throw();
43 /**
44 * Instanciates T with properly formatted message.
46 * T is supposed to have a static const char* TEMPLATE
47 * field, which will be used as formatstring for vformat().
49 * @param file To be passed on to format().
50 * @param line To be passed on to format().
51 * @param ... Passed to vformat() (sprintf() like).
52 * @return Instance of T.
54 template <typename T>
55 T formatted(
56 const char* const file,
57 unsigned short line,
58 ...) throw();
60 /**
61 * Instanciates T with properly formatted message and
62 * a previous exception.
64 * @see formatted()
66 template <typename T>
67 T formatted(
68 const Exception& previous,
69 const char* const file,
70 unsigned short line,
71 ...) throw();
73 }; // End of namespace.
75 #include "utility.ixx"
77 #endif