Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3232


Ignore:
Timestamp:
Jun 26, 2009, 11:41:11 AM (15 years ago)
Author:
rgrieder
Message:

Moved implicit conversion detection from Convert.h to the new TemplateUtils.h file.

Location:
code/trunk/src/util
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/util/Convert.h

    r3196 r3232  
    4444#include "Debug.h"
    4545#include "String.h"
    46 
    47 // GCC generates warnings when implicitely casting from float to int for instance.
    48 // This is however exactly what convertValue does, so we need to suppress these warnings.
    49 // They only occur when using the ImplicitConversion template.
    50 #ifdef ORXONOX_COMPILER_GCC
    51 #  pragma GCC system_header
    52 #endif
    53 
    54 
    55 ///////////////////////////////////////////////
    56 // Static detection for conversion functions //
    57 ///////////////////////////////////////////////
    58 
    59 /* The idea to use the sizeof() operator on return functions to determine function existance
    60    is described in 'Modern C++ design' by Alexandrescu (2001). */
    61 
    62 // disable warnings about possible loss of data
    63 #ifdef ORXONOX_COMPILER_MSVC
    64 #  pragma warning(push)
    65 #  pragma warning(disable:4244)
    66 #endif
    67 
    68 namespace orxonox
    69 {
    70     template <class FromType, class ToType>
    71     class ImplicitConversion
    72     {
    73     private:
    74         ImplicitConversion(); ImplicitConversion(const ImplicitConversion&); ~ImplicitConversion();
    75         // Gets chosen only if there is an implicit conversion from FromType to ToType.
    76         static char test(ToType);
    77         // Accepts any argument. Why do we not use a template? The reason is that with templates,
    78         // the function above is only taken iff it is an exact type match. But since we want to
    79         // check for implicit conversion, we have to use the ellipsis.
    80         static long long test(...);
    81         static FromType object; // helper object to handle private c'tor and d'tor
    82     public:
    83         // test(object) only has 'long long' return type iff the compiler doesn't choose test(...)
    84         enum { exists = (sizeof(test(object)) == sizeof(char)) };
    85     };
    86 }
    87 
    88 #ifdef ORXONOX_COMPILER_MSVC
    89 #  pragma warning(pop)
    90 #endif
    91 
     46#include "TemplateUtils.h"
    9247
    9348////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.