X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Ftype.h;h=fdd040d81adccd82b53b9e9509b48b4348b70ed8;hp=a7c57c40d230b55e15dc1d5313039e1d39cf347a;hb=HEAD;hpb=9bd3968eaaabb278d22f182365d022704d2a2cf1 diff --git a/source/type.h b/source/type.h index a7c57c4..0e371e6 100644 --- a/source/type.h +++ b/source/type.h @@ -1,6 +1,8 @@ #ifndef MSP_DATAFILE_TYPE_H_ #define MSP_DATAFILE_TYPE_H_ +#include +#include #include namespace Msp { @@ -10,8 +12,10 @@ struct Symbol { std::string name; + Symbol() = default; + 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,11 +23,7 @@ struct Symbol struct IntType { static const char signature = 'i'; -#ifdef MSVC - typedef __int64 Store; -#else - typedef long long int Store; -#endif + typedef std::int64_t Store; typedef Store Load; }; @@ -31,18 +31,21 @@ 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 @@ -52,58 +55,84 @@ struct SymbolType typedef Symbol Store; }; +const char valid_signatures[] = +{ + IntType::signature, + FloatType::signature, + BoolType::signature, + StringType::signature, + SymbolType::signature, + 0 +}; + +struct CheckLoadType: Sfinae +{ + template + static Yes f(typename T::LoadType *); + using Sfinae::f; +}; + template -struct TypeInfo: SymbolType { }; +struct HasLoadType: Sfinae::Evaluate { }; + +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 { }; -#ifdef MSVC template<> -struct TypeInfo<__int64>: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; -#else +struct TypeInfo: IntType { }; + template<> -struct TypeInfo: IntType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: IntType { }; -#endif +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: BoolType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: StringType { }; template<> -struct TypeInfo: BoolType { }; +struct TypeInfo: StringType { }; 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