X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Ftype.h;h=58766289bc172a0e214917c961452976fac5645e;hp=242a9e11d1bed7c30cf8bbc978ff1b001133d74b;hb=9867e5fdf99d7d6c9d83846c11a1cee6a9919be1;hpb=e5d760ccfaaa01884be2424b62e47a24466e0c4b diff --git a/source/type.h b/source/type.h index 242a9e1..5876628 100644 --- a/source/type.h +++ b/source/type.h @@ -1,13 +1,7 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_DATAFILE_TYPE_H_ #define MSP_DATAFILE_TYPE_H_ +#include #include namespace Msp { @@ -26,25 +20,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 @@ -54,50 +52,90 @@ 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: IntType { }; +#endif template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: BoolType { }; +struct TypeInfo: BoolType { }; template<> -struct TypeInfo: StringType { }; +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