src/helpers.hpp
branchcpp_gui
changeset 6285 187e3ef04cc9
parent 6268 4b5241e5dd10
equal deleted inserted replaced
6284:45d0233e7d79 6285:187e3ef04cc9
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file helpers.hpp */
     2 
     4 
     3 #ifndef HELPERS_HPP
     5 #ifndef HELPERS_HPP
     4 #define HELPERS_HPP
     6 #define HELPERS_HPP
     5 
     7 
     6 /** @file helpers.hpp */
       
     7 #include "macros.h"
     8 #include "macros.h"
     8 
     9 
     9 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    10 /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
    10 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    11 *  from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
    11 template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
    12 template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
    67 	FORCEINLINE mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
    68 	FORCEINLINE mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
    68 	FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
    69 	FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
    69 	FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
    70 	FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
    70 	FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
    71 	FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
    71 	FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
    72 	FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
    72 
       
    73 /** probably redundant enum combining operators (as we have conversion functions)
       
    74  *  but the old code is full of such arithmetics */
       
    75 # define DECLARE_ENUM_AS_BIT_INDEX(idx_t, mask_t) \
       
    76 	FORCEINLINE mask_t operator << (int m, idx_t i) {return (mask_t)(m << (int)i);} \
       
    77 	FORCEINLINE mask_t operator << (mask_t m, int i) {return (mask_t)(((int)m) << i);} \
       
    78 	FORCEINLINE mask_t operator >> (mask_t m, int i) {return (mask_t)(((int)m) >> i);}
       
    79 
    73 
    80 
    74 
    81 /** Informative template class exposing basic enumeration properties used by several
    75 /** Informative template class exposing basic enumeration properties used by several
    82  *  other templates below. Here we have only forward declaration. For each enum type
    76  *  other templates below. Here we have only forward declaration. For each enum type
    83  *  we will create specialization derived from MakeEnumPropsT<>.
    77  *  we will create specialization derived from MakeEnumPropsT<>.