| /** @file generic.h | |
| ** @author Andrea Vedaldi | |
| ** @brief Generic | |
| **/ | |
| /* AUTORIGHTS | |
| Copyright (C) 2007-09 Andrea Vedaldi and Brian Fulkerson | |
| This file is part of VLFeat, available in the terms of the GNU | |
| General Public License version 2. | |
| */ | |
| /** @brief Library version string */ | |
| /** ------------------------------------------------------------------ | |
| ** @name C preprocessor helper macros | |
| ** @{ */ | |
| /** @brief Convert the argument to a string | |
| ** | |
| ** @param x value to be stringified. | |
| ** | |
| ** This macro stringifies the argument @a x by means of the | |
| ** <code>#</code> prerpocessor operator. | |
| ** | |
| ** The standard C preprocessor does not prescan arguments which are | |
| ** stringified, so | |
| ** | |
| ** @code | |
| ** #define A B | |
| ** char const * str = VL_STRINGIFY(A) ; | |
| ** @endcode | |
| ** | |
| ** initializes <code>str</code> with a pointer to the string | |
| ** <code>"A"</code>, which mihgt be unexpected. To fix this issue, | |
| ** you can use ::VL_XSTRINGIFY. | |
| ** | |
| ** @sa ::VL_XSTRINGIFY | |
| **/ | |
| /** @brief Expand and then convert the argument to a string | |
| ** | |
| ** @param x value to be macro-expanded and converted. | |
| ** | |
| ** This macro macro-expands the argument @a x and stringifies the | |
| ** result of the expansion. For instance | |
| ** | |
| ** @code | |
| ** #define A B | |
| ** char const * str = VL_STRINGIFY(A) ; | |
| ** @endcode | |
| ** | |
| ** initializes <code>str</code> with a pointer to the string | |
| ** <code>"B"</code>. | |
| ** | |
| ** @sa ::VL_STRINGIFY | |
| **/ | |
| /** @brief Concatenate the arguments into a lexical unit | |
| ** | |
| ** @param x first argument to be concatenated. | |
| ** @param y second argument to be concatenated. | |
| ** | |
| ** This macro concatenates its arguments into a single lexical unit | |
| ** by means of the <code>##</code> preprocessor operator. Notice that | |
| ** arguments concatenated by <code>##</code> are not pre-expanded by | |
| ** the C preprocessor. To macro-expand the arguments and then | |
| ** concatenate them,use ::VL_XCAT. | |
| ** | |
| ** @see ::VL_XCAT | |
| **/ | |
| /** @brief Expand and then concatenate the arguments into a lexical unit | |
| ** | |
| ** @param x first argument to be concatenated. | |
| ** @param y second argument to be concatenated. | |
| ** | |
| ** This macro is the same as ::VL_CAT, except that the arguments are | |
| ** macro expanded before being concatenated. | |
| ** | |
| ** @see ::VL_CAT | |
| **/ | |
| /** @} */ | |
| /** @brief Convert a boolean to "yes" or "no" strings | |
| ** @param x boolean to convert. | |
| ** A pointer to either the string "yes" (if @a x is true) | |
| ** or the string "no". | |
| ** @par Example | |
| ** @code | |
| ** VL_PRINTF("Is x true? %s.", VL_YESNO(x)) | |
| ** @endcode | |
| **/ | |
| /** @name Type identidifers for atomic data types | |
| ** @{ */ | |
| /** @} */ | |
| /** ------------------------------------------------------------------ | |
| ** @name Memory allocation | |
| ** @{ */ | |
| VL_EXPORT | |
| void vl_set_alloc_func (void *(*malloc_func) (size_t), | |
| void *(*realloc_func) (void*,size_t), | |
| void *(*calloc_func) (size_t, size_t), | |
| void (*free_func) (void*)) ; | |
| VL_INLINE void *vl_malloc (size_t n) ; | |
| VL_INLINE void *vl_realloc (void *ptr, size_t n) ; | |
| VL_INLINE void *vl_calloc (size_t n, size_t size) ; | |
| VL_INLINE void vl_free (void* ptr) ; | |
| /** @} */ | |
| /** ------------------------------------------------------------------ | |
| ** @name Logging | |
| ** @{ */ | |
| /** ------------------------------------------------------------------ | |
| ** @brief Customizable printf function pointer type */ | |
| typedef int(*printf_func_t) (char const *format, ...) ; | |
| /** @brief Set printf function | |
| ** @param printf_func pointer to @c printf. | |
| ** Let @c print_func be NULL to disable printf. | |
| **/ | |
| VL_EXPORT void vl_set_printf_func (printf_func_t printf_func) ; | |
| /** @def VL_PRINTF | |
| ** @brief Call user-customizable @c printf function | |
| ** | |
| ** The function calls the user customizable @c printf. | |
| **/ | |
| /** @def VL_PRINT | |
| ** @brief Same as ::VL_PRINTF (legacy code) | |
| **/ | |
| /** @} */ | |
| /** ------------------------------------------------------------------ | |
| ** @name Error handling | |
| ** @{ */ | |
| /** @brief The number of the last error */ | |
| extern VL_EXPORT int vl_err_no ; | |
| /** @brief The maximum length of an error description. */ | |
| /** @brief The description of the last error. */ | |
| extern VL_EXPORT char vl_err_msg [VL_ERR_MSG_LEN + 1] ; | |
| /** @} */ | |
| /** ------------------------------------------------------------------ | |
| ** @name Common operations | |
| ** @{ */ | |
| /** @brief Min operation | |
| ** @param x value | |
| ** @param y value | |
| ** @return the minimum of @a x and @a y. | |
| **/ | |
| /** @brief Max operation | |
| ** @param x value. | |
| ** @param y value. | |
| ** @return the maximum of @a x and @a y. | |
| **/ | |
| /** @brief Signed left shift operation | |
| ** | |
| ** The macro is equivalent to the builtin @c << operator, but it | |
| ** supports negative shifts too. | |
| ** | |
| ** @param x value. | |
| ** @param n number of shift positions. | |
| ** @return @c x << n . | |
| **/ | |
| /* @} */ | |
| /** --------------------------------------------------------------- */ | |
| VL_EXPORT | |
| char const * vl_get_version_string () ; | |
| VL_EXPORT | |
| void vl_print_info () ; | |
| /** ------------------------------------------------------------------ | |
| ** @name Measuring time | |
| ** @{ | |
| **/ | |
| VL_EXPORT void vl_tic() ; | |
| VL_EXPORT double vl_toc() ; | |
| /** @} */ | |
| extern VL_EXPORT int (*vl_printf_func) (char const * format, ...) ; | |
| extern VL_EXPORT void *(*vl_malloc_func) (size_t) ; | |
| extern VL_EXPORT void *(*vl_realloc_func) (void*,size_t) ; | |
| extern VL_EXPORT void *(*vl_calloc_func) (size_t, size_t) ; | |
| extern VL_EXPORT void (*vl_free_func) (void*) ; | |
| VL_INLINE | |
| void* vl_malloc (size_t n) | |
| { | |
| return (*vl_malloc_func)(n) ; | |
| } | |
| VL_INLINE | |
| void* vl_realloc (void* ptr, size_t n) | |
| { | |
| return (*vl_realloc_func)(ptr, n) ; | |
| } | |
| VL_INLINE | |
| void* vl_calloc (size_t n, size_t size) | |
| { | |
| return (*vl_calloc_func)(n, size) ; | |
| } | |
| VL_INLINE | |
| void vl_free (void *ptr) | |
| { | |
| (*vl_free_func)(ptr) ; | |
| } | |
| /* VL_GENERIC_H */ | |