X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftype.h;h=fdd040d81adccd82b53b9e9509b48b4348b70ed8;hb=08ca2d33416e549bd3d071a164ed2a98765dda4b;hp=5a87a10222a84794341d9a167c94786ae022927f;hpb=a582163d380833b1370ba067a1fd0ad5c2984723;p=libs%2Fdatafile.git diff --git a/source/type.h b/source/type.h index 5a87a10..fdd040d 100644 --- a/source/type.h +++ b/source/type.h @@ -1,13 +1,8 @@ -/* $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 #include namespace Msp { @@ -17,7 +12,10 @@ struct Symbol { std::string name; - Symbol(const std::string &n): name(n) { } + Symbol() { } + + template + Symbol(const T &n): name(lexical_cast(n)) { } template operator T() const { return lexical_cast(name); } }; @@ -25,25 +23,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 @@ -53,50 +55,92 @@ 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 { }; + +template<> +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 { }; +struct TypeInfo: IntType { }; +#endif template<> -struct TypeInfo: IntType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: BoolType { }; template<> -struct TypeInfo: BoolType { }; +struct TypeInfo: StringType { }; template<> -struct TypeInfo: StringType { }; +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