Added (untested) Doxyfile.

Documented a few more hz files.
Added clang detection to the build system, use it when setting flags, etc...
Added some clang-specific flags to avoid excessive and unneeded warnings.
Fixed compilation under clang.
Fixed some clang-reported warnings.
This commit is contained in:
Alexander Shaduri
2011-08-15 20:08:11 +00:00
parent b19b094aaa
commit 0ffba26b1f
13 changed files with 1884 additions and 394 deletions
File diff suppressed because it is too large Load Diff
@@ -30,7 +30,7 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
# ---- Common compiler options (warnings, etc...)
AC_ARG_ENABLE(common-options, AS_HELP_STRING([--enable-common-options=<compiler>|auto|none],
[enable useful compilation options (warnings, mostly). Accepted values are auto, none, gnu, intel, sun. (Default: auto)]),
[enable useful compilation options (warnings, mostly). Accepted values are auto, none, gnu, clang, intel, sun. (Default: auto)]),
[app_cv_compiler_common_options=${enableval}], [app_cv_compiler_common_options=auto])
# the default value is "yes" (if no value given after =), treat it as auto.
@@ -47,8 +47,8 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
if test "x$app_cv_compiler_common_options" != "xnone"; then
# gcc / gnu environment, mingw, cygwin.
if test "x$app_cv_compiler_common_options" = "xgnu"; then
# gcc (or clang) / gnu environment, mingw, cygwin.
if test "x$app_cv_compiler_common_options" = "xgnu" || test "x$app_cv_compiler_common_options" = "xclang"; then
if test "x$app_cv_target_os_env" = "xmingw32" || test "x$app_cv_target_os_env" = "xmingw64" \
|| test "x$app_cv_target_os_env" = "xcygwin"; then
@@ -63,6 +63,10 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
app_cv_compiler_tmp_var="-Wall -Wcast-align -Wcast-qual -Wconversion \
-Wctor-dtor-privacy -Wfloat-equal -Wnon-virtual-dtor -Woverloaded-virtual \
-Wpointer-arith -Wshadow -Wsign-compare -Wsign-promo -Wundef -Wwrite-strings";
if test "x$app_cv_compiler_common_options" = "xclang"; then
# these are really annoying
app_cv_compiler_tmp_var="$app_cv_compiler_tmp_var -Wno-sign-conversion -Wno-format-security"
fi
app_cv_compiler_options_cflags="$app_cv_compiler_options_cflags $app_cv_compiler_tmp_var";
app_cv_compiler_options_cxxflags="$app_cv_compiler_options_cxxflags $app_cv_compiler_tmp_var";
@@ -102,7 +106,7 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
# ---- Compiler options for debug builds
AC_ARG_ENABLE(debug-options, AS_HELP_STRING([--enable-debug-options=<compiler>|auto|none],
[enable debug build options. Accepted values are auto, none, gnu, intel, sun. (Default: none)]),
[enable debug build options. Accepted values are auto, none, gnu, clang, intel, sun. (Default: none)]),
[app_cv_compiler_debug_options=${enableval}], [app_cv_compiler_debug_options=none])
# the default value is "yes" (if no value given after =), treat it as auto.
@@ -124,7 +128,7 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
AC_DEFINE([DEBUG_BUILD], [1], [Defined for debug builds])
# gcc, mingw
if test "x$app_cv_compiler_debug_options" = "xgnu"; then
if test "x$app_cv_compiler_debug_options" = "xgnu" || test "x$app_cv_compiler_debug_options" = "xclang"; then
# We could put libstdc++ debug options here, but it generates binary-incompatible
# C++ code, which leads to runtime errors with e.g. libsigc++.
app_cv_compiler_options_cflags="$app_cv_compiler_options_cflags -g3 -O0";
@@ -154,7 +158,7 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
# ---- Compiler options for optimized builds
AC_ARG_ENABLE(optimize-options, AS_HELP_STRING([--enable-optimize-options=<compiler>|auto|none],
[enable optimized build options. Accepted values are auto, none, gnu, intel, sun. (Default: none)]),
[enable optimized build options. Accepted values are auto, none, gnu, clang, intel, sun. (Default: none)]),
[app_cv_compiler_optimize_options=${enableval}], [app_cv_compiler_optimize_options=none])
# the default value is "yes" (if no value given after =), treat it as auto.
@@ -172,7 +176,7 @@ AC_DEFUN([APP_COMPILER_OPTIONS], [
if test "x$app_cv_compiler_optimize_options" != "xnone"; then
# gcc, mingw
if test "x$app_cv_compiler_optimize_options" = "xgnu"; then
if test "x$app_cv_compiler_optimize_options" = "xgnu" || test "x$app_cv_compiler_optimize_options" = "xclang"; then
# -mtune=generic is since gcc 4.0 iirc
if test "x$app_cv_target_os_env" = "xmingw32"; then
app_cv_compiler_options_cflags="$app_cv_compiler_options_cflags -g0 -O3 -s -march=i686";
+10 -10
View File
@@ -55,8 +55,8 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
linux)
# glibc manual says that defining either _REENTRANT or _THREAD_SAFE
# enables some thread-safe implementations of glibc functions.
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "intel" \
|| test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang" \
|| test "$ax_cv_cxx_compiler_vendor" = "intel" || test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
app_cv_target_thread_cflags="-pthread -D_MT -D_THREAD_SAFE"
app_cv_target_thread_cxxflags="-pthread -D_MT -D_THREAD_SAFE"
app_cv_target_thread_libs="-pthread"
@@ -77,12 +77,12 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
;;
windows*)
# NOTE: Not sure about cygwin.
# NOTE: Not sure about cygwin or clang.
# NOTE: This only enables multithreaded code generation. For linking
# with pthreads-win32 you need additional flags.
# gcc man page: -mthreads: Support thread-safe exception handling on Mingw32.
# -mthreads defines -D_MT, and links with -lmingwthrd.
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
app_cv_target_thread_cflags="-mthreads -D_THREAD_SAFE"
app_cv_target_thread_cxxflags="-mthreads -D_THREAD_SAFE"
app_cv_target_thread_libs="-mthreads"
@@ -104,7 +104,7 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
# NOTE: Not sure about debian gnu/kfreebsd and gnu/netbsd.
# Freebsd had -kthread, but it has been discontinued (afaik).
# For freebsd -pthread replaces libc with libc_r.
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
app_cv_target_thread_cflags="-pthread -D_MT -D_THREAD_SAFE"
app_cv_target_thread_cxxflags="-pthread -D_MT -D_THREAD_SAFE"
app_cv_target_thread_libs="-pthread"
@@ -113,7 +113,7 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
;;
openbsd)
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
app_cv_target_thread_cflags="-pthread -D_REENTRANT"
app_cv_target_thread_cxxflags="-pthread -D_REENTRANT"
app_cv_target_thread_libs="-pthread"
@@ -123,7 +123,7 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
netbsd)
# See sys/featuretest.h
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
app_cv_target_thread_cflags="-pthread -D_REENTRANT"
app_cv_target_thread_cxxflags="-pthread -D_REENTRANT"
app_cv_target_thread_libs="-pthread"
@@ -132,7 +132,7 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
;;
solaris)
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
# gnu documentation mentions -threads (and its aliases, -pthreads and -pthread).
# _REENTRANT is needed to enable some thread-safe equivalents of standard
# functions.
@@ -159,14 +159,14 @@ AC_DEFUN([APP_GET_MT_FLAGS], [
;;
darwin)
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
# Darwin produces mt code by default, and -pthread is an error.
app_cv_target_thread_found="yes"
fi
;;
qnx)
if test "$ax_cv_cxx_compiler_vendor" = "gnu"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang"; then
# afaik, gcc/qnx produces mt code by default (at least on newer qnx releases),
# so no flags are needed.
app_cv_target_thread_found="yes"
@@ -53,7 +53,7 @@ AC_DEFUN([AX_COMPILER_VENDOR],
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
[ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
# note: don't check for gcc first since some other compilers define __GNUC__
for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ pathscale:__PATHCC__,__PATHSCALE__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
for ventest in clang:__clang__ intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ pathscale:__PATHCC__,__PATHSCALE__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
#if !($vencpp)
+3 -1
View File
@@ -8,7 +8,7 @@ configure_script="$2";
if [ "$type" == "" ]; then
echo "Usage: $0 <type> [<configure_script>]"
echo "where <type> is one of:"
echo "debug optimized icc win32 win32-debug win64-debug sun portland open64";
echo "debug optimized icc clang win32 win32-debug win64-debug sun portland open64";
echo "<configure_script> is ../configure by default"
exit 1;
fi
@@ -25,6 +25,8 @@ case $type in
flags="--disable-user-flags --enable-optimize-options --enable-tests" ;;
debug)
flags="--enable-debug-options --enable-tests" ;;
clang)
flags="CC=clang CXX=clang++ --enable-debug-options --enable-tests" ;;
icc)
flags="CC=icc64 CXX=icpc64 --disable-user-flags --enable-tests" ;;
win32)
+2 -1
View File
@@ -454,7 +454,8 @@ ADDITIONAL_INCLUDES="-I\$(top_builddir) -I\$(top_srcdir)/src -I\$(top_srcdir)/sr
# (e.g. gccfss (gcc frontend / sun backend), etc...).
# We use -include only when using pch.
if test "x$app_cv_compiler_gcc_pch" = "xyes"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "intel" || test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "clang" \
|| test "$ax_cv_cxx_compiler_vendor" = "intel" || test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
# This auto-includes this file when compiling any file. Benefits include pch support.
ADDITIONAL_INCLUDES="$ADDITIONAL_INCLUDES -include global_macros.h"
fi
+2 -2
View File
@@ -126,7 +126,7 @@ class GscTextWindow : public AppUIResWidget<GscTextWindow<InstanceSwitch>, Insta
// by default, delete_event calls hide().
bool on_delete_event_before(GdkEventAny* e)
{
destroy(this); // deletes this object and nullifies instance
this->destroy(this); // deletes this object and nullifies instance
return true; // event handled, don't call default virtual handler
}
@@ -184,7 +184,7 @@ class GscTextWindow : public AppUIResWidget<GscTextWindow<InstanceSwitch>, Insta
void on_close_window_button_clicked()
{
destroy(this);
this->destroy(this);
}
+32 -277
View File
@@ -3,6 +3,11 @@
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
License: See LICENSE_zlib.txt file
***************************************************************************/
/// \file
/// \author Alexander Shaduri
/// \ingroup hz
/// \weakgroup hz
/// @{
#ifndef HZ_ANY_CONVERT_H
#define HZ_ANY_CONVERT_H
@@ -14,11 +19,13 @@
#include "string_num.h" // string_is_numeric(), number_to_string()
#include "type_categories.h" // type_check_category
// Loose conversions:
// Try to convert any type to any other type as long as specialization
// for any_convert is defined.
// String conversions to numbers are _not_ strictly checked.
// Numeric types are converted by static_cast between each other.
/// \file
/// Loose conversions:
/// Try to convert any type to any other type as long as specialization
/// for any_convert is defined.
/// String conversions to numbers are _not_ strictly checked.
/// Numeric types are converted by static_cast between each other.
@@ -28,260 +35,16 @@ namespace hz {
/// This can be used for inheritance to provide a const static \c value member
/// that is either true or false.
template<bool v = false>
struct AnyConvertibleValue {
static const bool value = v;
};
/*
// The actual implementation. This class may be specialized to provide needed conversions.
template<typename From, typename To,
typename SpecCatFrom = typename type_check_category<From>::type,
typename SpecCatTo = typename type_check_category<To>::type>
struct any_convert_impl : public AnyConvertibleValue<false> {
static bool func(From from, From& to)
{
return false;
}
};
// same-spec spec
template<typename From, typename To, typename Spec>
struct any_convert_impl<From, To, Spec, Spec> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from bool to char
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_bool, type_cat_char> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from bool to int
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_bool, type_cat_int> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from bool to float
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_bool, type_cat_float> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from char to bool
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_char, type_cat_bool> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from char to int
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_char, type_cat_int> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from char to float
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_char, type_cat_float> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from int to bool
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_int, type_cat_bool> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from int to char
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_int, type_cat_char> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from int to float
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_int, type_cat_float> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from float to bool
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_float, type_cat_bool> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(static_cast<int>(from)); // avoid "unsafe use of !=" warning
return true;
}
};
// from float to char
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_float, type_cat_char> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from float to int
template<typename From, typename To>
struct any_convert_impl<From, To, type_cat_float, type_cat_int> : public AnyConvertibleValue<true> {
static bool func(From from, To& to)
{
to = static_cast<To>(from);
return true;
}
};
// from bool to string
template<typename From>
struct any_convert_impl<From, std::string, type_cat_bool, type_cat_unknown> : public AnyConvertibleValue<true> {
static bool func(From from, std::string& to)
{
to = hz::number_to_string(from);
return true;
}
};
// from char to string
template<typename From>
struct any_convert_impl<From, std::string, type_cat_char, type_cat_unknown> : public AnyConvertibleValue<true> {
static bool func(From from, std::string& to)
{
to = hz::number_to_string(from);
return true;
}
};
// from int to string
template<typename From>
struct any_convert_impl<From, std::string, type_cat_int, type_cat_unknown> : public AnyConvertibleValue<true> {
static bool func(From from, std::string& to)
{
to = hz::number_to_string(from);
return true;
}
};
// from float to string
template<typename From>
struct any_convert_impl<From, std::string, type_cat_float, type_cat_unknown> : public AnyConvertibleValue<true> {
static bool func(From from, std::string& to)
{
to = hz::number_to_string(from);
return true;
}
};
// from string to bool
template<typename To>
struct any_convert_impl<std::string, To, type_cat_unknown, type_cat_bool> : public AnyConvertibleValue<true> {
static bool func(const std::string& from, To& to)
{
return hz::string_is_numeric(from, to, false);
}
};
// from string to char
template<typename To>
struct any_convert_impl<std::string, To, type_cat_unknown, type_cat_char> : public AnyConvertibleValue<true> {
static bool func(const std::string& from, To& to)
{
return hz::string_is_numeric(from, to, false);
}
};
// from string to int
template<typename To>
struct any_convert_impl<std::string, To, type_cat_unknown, type_cat_int> : public AnyConvertibleValue<true> {
static bool func(const std::string& from, To& to)
{
return hz::string_is_numeric(from, to, false);
}
};
// from string to float
template<typename To>
struct any_convert_impl<std::string, To, type_cat_unknown, type_cat_float> : public AnyConvertibleValue<true> {
static bool func(const std::string& from, To& to)
{
return hz::string_is_numeric(from, to, false);
}
};
*/
/// Convert \c from to \c to using loose conversion methods.
template<typename From, typename To>
inline bool any_convert(From from, To& to)
{
@@ -289,7 +52,8 @@ inline bool any_convert(From from, To& to)
}
// same-type spec
/// Convert \c from to \c to using loose conversion methods.
/// This is a same-type specialization.
template<typename From>
inline bool any_convert(From from, From& to)
{
@@ -299,12 +63,16 @@ inline bool any_convert(From from, From& to)
// master struct, default to non-convertible
/// The structure that says whether type \c From is convertible to type \c To
/// using loose conversion methods.
/// This is the master struct, defaults to non-convertible.
template<typename From, typename To>
struct any_convertible : public AnyConvertibleValue<false> { };
// same-type spec
/// The structure that says whether type \c From is convertible to type \c To
/// using loose conversion methods.
// Same-type specialization
template<typename From>
struct any_convertible<From, From> : public AnyConvertibleValue<true> { };
@@ -312,28 +80,8 @@ struct any_convertible<From, From> : public AnyConvertibleValue<true> { };
// specific type specs - see below.
/*
template<typename From, typename To>
inline bool any_convert(From from, To& to)
{
return any_convert_impl<From, To>::func(from, to);
}
*/
/*
// you may use this to check if it's convertible or not
template<typename From, typename To>
struct is_any_convertible : public AnyConvertibleValue<
any_convert_impl<From, To>::value || type_is_same<From, To>::value> { };
*/
/// Define \c any_convertible specialization for \c from_type and \c to_type, saying that
/// they're convertible. Also print \c any_convert function header.
#define DEFINE_ANY_CONVERT_SPEC(from_type, to_type) \
template<> \
struct any_convertible<from_type, to_type> : public AnyConvertibleValue<true> { }; \
@@ -343,6 +91,7 @@ struct is_any_convertible : public AnyConvertibleValue<
/// Define \c any_convertible and \c any_convert specializations using static_cast.
#define DEFINE_ANY_CONVERT_SPEC_STATIC(from_type, to_type) \
DEFINE_ANY_CONVERT_SPEC(from_type, to_type) \
{ \
@@ -350,6 +99,7 @@ struct is_any_convertible : public AnyConvertibleValue<
return true; \
}
/// Define \c any_convertible and \c any_convert specializations using static_cast using bool.
#define DEFINE_ANY_CONVERT_SPEC_STATIC_TOBOOL(from_type) \
DEFINE_ANY_CONVERT_SPEC(from_type, bool) \
{ \
@@ -357,6 +107,7 @@ struct is_any_convertible : public AnyConvertibleValue<
return true; \
}
/// Define \c any_convertible and \c any_convert specializations using hz::number_to_string().
#define DEFINE_ANY_CONVERT_SPEC_NUMTOSTRING(from_type) \
DEFINE_ANY_CONVERT_SPEC(from_type, std::string) \
{ \
@@ -364,6 +115,7 @@ struct is_any_convertible : public AnyConvertibleValue<
return true; \
}
/// Define \c any_convertible and \c any_convert specializations using hz::string_is_numeric().
#define DEFINE_ANY_CONVERT_SPEC_STRINGTONUM(to_type) \
DEFINE_ANY_CONVERT_SPEC(std::string, to_type) \
{ \
@@ -390,6 +142,7 @@ struct is_any_convertible : public AnyConvertibleValue<
#endif
/// Define \c any_convertible and \c any_convert specializations for all built-in types as \c To.
#define DEFINE_ANY_CONVERT_SPEC_ALL(from_type) \
DEFINE_ANY_CONVERT_SPEC_STATIC_TOBOOL(from_type) \
DEFINE_ANY_CONVERT_SPEC_STATIC(from_type, char) \
@@ -452,3 +205,5 @@ DEFINE_ANY_CONVERT_SPEC_ALL(long double)
#endif
/// @}
+57 -33
View File
@@ -4,17 +4,23 @@
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
License: See LICENSE_boost_1_0.txt file
***************************************************************************/
/// \file
/// \author Kevlin Henney
/// \author Alexander Shaduri
/// \ingroup hz
/// \weakgroup hz
/// @{
#ifndef HZ_ANY_TYPE_H
#define HZ_ANY_TYPE_H
#include "hz_config.h" // feature macros
/*
/**
\file
any_type library (any type one-element container), based on boost::any.
Original notes and copyright info follow:
*/
// what: variant type boost::any
// who: contributed by Kevlin Henney,
@@ -36,6 +42,7 @@ Original notes and copyright info follow:
// - Define DISABLE_ANY_CONVERT=1 to disable all .convert functions
// (avoids dependency on any_convert.h)
*/
#if !(defined DISABLE_RTTI && DISABLE_RTTI)
@@ -56,38 +63,43 @@ namespace hz {
/// An object of this type can contain any variable of any type in it.
class any_type {
public:
/// Constructor
any_type()
: content(0)
{ }
// construct from a specific data type
/// Construct from a value
template<typename ValueType>
any_type(const ValueType& value)
: content(new internal::AnyHolder<ValueType>(value))
{ }
// copy constructor
/// Copy constructor
any_type(const any_type& other)
: content(other.content ? other.content->clone() : 0)
{ }
/// Destructor
~any_type()
{
delete content;
}
/// Swap *this with rhs
inline any_type& swap(any_type& rhs);
/// Check whether the wrapped variable is set
bool empty() const
{
return !content;
}
/// Remove the wrapped variable
void clear()
{
delete content;
@@ -96,52 +108,58 @@ class any_type {
#if !(defined DISABLE_RTTI && DISABLE_RTTI)
/// Get type info of the wrapped variable
const std::type_info& type() const
{
return (content ? content->type() : typeid(void));
}
/// Check whether the wrapped variable is of type T.
template<typename T> inline
bool is_type() const; // e.g. is_type<int>
#endif
// get the value into _exactly_ the same type.
/// Get the value into a variable of _exactly_ the same type.
/// \return false if casting fails
template<typename T> inline
bool get(T& put_it_here) const; // returns false if cast failed
bool get(T& put_it_here) const;
/// Get the value using _exactly_ the same type.
/// \throw bad_any_cast if casting fails
template<typename T> inline
T get() const; // this may throw if cast fails!
#if !(defined DISABLE_ANY_CONVERT && DISABLE_ANY_CONVERT)
// convert the value into a castable type.
/// Convert the value into a castable type using any_convert().
template<typename T> inline
bool convert(T& val) const;
/// Convert the value into a castable type using any_convert().
/// \throw bad_any_cast if casting fails
template<typename T> inline
T convert() const; // this may throw if cast fails!
T convert() const;
#endif
// assignment operator from specific type
/// Assignment operator from specific type
template<typename ValueType>
any_type& operator= (const ValueType& value)
{
// any_type(value).swap(*this);
delete content;
content = new internal::AnyHolder<ValueType>(value);
return *this;
}
/// Assignment operator from another any_type
any_type& operator= (const any_type& other)
{
// any_type(other).swap(*this);
delete content;
content = other.content->clone();
return *this;
@@ -149,14 +167,15 @@ class any_type {
// a helper class for easy << usage.
/// A helper class for easy operator<<() usage.
struct StreamHelper {
StreamHelper(internal::AnyHolderBase* c) : content(c) { }
internal::AnyHolderBase* content;
};
// example: std::cerr << any_type_object.to_stream()
/// A helper function to send any_type to a stream.
/// Example: std::cerr << any_type_object.to_stream()
StreamHelper to_stream() const
{
return StreamHelper(content);
@@ -166,21 +185,25 @@ class any_type {
// helper classes for enabling <<.
/// A helper struct for operator<<()
template<typename T>
struct is_default_printable
: public type_integral_constant<bool, (type_is_integral<T>::value
|| type_is_floating_point<T>::value || type_is_pointer<T>::value)> { };
/// A helper struct for operator<<()
template<bool b>
struct printable {
static const bool value = b;
};
// you may specialize this to <A>, with "public printable<true>" to enable default printing
/// A helper struct for operator<<().
// You may specialize this to <A>, with "public printable<true>" to enable default printing
template<typename T>
struct set_printable : public printable<false> { };
/// A helper struct for operator<<()
template<typename T>
struct is_printable {
static const bool value = (is_default_printable<T>::value || set_printable<T>::value);
@@ -188,13 +211,13 @@ class any_type {
internal::AnyHolderBase* content; // pointer to Holder<T>
internal::AnyHolderBase* content; ///< Pointer to internal::AnyHolder<T>
};
/// Operator<<() for any_type::StreamHelper. See any_type::to_stream().
inline std::ostream& operator<< (std::ostream& os, const any_type::StreamHelper& sh)
{
if (sh.content)
@@ -205,7 +228,7 @@ inline std::ostream& operator<< (std::ostream& os, const any_type::StreamHelper&
// this is thrown in case of bad reference casts
/// This is thrown in case of bad reference casts
DEFINE_BAD_CAST_EXCEPTION(bad_any_cast,
"Data type mismatch for AnyType. Original type: \"%s\", requested type: \"%s\".",
"Data type mismatch for AnyType.");
@@ -218,8 +241,8 @@ DEFINE_BAD_CAST_EXCEPTION(bad_any_cast,
// cast a "pointer to any_type" to a "pointer to value_type"
template<typename ValueType> inline
/// Cast a "pointer to any_type" to a "pointer to value_type"
template<typename ValueType>
ValueType any_cast(any_type* operand)
{
typedef typename type_remove_pointer<ValueType>::type nopointer;
@@ -236,8 +259,8 @@ ValueType any_cast(any_type* operand)
}
// const variant of the above
template<typename ValueType> inline
/// Cast a "pointer to any_type" to a "pointer to value_type"
template<typename ValueType>
const ValueType any_cast(const any_type* operand)
{
return any_cast<ValueType>(const_cast<any_type*>(operand));
@@ -246,8 +269,8 @@ const ValueType any_cast(const any_type* operand)
// cast an any_type object to value_type
template<typename ValueType> inline
/// Cast an any_type object to value_type
template<typename ValueType>
ValueType any_cast(any_type& operand)
{
typedef typename type_remove_reference<ValueType>::type nonref;
@@ -264,8 +287,8 @@ ValueType any_cast(any_type& operand)
}
// const variant of the above
template<typename ValueType> inline
/// Cast an any_type object to value_type
template<typename ValueType>
ValueType any_cast(const any_type& operand)
{
typedef typename type_remove_reference<ValueType>::type nonref;
@@ -330,7 +353,6 @@ T any_type::get() const
#if !(defined DISABLE_ANY_CONVERT && DISABLE_ANY_CONVERT)
// convert the value into a castable type.
template<typename T> inline
bool any_type::convert(T& val) const
{
@@ -358,7 +380,7 @@ T any_type::convert() const
namespace internal {
// you may specialize this for <T, true> to enable custom printing.
/// You may specialize this for <T, true> to enable custom printing.
template <class ValueType, bool b = !any_type::is_printable<ValueType>::value >
struct AnyPrinter {
static void to_stream(std::ostream& os, const ValueType& value)
@@ -367,7 +389,7 @@ namespace internal {
}
};
// specialization
/// Specialization
template <class ValueType>
struct AnyPrinter<ValueType, false> {
static void to_stream(std::ostream& os, const ValueType& value)
@@ -395,20 +417,20 @@ namespace internal {
// Use this to add supported types to any_type::to_stream().
// Any type may be added if it supports operator <<.
/// Use this to add supported types to any_type::to_stream().
/// Any type may be added if it supports operator <<.
#define ANY_TYPE_SET_PRINTABLE(type, truefalse) \
namespace hz { \
template<> struct any_type::set_printable<type> : public any_type::printable<truefalse> { }; \
}
} // ns
/// Make std::string printable using any_type::to_stream().
ANY_TYPE_SET_PRINTABLE(std::string, true)
@@ -416,3 +438,5 @@ ANY_TYPE_SET_PRINTABLE(std::string, true)
#endif
/// @}
+24 -5
View File
@@ -4,13 +4,20 @@
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
License: See LICENSE_boost_1_0.txt file
***************************************************************************/
/// \file
/// \author Kevlin Henney
/// \author Alexander Shaduri
/// \ingroup hz
/// \weakgroup hz
/// @{
#ifndef HZ_ANY_TYPE_HOLDER_H
#define HZ_ANY_TYPE_HOLDER_H
#include "hz_config.h" // feature macros
/*
/**
\file
Internal header, do not include manually.
*/
@@ -35,21 +42,26 @@ namespace internal {
// base class for content
/// Base class for content of hz::any_type
struct AnyHolderBase {
/// Virtual destructor
virtual ~AnyHolderBase() { }
#if !(defined DISABLE_RTTI && DISABLE_RTTI)
/// Get std::type_info for the wrapped variable
virtual const std::type_info& type() const = 0;
#endif
/// Clone the wrapped variable
virtual AnyHolderBase* clone() const = 0;
/// Send the wrapped variable to std::ostream
virtual void to_stream(std::ostream& os) const = 0;
#if !(defined DISABLE_ANY_CONVERT && DISABLE_ANY_CONVERT)
/// Convert the wrapped variable to argument type
virtual bool convert(bool& val) const = 0;
virtual bool convert(char& val) const = 0;
@@ -84,30 +96,34 @@ struct AnyHolderBase {
// child class for content, holds the actual value
/// Child class for content, holds the actual value
template<typename ValueType>
struct AnyHolder : public AnyHolderBase {
/// Type of the wrapped variable
typedef ValueType value_type;
/// Constructor
AnyHolder(const ValueType& val)
: value(val)
{ }
#if !(defined DISABLE_RTTI && DISABLE_RTTI)
/// Get std::type_info object for the wrapped variable
const std::type_info& type() const
{
return typeid(ValueType);
}
#endif
/// Clone the wrapped variable. Note that this is not a deep clone.
AnyHolderBase* clone() const
{
return new AnyHolder(value);
}
/// Send the wrapped variable to std::ostream
inline void to_stream(std::ostream& os) const;
// {
// AnyPrinter<ValueType>::to_stream(os, value);
@@ -117,6 +133,7 @@ struct AnyHolder : public AnyHolderBase {
#if !(defined DISABLE_ANY_CONVERT && DISABLE_ANY_CONVERT)
// Reimplemented from AnyHolderBase
bool convert(bool& val) const { return any_convert(value, val); }
bool convert(char& val) const { return any_convert(value, val); }
@@ -146,7 +163,7 @@ struct AnyHolder : public AnyHolderBase {
#endif // DISABLE_ANY_CONVERT
ValueType value; // the actual data
ValueType value; ///< The wrapped data
};
@@ -162,3 +179,5 @@ struct AnyHolder : public AnyHolderBase {
#endif
/// @}
+25 -15
View File
@@ -5,6 +5,12 @@
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
License: See LICENSE_zlib.txt file
***************************************************************************/
/// \file
/// \author The Regents of the University of California
/// \author Alexander Shaduri
/// \ingroup hz
/// \weakgroup hz
/// @{
#ifndef HZ_ASCII_H
#define HZ_ASCII_H
@@ -12,8 +18,9 @@
#include "hz_config.h" // feature macros
// Part of this file (specifically, ascii_strtoi() implementation)
// is derived from FreeBSD's strtol() and friends.
/// \file
/// Part of this file (specifically, ascii_strtoi() implementation)
/// is derived from FreeBSD's strtol() and friends.
// The original FreeBSD copyright header follows:
/*-
@@ -79,9 +86,9 @@ namespace hz {
// Implementation of std::isspace().
// This function always behaves like the standard function
// does in Classic locale.
/// Implementation of std::isspace().
/// This function always behaves like the standard function
/// does in Classic locale (regardless of current locale).
inline bool ascii_isspace(char c)
{
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
@@ -89,11 +96,11 @@ inline bool ascii_isspace(char c)
// Implementation of std::strtoX() for every native integral type:
// char (numerical value), wchar_t (numerical value),
// int, short, long, long long, plus their signed/unsigned variants.
// This function always behaves like the standard functions do
// in Classic locale.
/// Implementation of std::strtoX() functions for every native integral type:
/// char (numerical value), wchar_t (numerical value),
/// int, short, long, long long, plus their signed/unsigned variants.
/// This function always behaves like the standard functions do
/// in Classic locale.
template<typename T> inline
T ascii_strtoi(const char* nptr, char** endptr, int base)
{
@@ -232,7 +239,7 @@ namespace internal {
// proxy functions for system strtod family.
// we use struct because the errors are easier on the user this way.
/// We use struct because the errors are easier on the user this way.
template<typename T>
struct ascii_strtof_impl { };
@@ -328,9 +335,9 @@ namespace internal {
// on overflow, +/-HUGE_VAL[L|F] is returned, and errno is set to ERANGE.
// on underflow, 0 is returned and errno is set to ERANGE.
// A unified strtod/strtof/strtold.
// This function always behaves like the standard functions do
// in Classic locale.
/// Implementation of strtod/strtof/strtold for any floating-point type.
/// This function always behaves like the standard functions do
/// in Classic locale.
template<typename T> inline
T ascii_strtof(const char* nptr, char** endptr)
{
@@ -497,7 +504,8 @@ namespace {
// Note: Parameter "base" is ignored for floating point types.
/// Create any number (integral or floating point) from a string.
/// Note: Parameter "base" is ignored for floating point types.
template<typename T> inline
T ascii_strton(const char* nptr, char** endptr, int base = 0)
{
@@ -514,3 +522,5 @@ T ascii_strton(const char* nptr, char** endptr, int base = 0)
#endif
/// @}
+42 -39
View File
@@ -215,18 +215,19 @@ class ErrorCodeHolder<void> : public ErrorBase {
// Error class. Instantiate this in user code.
template<typename CodeType>
struct Error : public ErrorCodeHolder<CodeType> {
class Error : public ErrorCodeHolder<CodeType> {
public:
Error(const std::string& type_, ErrorLevel::level_t level_, const CodeType& code_,
const std::string& msg)
: ErrorCodeHolder<CodeType>(type_, level_, code_, msg)
{ }
Error(const std::string& type_, ErrorLevel::level_t level_, const CodeType& code_,
const std::string& msg)
: ErrorCodeHolder<CodeType>(type_, level_, code_, msg)
{ }
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<CodeType>::type, ErrorCodeHolder<CodeType>::level,
ErrorCodeHolder<CodeType>::code, ErrorCodeHolder<CodeType>::message);
}
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<CodeType>::type, ErrorCodeHolder<CodeType>::level,
ErrorCodeHolder<CodeType>::code, ErrorCodeHolder<CodeType>::message);
}
};
@@ -234,17 +235,18 @@ struct Error : public ErrorCodeHolder<CodeType> {
// Error class specialization for void (helpful for custom messages).
template<>
struct Error<void> : public ErrorCodeHolder<void> {
class Error<void> : public ErrorCodeHolder<void> {
public:
Error(const std::string& type_, ErrorLevel::level_t level_, const std::string& msg)
: ErrorCodeHolder<void>(type_, level_, msg)
{ }
Error(const std::string& type_, ErrorLevel::level_t level_, const std::string& msg)
: ErrorCodeHolder<void>(type_, level_, msg)
{ }
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<void>::type, ErrorCodeHolder<void>::level,
ErrorCodeHolder<void>::message);
}
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<void>::type, ErrorCodeHolder<void>::level,
ErrorCodeHolder<void>::message);
}
};
@@ -252,32 +254,33 @@ struct Error<void> : public ErrorCodeHolder<void> {
// int specialization for signal, errno; message is auto-evaluated.
template<>
struct Error<int> : public ErrorCodeHolder<int> {
class Error<int> : public ErrorCodeHolder<int> {
public:
Error(const std::string& type_, ErrorLevel::level_t level_, int code_, const std::string& msg)
: ErrorCodeHolder<int>(type_, level_, code_, msg)
{ }
Error(const std::string& type_, ErrorLevel::level_t level_, int code_, const std::string& msg)
: ErrorCodeHolder<int>(type_, level_, code_, msg)
{ }
Error(const std::string& type_, ErrorLevel::level_t level_, int code_)
: ErrorCodeHolder<int>(type_, level_, code)
{
if (type == "errno") {
message = hz::errno_string(code_);
Error(const std::string& type_, ErrorLevel::level_t level_, int code_)
: ErrorCodeHolder<int>(type_, level_, code)
{
if (type == "errno") {
message = hz::errno_string(code_);
} else if (type == "signal") {
// hz::signal_string should be translated already
message = HZ__("Child exited with signal: ") + hz::signal_to_string(code_);
} else if (type == "signal") {
// hz::signal_string should be translated already
message = HZ__("Child exited with signal: ") + hz::signal_to_string(code_);
} else { // nothing else supported here. use constructor with a message.
DBG_ASSERT(0);
} else { // nothing else supported here. use constructor with a message.
DBG_ASSERT(0);
}
}
}
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<int>::type, ErrorCodeHolder<int>::level,
ErrorCodeHolder<int>::code, ErrorCodeHolder<int>::message);
}
ErrorBase* clone() // needed for copying by base pointers
{
return new Error(ErrorCodeHolder<int>::type, ErrorCodeHolder<int>::level,
ErrorCodeHolder<int>::code, ErrorCodeHolder<int>::message);
}
};
+3 -3
View File
@@ -232,9 +232,9 @@ void debug_indent_reset();
namespace debug_internal {
class DebugIndent;
class DebugUnindent;
class DebugResetIndent;
struct DebugIndent;
struct DebugUnindent;
struct DebugResetIndent;