summaryrefslogtreecommitdiff
path: root/sal/inc
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-10-08 18:56:48 +0200
committerStephan Bergmann <sbergman@redhat.com>2011-10-08 18:56:48 +0200
commitd1076b1b7f4049d8820f410d72c7a60bfac95152 (patch)
treeb7d734cddb6b39a1028834e4307bbc5744c35e2f /sal/inc
parentd71c0373433da965f8a2d512f72df1d0a0adee2b (diff)
Second attempt at (cross-platform) OSL_FORMAT.
Diffstat (limited to 'sal/inc')
-rw-r--r--sal/inc/osl/diagnose.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/sal/inc/osl/diagnose.h b/sal/inc/osl/diagnose.h
index ab5243fe94d5..aab76b320f2a 100644
--- a/sal/inc/osl/diagnose.h
+++ b/sal/inc/osl/diagnose.h
@@ -192,6 +192,30 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pf
#define OSL_THIS_FUNC ""
#endif
+#if defined __cplusplus
+
+#include "rtl/string.hxx"
+
+/** @internal */
+extern "C" struct _rtl_String * SAL_CALL osl_detail_formatString(
+ char const * format, ...) SAL_THROW_EXTERN_C();
+ // "struct _rtl_String" instead of "rtl_String" for the case where
+ // osl/diagnose.h is included in rtl/string.hxx
+
+/** A facility for printf-style messages in OSL_ENSURE, OSL_FAIL, etc.
+
+ Use like: OSL_ENSURE(i == 5, OSL_FORMAT("i should be 5 but is %d", i));
+*/
+#define OSL_FORMAT(format, ...) \
+ (::rtl::OString( \
+ ::osl_detail_formatString(format, __VA_ARGS__), \
+ ::SAL_NO_ACQUIRE).getStr())
+ // it appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
+ // Express) already support variadic macros in C++; see also
+ // <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>
+
+#endif
+
#endif /* _OSL_DIAGNOSE_H_ */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */