X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftype.h;h=72d148a0e16631b2440747fd2c20a1556597b728;hb=818ead7b6ccef1e4d2435cc959bc07f910fcde46;hp=5a87a10222a84794341d9a167c94786ae022927f;hpb=a582163d380833b1370ba067a1fd0ad5c2984723;p=libs%2Fdatafile.git diff --git a/source/type.h b/source/type.h index 5a87a10..72d148a 100644 --- a/source/type.h +++ b/source/type.h @@ -1,10 +1,3 @@ -/* $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_ @@ -17,7 +10,8 @@ struct Symbol { std::string name; - Symbol(const std::string &n): name(n) { } + template + Symbol(const T &n): name(lexical_cast(n)) { } template operator T() const { return lexical_cast(name); } }; @@ -25,25 +19,33 @@ struct Symbol struct IntType { static const char signature = 'i'; +#ifdef MSVC + typedef __int64 Store; +#else typedef long long int Store; +#endif + 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,49 +56,79 @@ struct SymbolType }; 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 { }; +#ifdef MSVC template<> -struct TypeInfo: IntType { }; +struct TypeInfo<__int64, false>: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; +#else +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