PageRenderTime 23ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Class_Segmentation/vlfeat/vl/generic.h

http://phd-workspace.googlecode.com/
C Header | 214 lines | 93 code | 39 blank | 82 comment | 1 complexity | a8f2694e297af41ca1e98bfef1818946 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. /** @file generic.h
  2. ** @author Andrea Vedaldi
  3. ** @brief Generic
  4. **/
  5. /* AUTORIGHTS
  6. Copyright (C) 2007-09 Andrea Vedaldi and Brian Fulkerson
  7. This file is part of VLFeat, available in the terms of the GNU
  8. General Public License version 2.
  9. */
  10. #ifndef VL_GENERIC_H
  11. #define VL_GENERIC_H
  12. #include <stddef.h>
  13. #include <time.h>
  14. #include <assert.h>
  15. #include "host.h"
  16. /** @brief Library version string */
  17. #define VL_VERSION_STRING "0.9.7"
  18. /** @brief Maximum length (in characters) of an error message */
  19. #define VL_ERR_MSG_LEN 1024
  20. /** @name Type identidifers for atomic data types
  21. ** @{ */
  22. #define VL_TYPE_FLOAT 1
  23. #define VL_TYPE_DOUBLE 2
  24. #define VL_TYPE_INT8 3
  25. #define VL_TYPE_UINT8 4
  26. #define VL_TYPE_INT16 5
  27. #define VL_TYPE_UINT16 6
  28. #define VL_TYPE_INT32 7
  29. #define VL_TYPE_UINT32 8
  30. #define VL_TYPE_INT64 9
  31. #define VL_TYPE_UINT64 10
  32. /** @brief Get the symbolic name of a data type
  33. ** @param type data type.
  34. ** @return data type symbolic name.
  35. **
  36. ** @c type is one of ::VL_TYPE_FLOAT, ::VL_TYPE_DOUBLE,
  37. ** ::VL_TYPE_INT8, ::VL_TYPE_INT16, ::VL_TYPE_INT32, ::VL_TYPE_INT64,
  38. ** ::VL_TYPE_UINT8, ::VL_TYPE_UINT16, ::VL_TYPE_UINT32, ::VL_TYPE_UINT64.
  39. **/
  40. VL_INLINE char const *
  41. vl_get_type_name (int type)
  42. {
  43. switch (type) {
  44. case VL_TYPE_FLOAT : return "float" ;
  45. case VL_TYPE_DOUBLE : return "double" ;
  46. case VL_TYPE_INT8 : return "int8" ;
  47. case VL_TYPE_INT16 : return "int16" ;
  48. case VL_TYPE_INT32 : return "int32" ;
  49. case VL_TYPE_INT64 : return "int64" ;
  50. case VL_TYPE_UINT8 : return "int8" ;
  51. case VL_TYPE_UINT16 : return "int16" ;
  52. case VL_TYPE_UINT32 : return "int32" ;
  53. case VL_TYPE_UINT64 : return "int64" ;
  54. default: return NULL ;
  55. }
  56. }
  57. /** @} */
  58. /** ------------------------------------------------------------------
  59. ** @name Memory allocation
  60. ** @{ */
  61. VL_EXPORT
  62. void vl_set_alloc_func (void *(*malloc_func) (size_t),
  63. void *(*realloc_func) (void*,size_t),
  64. void *(*calloc_func) (size_t, size_t),
  65. void (*free_func) (void*)) ;
  66. VL_INLINE void *vl_malloc (size_t n) ;
  67. VL_INLINE void *vl_realloc (void *ptr, size_t n) ;
  68. VL_INLINE void *vl_calloc (size_t n, size_t size) ;
  69. VL_INLINE void vl_free (void* ptr) ;
  70. /** @} */
  71. /** ------------------------------------------------------------------
  72. ** @name Logging
  73. ** @{ */
  74. /** ------------------------------------------------------------------
  75. ** @brief Customizable printf function pointer type */
  76. typedef int(*printf_func_t) (char const *format, ...) ;
  77. /** @brief Set printf function
  78. ** @param printf_func pointer to @c printf.
  79. ** Let @c print_func be NULL to disable printf.
  80. **/
  81. VL_EXPORT void vl_set_printf_func (printf_func_t printf_func) ;
  82. /** @def VL_PRINTF
  83. ** @brief Call user-customizable @c printf function
  84. **
  85. ** The function calls the user customizable @c printf.
  86. **/
  87. #define VL_PRINTF (*vl_printf_func)
  88. /** @def VL_PRINT
  89. ** @brief Same as ::VL_PRINTF (legacy code)
  90. **/
  91. #define VL_PRINT (*vl_printf_func)
  92. /** @} */
  93. /** ------------------------------------------------------------------
  94. ** @name Error handling
  95. ** @{ */
  96. /** @brief The number of the last error */
  97. extern VL_EXPORT int vl_err_no ;
  98. /** @brief The maximum length of an error description. */
  99. #define VL_ERR_MSG_LEN 1024
  100. /** @brief The description of the last error. */
  101. extern VL_EXPORT char vl_err_msg [VL_ERR_MSG_LEN + 1] ;
  102. #define VL_ERR_OK 0 /**< No error */
  103. #define VL_ERR_OVERFLOW 1 /**< Buffer overflow error */
  104. #define VL_ERR_ALLOC 2 /**< Resource allocation error */
  105. #define VL_ERR_BAD_ARG 3 /**< Bad argument or illegal data error */
  106. #define VL_ERR_IO 4 /**< Input/output error */
  107. #define VL_ERR_EOF 5 /**< End-of-file or end-of-sequence error */
  108. #define VL_ERR_NO_MORE 5 /**< End-of-sequence @deprecated */
  109. /** @} */
  110. /** ------------------------------------------------------------------
  111. ** @name Common operations
  112. ** @{ */
  113. /** @brief Min operation
  114. ** @param x value
  115. ** @param y value
  116. ** @return the minimum of @a x and @a y.
  117. **/
  118. #define VL_MIN(x,y) (((x)<(y))?(x):(y))
  119. /** @brief Max operation
  120. ** @param x value.
  121. ** @param y value.
  122. ** @return the maximum of @a x and @a y.
  123. **/
  124. #define VL_MAX(x,y) (((x)>(y))?(x):(y))
  125. /** @brief Signed left shift operation
  126. **
  127. ** The macro is equivalent to the builtin @c << operator, but it
  128. ** supports negative shifts too.
  129. **
  130. ** @param x value.
  131. ** @param n number of shift positions.
  132. ** @return @c x << n .
  133. **/
  134. #define VL_SHIFT_LEFT(x,n) (((n)>=0)?((x)<<(n)):((x)>>-(n)))
  135. /* @} */
  136. /** --------------------------------------------------------------- */
  137. VL_EXPORT
  138. char const * vl_get_version_string () ;
  139. VL_EXPORT
  140. void vl_print_info () ;
  141. /** ------------------------------------------------------------------
  142. ** @name Measuring time
  143. ** @{
  144. **/
  145. VL_EXPORT void vl_tic() ;
  146. VL_EXPORT double vl_toc() ;
  147. /** @} */
  148. extern VL_EXPORT int (*vl_printf_func) (char const * format, ...) ;
  149. extern VL_EXPORT void *(*vl_malloc_func) (size_t) ;
  150. extern VL_EXPORT void *(*vl_realloc_func) (void*,size_t) ;
  151. extern VL_EXPORT void *(*vl_calloc_func) (size_t, size_t) ;
  152. extern VL_EXPORT void (*vl_free_func) (void*) ;
  153. VL_INLINE
  154. void* vl_malloc (size_t n)
  155. {
  156. return (*vl_malloc_func)(n) ;
  157. }
  158. VL_INLINE
  159. void* vl_realloc (void* ptr, size_t n)
  160. {
  161. return (*vl_realloc_func)(ptr, n) ;
  162. }
  163. VL_INLINE
  164. void* vl_calloc (size_t n, size_t size)
  165. {
  166. return (*vl_calloc_func)(n, size) ;
  167. }
  168. VL_INLINE
  169. void vl_free (void *ptr)
  170. {
  171. (*vl_free_func)(ptr) ;
  172. }
  173. /* VL_GENERIC_H */
  174. #endif