Ignore:
Timestamp:
Dec 21, 2005, 4:55:34 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Darin.

Removed evil hack for determining if a type is an integer, replaced
with template metaprogramming.

  • JavaScriptCore.xcodeproj/project.pbxproj: Set tab size to 2 for testkjs.cpp
  • kjs/testkjs.cpp: (main): Inserted asserts to test IsInteger. FIXME: Move these to KXMLCore unit tests directory when we create one.
  • kxmlcore/HashTraits.h: (KXMLCore::): Added IsInteger class for querying types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kxmlcore/HashTraits.h

    r11628 r11719  
    2525
    2626#include <utility>
    27 #ifndef WIN32
    28 #include <bits/cpp_type_traits.h>
    29 #endif
    3027
    3128namespace KXMLCore {
    3229
    3330    using std::pair;
    34  
    35     // FIXME: stop using this evil hack, use something supported or else specialize
    36     // for all numerit cypes by hand
     31   
     32    template <typename T> struct IsInteger           { static const bool value = false; };
     33    template <> struct IsInteger<bool>               { static const bool value = true; };
     34    template <> struct IsInteger<char>               { static const bool value = true; };
     35    template <> struct IsInteger<signed char>        { static const bool value = true; };
     36    template <> struct IsInteger<unsigned char>      { static const bool value = true; };
     37    template <> struct IsInteger<short>              { static const bool value = true; };
     38    template <> struct IsInteger<unsigned short>     { static const bool value = true; };
     39    template <> struct IsInteger<int>                { static const bool value = true; };
     40    template <> struct IsInteger<unsigned int>       { static const bool value = true; };
     41    template <> struct IsInteger<long>               { static const bool value = true; };
     42    template <> struct IsInteger<unsigned long>      { static const bool value = true; };
     43    template <> struct IsInteger<long long>          { static const bool value = true; };
     44    template <> struct IsInteger<unsigned long long> { static const bool value = true; };
     45       
    3746    template<typename T>
    3847    struct HashTraits {
    3948        typedef T traitType;
    40 #ifdef __GLIBCXX__ // gcc 3.4 and greater:
    41         static const bool emptyValueIsZero = std::__is_integer<T>::__value;
    42 #else
    43         static const bool emptyValueIsZero = std::__is_integer<T>::_M_type;
    44 #endif
     49        static const bool emptyValueIsZero = IsInteger<T>::value;
    4550       
    4651        static traitType emptyValue() {
Note: See TracChangeset for help on using the changeset viewer.