X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftype.h;h=f40657eb14a07003a295cb979ae4813523183d17;hb=b39ce68f12c30eedb272b65fe78baec5864d89ca;hp=6959e98526669e4482c34d59b26530450c12fedd;hpb=7df5e45c7f414f6a07681dc4ec2abb63b091a309;p=libs%2Fdatafile.git diff --git a/source/type.h b/source/type.h index 6959e98..f40657e 100644 --- a/source/type.h +++ b/source/type.h @@ -1,6 +1,7 @@ #ifndef MSP_DATAFILE_TYPE_H_ #define MSP_DATAFILE_TYPE_H_ +#include #include namespace Msp { @@ -10,8 +11,10 @@ struct Symbol { std::string name; + Symbol() { } + template - Symbol(const T &n): name(lexical_cast(n)) { } + Symbol(const T &n): name(lexical_cast(n)) { } template operator T() const { return lexical_cast(name); } }; @@ -19,25 +22,29 @@ struct Symbol struct IntType { static const char signature = 'i'; - typedef long long int Store; + typedef Int64 Store; + typedef Store Load; }; struct FloatType { static const char signature = 'f'; typedef double Store; + typedef Store Load; }; struct BoolType { static const char signature = 'b'; typedef bool Store; + typedef Store Load; }; struct StringType { static const char signature = 's'; typedef std::string Store; + typedef Store Load; }; struct SymbolType @@ -47,50 +54,96 @@ struct SymbolType typedef Symbol Store; }; +const char valid_signatures[] = +{ + IntType::signature, + FloatType::signature, + BoolType::signature, + StringType::signature, + SymbolType::signature, + 0 +}; + template -struct TypeInfo: SymbolType { }; +struct HasLoadType +{ + struct Yes { char c[2]; }; + struct No { char c; }; + + template + static Yes f(typename U::LoadType *); + template + static No f(...); + + enum { value = (sizeof(f(0))==sizeof(Yes)) }; +}; + +template::value> +struct TypeInfo; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; +#if defined(_MSC_VER) template<> -struct TypeInfo: IntType { }; +struct TypeInfo<__int64, false>: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; +#elif defined(__GNUC__) +template<> +struct TypeInfo: IntType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: IntType { }; +#endif template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: BoolType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: StringType { }; +struct TypeInfo: BoolType { }; + +template<> +struct TypeInfo: StringType { }; + +template<> +struct TypeInfo: StringType { }; + +template<> +struct TypeInfo: StringType { }; + +template +struct TypeInfo: TypeInfo { }; + +template +struct TypeInfo: TypeInfo { }; template -struct TypeInfo: TypeInfo { }; +struct TypeInfo: TypeInfo +{ typedef typename T::LoadType Load; }; template -struct TypeInfo: TypeInfo { }; +struct TypeInfo: SymbolType +{ typedef T Load; }; } // namespace DataFile } // namespace Msp