libsex  3.1.0
simple exception library (C++)
/home/ptr/dev/dev-libs/libsex/libsex/utility.ixx
Go to the documentation of this file.
00001 /**
00002  * @file
00003  *
00004  * Templates of formatting-related internal functions.
00005  */
00006 
00007 #include <libsex/Exception.hxx> // Exception::LENGTH
00008 
00009 template <typename T>
00010 T libsex::formatted(
00011         const char* const file,
00012         unsigned short line,
00013         ...) throw()
00014 {
00015         // Temporary string should be initialized
00016         // with 0 to not forget a trailing 0.
00017         char buf[Exception::LENGTH + 1] = { 0 };
00018 
00019         va_list ap;
00020         va_start(ap, line);
00021 
00022         // Fill buf with formatted T::TEMPLATE message.
00023         vformat(buf, Exception::LENGTH + 1,
00024                 file, line,
00025                 T::TEMPLATE, ap);\
00026         va_end(ap);
00027 
00028         return T(buf);
00029 }
00030 
00031 template <typename T>
00032 T libsex::formatted(
00033         const Exception& previous,
00034         const char* const file,
00035         unsigned short line,
00036         ...) throw()
00037 {
00038         char buf[Exception::LENGTH + 1] = { 0 };
00039 
00040         va_list ap;
00041         va_start(ap, line);
00042         vformat(buf, Exception::LENGTH + 1,
00043                 file, line,
00044                 T::TEMPLATE, ap);\
00045         va_end(ap);
00046 
00047         return T(buf, previous);
00048 }
 All Classes Files Functions Variables Defines