libsex  3.1.0
simple exception library (C++)
/home/ptr/dev/dev-libs/libsex/libsex/utility.hxx
Go to the documentation of this file.
00001 /**
00002  * @file
00003  *
00004  * Declarations of auxiliary formatting functions intended
00005  * for internal use only.
00006  */
00007 
00008 #ifndef LIBSEX_UTILITY_HXX
00009 #define LIBSEX_UTILITY_HXX
00010 
00011 #include <libsex/Exception.hxx>
00012 
00013 #include <cstdarg> // variadic argument fun
00014 #include <cstdio>  // size_t
00015 
00016 namespace libsex
00017 {
00018         /**
00019          * Formats a message and writes it into @a buffer.
00020          *
00021          * It is guaranteed that not more than @a length
00022          * characters are written to @a buffer.
00023          *
00024          * @param buffer  String to be filled.
00025          * @param length  Size of buffer.
00026          * @param file    Filename in which the error occured.
00027          * @param line    Line number in which the error occured.
00028          * @param message printf formatstring template
00029          * @param ap      variadic argument list, holds parameters
00030          *                to be used when formatting (vsnprintf()).
00031          * @return true if buffer was large enough, false otherwise
00032          */
00033         bool vformat(
00034                 char* const buffer,
00035                 size_t length,
00036                 const char* const file,
00037                 unsigned short line,
00038                 const char* const message,
00039                 va_list ap) throw();
00040 
00041         /// @see vformat()
00042         bool format(
00043                 char* const buffer,
00044                 size_t length,
00045                 const char* const file,
00046                 unsigned short line,
00047                 const char* const message,
00048                 ...) throw();
00049 
00050         /**
00051          * Instanciates T with properly formatted message.
00052          *
00053          * T is supposed to have a static const char* TEMPLATE
00054          * field, which will be used as formatstring for vformat().
00055          *
00056          * @param file To be passed on to format().
00057          * @param line To be passed on to format().
00058          * @param ...  Passed to vformat() (sprintf() like).
00059          * @return Instance of T.
00060          */
00061         template <typename T>
00062         T formatted(
00063                 const char* const file,
00064                 unsigned short line,
00065                 ...) throw();
00066 
00067         /**
00068          * Instanciates T with properly formatted message and
00069          * a previous exception.
00070          *
00071          * @see formatted()
00072          */
00073         template <typename T>
00074         T formatted(
00075                 const Exception& previous,
00076                 const char* const file,
00077                 unsigned short line,
00078                 ...) throw();
00079 }
00080 
00081 #include "utility.ixx"
00082 
00083 #endif
 All Classes Files Functions Variables Defines