src/helpers.hpp
changeset 5609 dc6a58930ba4
parent 5587 167d9a91ef02
child 5733 388bb9dcb79b
equal deleted inserted replaced
5608:0b0aff054402 5609:dc6a58930ba4
     8 
     8 
     9 #ifdef __cplusplus
     9 #ifdef __cplusplus
    10 
    10 
    11 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    11 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    12 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    12 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    13 template <typename T> FORCEINLINE bool MallocT(T** t_ptr, size_t num_elements)
    13 template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
    14 {
    14 {
    15 	*t_ptr = (T*)malloc(num_elements * sizeof(T));
    15 	T *t_ptr = (T*)malloc(num_elements * sizeof(T));
    16 	return (*t_ptr != NULL);
    16 	return t_ptr;
    17 }
    17 }
    18 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    18 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    19 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    19 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    20 template <typename T> FORCEINLINE bool CallocT(T** t_ptr, size_t num_elements)
    20 template <typename T> FORCEINLINE T* CallocT(size_t num_elements)
    21 {
    21 {
    22 	*t_ptr = (T*)calloc(num_elements, sizeof(T));
    22 	T *t_ptr = (T*)calloc(num_elements, sizeof(T));
    23 	return (*t_ptr != NULL);
    23 	return t_ptr;
    24 }
    24 }
    25 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    25 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    26 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    26 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    27 template <typename T> FORCEINLINE bool ReallocT(T** t_ptr, size_t num_elements)
    27 template <typename T> FORCEINLINE T* ReallocT(T* t_ptr, size_t num_elements)
    28 {
    28 {
    29 	*t_ptr = (T*)realloc(*t_ptr, num_elements * sizeof(T));
    29 	t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T));
    30 	return (*t_ptr != NULL);
    30 	return t_ptr;
    31 }
    31 }
    32 
    32 
    33 /** type safe swap operation */
    33 /** type safe swap operation */
    34 template <typename T> void SwapT(T *a, T *b);
    34 template <typename T> void SwapT(T *a, T *b);
    35 
    35